【发布时间】:2019-05-30 21:47:12
【问题描述】:
我正在使用本机反应,我想从使用 oAuth 2 身份验证在 django 中创建的 api 获取访问令牌
我正在传递所有必需的详细信息,但我不知道为什么我会收到不受支持的授权类型的错误
fetch('MyApiUrl', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({
'grant_type': 'password',
'username': 'MyUserNameSettedInApi',
'password': 'PasswordSettedInApi',
'client_id': 'MyClientId',
'client_secret': 'MyClientSecret',
'scope': 'read Write'
})
})
.then((response) => response) <----tried response.json() but giving same error of grant type
.then((responseData) => {
console.log(responseData);
})
我的预期结果是我希望显示访问令牌 我得到的是
Response {type: "default", status: 400, ok: false, statusText: undefined, headers: Headers, …}
headers: Headers {map: {…}}
ok: false
status: 400
statusText: undefined
type: "default"
url: "http://MyUrl"
_bodyInit: "{"error": "unsupported_grant_type"}"
_bodyText: "{"error": "unsupported_grant_type"}"
__proto__: Object
请帮忙 提前致谢
【问题讨论】:
标签: react-native oauth-2.0 fetch access-token