spring - 尝试刷新访问令牌时出现“未经授权”错误
问题描述
我正在尝试按照本教程刷新用户的访问令牌。
但是,我越来越
{
"error":"unauthorized",
"error_description":"Full authentication is required to access this resource"
}
而且我看不到缺少什么。
以下是我oauth/refresh
在 Angular 应用程序中构建请求的方式:
refreshToken() {
this.logger.info('Attempting to refresh access token');
const headers = new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')
// CLIENT_ID:CLIENT_SECRET
.set('Authorization', 'Basic Q0xJRU5UX0lEOkNMSUVOVF9TRUNSRVQ=');
const payload = {
refresh_token: AuthenticationService.getRefreshToken(),
grant_type: 'refresh_token'
};
return this.http.post(environment.apiUrl + '/oauth/refresh',
payload, {headers: headers})
.pipe(map(r => r));
}
我在这里想念什么?
解决方案
好吧,我几乎是对的。
首先,我确实使用了错误的端点/oauth/refresh
——我不知道为什么我认为它存在。它必须是/oauth/token
。
有效载荷也通过 URL 参数发送:
const payload = `refresh_token=${AuthenticationService.getRefreshToken()}&grant_type=refresh_token`;
所以最后我得到了这个工作:
refreshToken() {
this.logger.info('Attempting to refresh access token');
const headers = new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')
.set('Authorization', 'Basic Q0xJRU5UX0lEOkNMSUVOVF9TRUNSRVQ=');
const payload = `refresh_token=${AuthenticationService.getRefreshToken()}&grant_type=refresh_token`;
return this.http.post(environment.apiUrl + '/oauth/token',
payload, {headers: headers})
.pipe(map(r => r));
}
推荐阅读
- c# - C# 最佳实践 (LINQ) 检查字符串列表/数组中的字符串
- digital-ocean - 数字海滴
- javascript - 如何将excel文件(exceljs)上传到s3
- flutter - 使用 Flutter with IOS 接收共享文件意图
- javascript - 分页逻辑 - Vue
- javascript - 在 Node js 中不使用 Buffer 的情况下将字符串转换为 base64 的替代方法
- json - 我无法使用 Swift JSON 打印到 TableView 数据
- c# - VlcControl.TakeSnapshot 生成文件但为空
- android - Kotlin 使用协程处理改造请求
- python - 重塑阵列以重组阵列拼贴