angular - atlassian cloud oauth 2.0,POST 请求获取令牌时出现错误 403
问题描述
我打算将我的 Angular 应用程序与 Jira 云集成。为了对用户进行身份验证,Atlassian 使用 OAuth 2.0 让外部应用程序代表用户访问产品 API。我按照此页面的说明进行操作
- 将用户定向到授权 URL 以获取授权码
- 交换访问令牌的授权码
- 使用访问令牌授权对产品 API 的任何调用
- 检查应用程序的站点访问权限
我顺利通过了第一步。但是在第二步,我获取令牌的 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));
我已经陷入这个错误几天了:(任何想法都会有很大帮助。
解决方案
我认为这是因为您尝试使用相同的代码两次。
一旦您授权 Jira,您被重定向到的路由可能会立即使用该代码。检查您是否有请求处理程序http://localhost:4200/
。
如果你这样做了,是在哪里https://auth.atlassian.com/oauth/token
调用请求?如果是这样,代码会立即用于对 redirect_url 的 get 请求
推荐阅读
- c# - 使用 System.Text.Encoding.Unicode.GetBytes(aString) 时是否应该检查字节顺序?
- google-sheets - 如何计算当天剩余时间
- python - python脚本 - 调用函数的问题
- javascript - 如何读取数组nodejs中存在的文件
- apache-spark - 我们可以为所有作业/应用程序使用相同的 Spark Config 吗?
- node.js - 无法使用 nestjs-joi lib 对 mongoose 模式进行验证
- python - 列表中的 Python 算法
- c++ - 如何在 C++ 中捕获异常?
- json - 无法使用 VBA 从网页解析 JSON 中的某个字段
- r - 如何使用 hist() 将统计信息放在输出图上?