gpt4 book ai didi

alexa-skills-kit - 尽管 LWA 授权 token 有效,但 Alexa SMAPI 仍返回 HTTP 4xx

转载 作者:行者123 更新时间:2023-12-03 17:36:27 26 4
gpt4 key购买 nike

我目前正在努力将 Amazon Alexa 与我们当前的系统集成。我必须做的 TL;DR 版本是我应该能够通过 Alexa Skill Management API 以编程方式创建 Alexa 技能。

虽然这很简单,但我在身份验证阶段遇到了障碍(涉及登录亚马逊):

这应该起作用的方式是,您针对 SMAPI 端点发出的每个请求都必须在 Authorization 中包含授权 token 。 HTTP header 。

假设我向 https://api.amazonalexa.com/v0/skills 发出 POST 请求用这个 body :

{
"vendorId":"my-vendor-id",
"skillManifest": {
"publishingInformation": {
"locales": {
"en-US": {
"summary": "This is a sample Alexa skill.",
"examplePhrases": [
"Alexa, open sample skill.",
"Alexa, turn on kitchen lights.",
"Alexa, blink kitchen lights."
],
"keywords": [
"Smart Home",
"Lights",
"Smart Devices"
],
"name": "Sample custom skill name.",
"description": "This skill has basic and advanced smart devices control features."
}
},
"isAvailableWorldwide": false,
"testingInstructions": "1) Say 'Alexa, discover my devices' 2) Say 'Alexa, turn on sample lights'",
"category": "SMART_HOME",
"distributionCountries": [
"US",
"GB"
]
},
"apis": {
"custom": {
"endpoint": {
"uri": <some-aws-lambda-endpoint-uri>"
}
}
},
"manifestVersion": "1.0",
"privacyAndCompliance": {
"allowsPurchases": false,
"locales": {
"en-US": {
"termsOfUseUrl": "http://www.termsofuse.sampleskill.com",
"privacyPolicyUrl": "http://www.myprivacypolicy.sampleskill.com"
}
},
"isExportCompliant": true,
"isChildDirected": false,
"usesPersonalInfo": false
}
}
}

以及这些标题字段:
{
"Authorization":"<my-auth-token-that-i-get-from-lwa>"
}

预期的响应应采用以下格式:
{
"skill_id": "{skill_id}"
}

然而,这是我得到的回应:
{
"message": "User has not consented to this operation"
}

(尽管有问题的用户已经同意这些操作,这在这个权限请求数组中非常明显:
['profile profile:user_id alexa::ask:skills:readwrite alexa::ask:skills:test alexa::ask:models:readwrite alexa::ask:skills:test alexa::ask:models:read alexa::ask:skills:read']

)

此外,如果我添加 Bearer Authorization 的前缀这样的标题:
{
"Authorization":"Bearer <my-lwa-auth-token>"
}

我得到这个回应:
{
"message": "Token is invalid/expired"
}

考虑到身份验证 token 仅在十(可能是十五)分钟前生成并且仍在其保质期内(大约一个小时),这一点非常令人惊讶。

在另一个线程 here ,我读到亚马逊正在解决这个问题(2017 年 10 月 21 日)。同时,如果你已经找到了另一种方法,请你描述一下并帮助一个人吗?

最佳答案

从 Node 访问 SMAPI 的最简单方法是使用 SMAPI Node.js SDK,文档可用 here .
为了使用 SMAPI 进行身份验证,您需要执行以下操作:

  • 设置 LWA 安全配置文件。
  • 使用 ASK CLI 使用 ask util generate-lwa-tokens --client-id <Client ID> --client-confirmation <Client Secret> 将您的 LWA 客户端 ID 和客户端 key 交换为 LWA 刷新 token .
  • 初始化 SMAPI 节点 SDK 时使用此刷新 token :
  • const Alexa = require('ask-smapi-sdk');

    // specify the refreshTokenConfig with clientId, clientSecret and refreshToken generated in the previous step
    const refreshTokenConfig = {
    clientId,
    clientSecret,
    refreshToken
    }
    const smapiClient = new Alexa.StandardSmapiClientBuilder()
    .withRefreshTokenConfig(refreshTokenConfig)
    .client();
    然后您就可以通过 SDK 上的函数调用来访问 SMAPI!
    这方面的有用资源:
    https://levelup.gitconnected.com/email-yourself-daily-alexa-skill-metrics-updates-using-lambda-smapi-and-ses-9c16ac97c1f8

    关于alexa-skills-kit - 尽管 LWA 授权 token 有效,但 Alexa SMAPI 仍返回 HTTP 4xx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47389444/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com