我将把我的角度应用程序与Jira cloud集成在一起。为了验证用户身份,Atlassian使用OAuth 2.0允许外部应用程序代表用户访问产品API。我遵循了this page
的指示我成功地通过了第一步。但是在第二步,获取令牌的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));
我在这个错误中停留了几天:( 任何想法都会有很大帮助。
答案 0 :(得分:0)
我认为这是因为您尝试两次使用相同的代码。
一旦您授权了Jira,也许您重定向到的路由会立即使用该代码。检查您在http://localhost:4200/
上是否有请求处理程序。
如果这样做,是在哪里调用https://auth.atlassian.com/oauth/token
的请求?如果是这样,该代码将立即用于get请求中以redirect_url