我正在尝试在 Alexa Skill 中实现 LWA(接受 Grant 以便将事件发送到 Alexa)。我过去已经在已发布的技能中成功完成了此操作,因此我只是在 LWA 控制台上创建了一个新的安全配置文件,复制了 client_id 和 client_secret 并将请求形成为:
const data = {
"grant_type": grant_type,
"client_id": client_id,
"client_secret": client_secret,
"code": code,
};
let authResponse = await axios.post(url, data,
{headers: {'content-type': 'application/x-www-form-urlencoded'}}
);
我收到以下错误消息:400 错误请求:
{
"error_description": "The request has an invalid grant parameter : code",
"error": "invalid_grant"
}
我从 LWA 开发者控制台安全设置中为我的域添加了 client_id 和 client_secret。我不明白为什么我会遇到这个错误。我从 AcceptGrant 指令获得的“代码”,grant_type 是“authorization_code”。谁能帮我解决这个问题吗?
另外:在我发布的技能中,此功能完美无缺,Lambda 函数中提到的 client_id 和 client_secret 与该域的 LWA 安全设置中提到的值不同,我不确定为什么会这样,因为我记得使用LWA 安全设置中的值,这些值会随时间变化吗?
亚马逊的文档基本上给出了错误代码“无效授权”的 2 个原因。
invalid_grant The authorization code is invalid, expired, revoked, or was issued to a different client_id.
授权代码不好,或者随授权请求一起发送的客户端 ID 与令牌请求中的客户端 ID 不同。