【问题标题】:Jira API getting attachmentJira API 获取附件
【发布时间】:2015-04-15 00:02:57
【问题描述】:

我编写了一些显示附件列表的代码。但问题是,我希望用户能够在不登录的情况下查看附件。有没有办法为用户进行身份验证?这是我的代码:

 //to get cases.  this returns a list of attachments, with the url in Jira

  $attachments = $jira_case->issues[0]->fields->attachment;

   //iterates over the lists and creates links
   foreach ($attachments as $i=> $attachment) {
      $html .="
      <tr>
          <td style='padding-left: 10px; width:0px; padding-top: 20px;' colspan='3'>
          ". ($i+1) .") <a target = '_blank' href ='". $attachment->content ."'>". nl2br($attachment->filename) ."</a>
          </td>
     </tr>";
}

问题是当用户点击链接时,如果他们没有登录,他们将被要求登录。我不想要这个,因为它是我的应用程序,所以用户不需要一个jira帐户。这可能吗?也许通过传递某种令牌?

杰森

【问题讨论】:

  • 您可以使用服务帐户,该帐户可以查看该项目中的所有内容。

标签: php api jira jira-rest-api


【解决方案1】:

从 JIRA 的角度来看,来自用户浏览器的请求不包含任何身份验证标头。 JIRA 对附件使用与问题相同的权限集,因此每当用户能够查看特定的 JIRA 问题时,他也能够查看(和下载)附件。因此,除非您让匿名用户可以访问您的项目{s} 和问题{s},否则具有适当权限的人必须进行身份验证。如果您希望用户只能通过您的应用程序下载附件,作为您的应用程序用户,那么您需要通过您的应用程序以某种方式代理它。您需要生成指向您的服务器的链接,而不是在直接指向 JIRA 的页面链接上呈现,然后您的服务器应联系 JIRA 获取附件并将​​自己验证为您的应用程序用户(有权查看包含附件的问题)并传输JIRA 对最终用户的响应。

【讨论】:

  • 谢谢,这正是我所做的。我会发布代码,以防有人需要。
【解决方案2】:

如果其他人想知道如何做到这一点:

$url = "https://mySite.atlassian.net/secure/attachment/". $attachment_id ."/". $attachment_name ."?os_username=". $this->jira_user_name ."&os_password=" . $this->jira_password;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$file = curl_exec($ch);
curl_close($ch);

if($file){
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename='.$attachment_name);
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     echo ($file);
     exit;
}else{
     throw new Exception("Error:  file now found.");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-17
    • 2016-08-27
    • 2017-03-22
    • 2015-03-20
    • 2021-09-18
    • 1970-01-01
    相关资源
    最近更新 更多