Jira API 正在获取附件

Jira API getting attachment

我写了一些显示附件列表的代码。但问题是,我希望用户无需登录即可查看附件。有没有办法对用户进行身份验证?这是我的代码:

 //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>";
}

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

杰森

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

如果其他人想知道如何执行此操作:

$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.");
}