【问题标题】:atlassian cloud oauth 2.0, Error 403 on POST request to get tokenatlassian cloud oauth 2.0,POST 请求获取令牌时出现错误 403
【发布时间】:2020-07-29 17:24:40
【问题描述】:

我打算将我的 Angular 应用程序与 Jira 云集成。为了对用户进行身份验证,Atlassian 使用 OAuth 2.0 让外部应用程序代表用户访问产品 API。我按照this page的指示进行操作

  1. 将用户引导至授权 URL 以获取授权码
  2. 用授权码交换访问令牌
  3. 使用访问令牌授权对产品 API 的任何调用
  4. 检查应用的网站访问权限

我成功通过了第一步。但是在第二步,我获取令牌的 POST 请求失败了。 这是我的请求数据

    {
    "grant_type":"authorization_code",
    "client_id":"xxx", 
    "client_secret":"xxx",
    "code":"xxx", // I receive this code from callback url from atlassian login page
    "redirect_uri":"http://localhost:4200/"}

这是标题:

{'Content-Type': 'application/json'}

这是我收到的:

{"error":"invalid_grant","error_description":"Invalid authorization code"}

这是用 Angular 10 编写的请求代码:

this.http
        .post(
          'https://auth.atlassian.com/oauth/token', {
            grant_type: 'authorization_code',
            client_id: environment.oauth.clientID,
            client_secret: environment.oauth.secret,
            code: codeStr,
            redirect_uri: environment.oauth.redirect_uri
          }, {
            headers: exchangeAuthCodeHeader,
            responseType: 'json'}
        ).subscribe((data) => console.log(data), (error) => console.log(error));

我已经陷入这个错误好几天了:( 任何想法都会有很大帮助。

【问题讨论】:

    标签: angular oauth-2.0 http-status-code-403


    【解决方案1】:

    我认为这是因为您尝试使用相同的代码两次。

    一旦您授权 Jira,您被重定向到的路由可能会立即使用该代码。检查http://localhost:4200/ 上是否有请求处理程序。

    如果你这样做,是在哪里调用https://auth.atlassian.com/oauth/token 的请求?如果是这样,代码会立即用于重定向 URL 的 get 请求

    【讨论】:

      猜你喜欢
      • 2019-05-17
      • 2015-09-04
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      • 2018-10-28
      • 2011-10-25
      相关资源
      最近更新 更多