django - 错误:来自 django oauth2 服务器的“unsupported_grant_type”
问题描述
不知道为什么 django 不接受我对访问令牌的 POST 请求。我所有的参数都是正确的,并且我已经有了授权码,但是访问令牌的后续 POST 请求给了我这个错误。
从我从其他人那里读到的内容类型是正确的。如果 pkce 方面不准确,它会给我一个更具体的错误。
HttpErrorResponse 是
{ error: "unsupported_grant_type" } 400 bad request
requestToken(code: string, state: string) {
const clientState = sessionStorage.getItem('pkce-state');
if (clientState !== state) {
console.error('States do not match!');
}
const verifier = sessionStorage.getItem('pkce-verifier');
const params = new URLSearchParams({
grant_type: 'authorization_code',
redirect_uri: 'http://localhost:4200/dashboard',
client_id: 'client_id',
code,
state,
verifier
});
return this.http.post('http://localhost:8000/o/token/',
{
params
},
{
withCredentials: true,
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
}
)
});
}
也试过这个:
requestToken(code: string, state: string) {
const clientState = sessionStorage.getItem('pkce-state');
if (clientState !== state) {
console.error('States do not match!');
}
const verifier = sessionStorage.getItem('pkce-verifier');
return this.http.post('http://localhost:8000/o/token/',
{
grant_type: 'authorization_code',
redirect_uri: 'http://localhost:4200/dashboard',
client_id: 'client_id',
code,
state,
verifier
},
{
withCredentials: true,
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
}
)
});
}
解决方案
尝试精确匹配我写的第 7 步:
- 使用 code_verifier
- 去掉 state 参数,直接 https 消息到令牌端点时不需要该参数
错误消息通常具有误导性,但这将使您的消息 100% 符合标准,并希望能够奏效。
再说一次,Django总是有可能不正确支持这个流程......
推荐阅读
- directory - found.000 文件夹,dir0000.chk 文件夹
- c++ - 如何打印成员变量?
- karate - 空手道 - UI 自动化 - 是否可以获取 Web 元素的 Css 样式属性
- canvas - 使用 NativeScript 6 + VueJS 在 Canvas 上绘图
- c# - 用于更新子文档数组中特定字段的 MongoDB Shell 命令
- airflow-scheduler - 如何通过创建一个 DAG 来开始使用 Airflow,该 DAG 将调用我在另一个 repo 中的 python 代码(按计划)?
- python - 使用优化的最小化求解复合期权模型参数中的参数的错误
- python - SQLAlchemy:是否可以在同一个查询中组合“like”和“in”
- css - 引导边距左侧类在反应中不起作用
- kotlin - 我怎样才能将苛刻的地图传递给 Kotlin 上的另一个活动?