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

问题是,当用户点击链接时,如果他们没有登录,他们将被要求登录。我不希望这样,因为这是我的应用程序进行身份验证,这样用户就不需要jira帐户。这可能吗?也许是传递某种象征?

从JIRA的角度来看,来自用户浏览器的请求不包含任何身份验证头。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.");
}
Unirest

//导入

使用Unirest''Request作为UnirestRequest

//Laravel代码//控制器

$url=";https://your-domain.atlassian.net/rest/api/3/attachment/content/{id}";;

$headers=数组("Accept"=>"application/json");

UnirestRequest::auth(env('JIRA_PROJECT_USER'),env('JIRA_PROJECT_KEY'));

$response=UnirestRequest::get($url,$headers);

return$response->身体