javascript - Auth0 授权者拒绝来自服务的 JWT token - "jwt issuer invalid. expected: https://myservice.auth0.com"

标签 javascript aws-lambda aws-api-gateway auth0

我正在浏览将 auth0 设置为此处列出的 AWS 的 API 网关授权方的教程:https://auth0.com/docs/integrations/aws-api-gateway/custom-authorizers

我正在使用此处推荐的授权方:https://github.com/auth0-samples/jwt-rsa-aws-custom-authorizer

唯一的修改是配置文件。

但是,在测试授权函数时,出现如下错误:

{"name":"JsonWebTokenError","message":"jwt issuer invalid. expected: https://MYSERVICE.auth0.com"}

其中 MYSERVICE 是我设置的 auth0 api。这很令人困惑,因为我已经通过这种方法获得了 jwt token :

curl --request POST \
--url https://MYSERVICE.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"MY_ID","client_secret":"MY_SECRET","audience":"TestApi","grant_type":"client_credentials"}'

生成的 token 可以加载到位于 https://jwt.io/ 的调试器工具中,并将 iss 字段报告为 https://MYSERVICE.auth0.com

enter image description here

是否存在可能导致此问题的错误配置?

最佳答案

在阅读您的问题后通读了整个教程,这对我有用(最近已经这样做了)。

不清楚,但从您报告的错误消息来看,预期的发行人似乎没有尾随 /

但是,我的确实有。这是来自 JWT.IO 的正在运行的 token 的屏幕截图。

enter image description here

可以简单地发送 API(使用 postman )并将其附加为 Authorization Bearer {{token}} header 。使用教程的 api (AWS petshop),接收输出:

[
    {
        "id": 1,
        "type": "dog",
        "price": 249.99
    },
    {
        "id": 2,
        "type": "cat",
        "price": 124.99
    },
    {
        "id": 3,
        "type": "fish",
        "price": 0.99
    }
]

有助于查看您的 JWT token issaud(受众)值。

关于javascript - Auth0 授权者拒绝来自服务的 JWT token - "jwt issuer invalid. expected: https://myservice.auth0.com",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49410108/

相关文章:

javascript - 将回调函数作为参数返回 false

amazon-web-services - 如何自动化我的无服务器 Web 应用程序的端到端测试?

javascript - 屏幕宽度变化时无法使 div 元素居中

javascript - 在 ReactJS/Javascript Es6 中使用哈希声明变量

javascript - 未定义不是一个函数

aws-lambda - AWS Lambda/SAM : How to get invocation URI from CLI?

amazon-web-services - 在 AWS API Gateway 中导出正文映射模板

http - 在 AWS API Gateway 响应正文中修改的数据

amazon-web-services - AWS API Gateway 授权方谷歌登录