简体   繁体   English

无法从亚马逊获取访问令牌

[英]Can't get access token from amazon

I'm trying to add amazon sign in following "The Authorization CodeGrant" I get the code client side and send it to my node js express server but can't get the access token from amazon.我正在尝试在“授权 CodeGrant”之后添加亚马逊登录,我获取代码客户端并将其发送到我的节点 js 快递服务器,但无法从亚马逊获取访问令牌。 I get 500 Internal Storage Error and:我收到 500 内部存储错误,并且:

x-amzn-errortype': 'InternalFailure:http://internal.amazon.com/coral/com.amazon.coral.service/'

My code:我的代码:

async function getAmazonAccessTokenFromCode(code) {
    try {
        const { data } = await axios({
            url: 'https://api.amazon.com/auth/o2/token',
            method: 'POST',
            headers: {
                "Content-type": "application/x-www-form-urlencoded"
            },
            params: {
                grant_type: "authorization_code",
                code,
                client_id: "my_client_id",
                client_secret: "my_client_secret",
                redirect_uri: 'http://localhost:3000/amazon-auth',
            }
        })
        console.log("data", data)
        return data.access_token
    } catch (err) {
        console.log("err", err)
        return null
    }
}

I made it work by replacing "params" with "data" in the axios fetch request.我通过在 axios 获取请求中将“参数”替换为“数据”来使其工作。

Also, if it doesn't work try to use application/json in content type.此外,如果它不起作用,请尝试在内容类型中使用 application/json。 It worked for me.它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM