Mat*_*ner 6 amazon-web-services amazon-cognito
成功检索身份验证代码后,按照https://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html 中的文档进行操作。
据我所知,这正是请求的设置方式:
import request from 'request'
function fetchToken(code: any, clientId: string, clientSecret: string) {
try {
let tokenEndpoint = `https://example.auth.us-east-1.amazoncognito.com/oauth2/token`
const clientIdEncoded = Buffer.from(`${clientId}:${clientSecret}`).toString('base64')
request.post({
url:tokenEndpoint,
headers: {
'Content-Type':'application/x-www-form-urlencoded',
'Authorization':`Basic ${clientIdEncoded}`
},
form: {
code,
'grant_type':'authorization_code',
'client_id':clientId,
'redirect_uri':'http://localhost:3000'
}},
function(err,httpResponse,body){
console.log(httpResponse.statusCode)
//400
console.log(httpResponse.statusMessage)
//Bad Request
if(err) {
console.error(err)
}
console.log(body)
//{"error":"unauthorized_client"}
})
} catch (error) {
console.error(error)
}
}
Run Code Online (Sandbox Code Playgroud)
为什么会得到unauthorized_client
?有没有更简单的方法来调试这个?
编辑:使用相同的请求在 Postman 中对此进行了测试并得到相同的错误
归档时间: |
|
查看次数: |
3319 次 |
最近记录: |