Atlassian Cloud OAuth 2.0,POST请求上的错误403以获取令牌

时间:2020-07-29 17:24:40

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

我将把我的角度应用程序与Jira cloud集成在一起。为了验证用户身份,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));

我在这个错误中停留了几天:( 任何想法都会有很大帮助。

1 个答案:

答案 0 :(得分:0)

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

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

如果这样做,是在哪里调用https://auth.atlassian.com/oauth/token的请求?如果是这样,该代码将立即用于get请求中以redirect_url