Auth0 授权者拒绝来自服务的 JWT 令牌 - "jwt issuer invalid. expected: https://myservice.auth0.com"
Auth0 authorizor rejects JWT token from service - "jwt issuer invalid. expected: https://myservice.auth0.com"
我正在浏览将 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是我设置的auth0api。这很令人困惑,因为我已经通过这种方法获得了 jwt 令牌:
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"}'
生成的令牌可以在 https://jwt.io/, and it reports the iss field as https://MYSERVICE.auth0.com
处加载到调试器工具中
是否存在可能导致此问题的错误配置?
在阅读了您的问题后通读了整个教程,这对我有用(最近已经这样做了)。
不清楚,但从您报告的相关错误消息来看,预期的发行人似乎没有尾随 /
。
然而,我的确实有。这是来自 JWT.IO 的正在运行的令牌的屏幕截图。
可以简单地发送 API(使用邮递员)并将其附加为授权承载 {{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 令牌 iss
和 aud
(受众)值。
晚会有点晚,但这适用于我的 Blazor WASM ASP.Net Core 3.1 Web API 项目,当我设置自定义域并收到相同的错误时。
我的解决方法是在我的网络服务应用程序的 Startup.cs class 中设置 TokenValidationParameters.ValidIssuer = [MY_CUSTOM_DOMAIN]。
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.Authority = Configuration[“Auth0:Authority”];
options.Audience = Configuration[“Auth0:ApiIdentifier”];
options.TokenValidationParameters.ValidIssuer = Configuration[“Auth0:Issuer”];
});
}
这是我的 appsettings.config 服务器:
{
“AllowedHosts”: “*”,
“Auth0”: {
“Authority”: “[AUTH0_TENANT_DOMAIN]”, (i.e. https://prod-mydomain.us.auth0.com)
“Issuer”: “[MY_CUSTOM_DOMAIN]”, (i.e. https://login.mycustomdomain.net/)
“ApiIdentifier”: “[MY_API_DOMAIN]” (i.e. https://example.net/api)
}
}
重要! => 对于我的自定义域,我必须在 URL 中包含一个尾随的“/”,如下所示:https://login.mycustomdomain.net/"。您可以通过查看在调用 Web 服务期间传递的不记名令牌(@ jwt.io 或 jwt.ms)中找到的 ISS 值来验证是否需要尾随“/”。
我正在浏览将 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是我设置的auth0api。这很令人困惑,因为我已经通过这种方法获得了 jwt 令牌:
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"}'
生成的令牌可以在 https://jwt.io/, and it reports the iss field as https://MYSERVICE.auth0.com
处加载到调试器工具中是否存在可能导致此问题的错误配置?
在阅读了您的问题后通读了整个教程,这对我有用(最近已经这样做了)。
不清楚,但从您报告的相关错误消息来看,预期的发行人似乎没有尾随 /
。
然而,我的确实有。这是来自 JWT.IO 的正在运行的令牌的屏幕截图。
可以简单地发送 API(使用邮递员)并将其附加为授权承载 {{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 令牌 iss
和 aud
(受众)值。
晚会有点晚,但这适用于我的 Blazor WASM ASP.Net Core 3.1 Web API 项目,当我设置自定义域并收到相同的错误时。
我的解决方法是在我的网络服务应用程序的 Startup.cs class 中设置 TokenValidationParameters.ValidIssuer = [MY_CUSTOM_DOMAIN]。
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.Authority = Configuration[“Auth0:Authority”];
options.Audience = Configuration[“Auth0:ApiIdentifier”];
options.TokenValidationParameters.ValidIssuer = Configuration[“Auth0:Issuer”];
});
}
这是我的 appsettings.config 服务器:
{
“AllowedHosts”: “*”,
“Auth0”: {
“Authority”: “[AUTH0_TENANT_DOMAIN]”, (i.e. https://prod-mydomain.us.auth0.com)
“Issuer”: “[MY_CUSTOM_DOMAIN]”, (i.e. https://login.mycustomdomain.net/)
“ApiIdentifier”: “[MY_API_DOMAIN]” (i.e. https://example.net/api)
}
}
重要! => 对于我的自定义域,我必须在 URL 中包含一个尾随的“/”,如下所示:https://login.mycustomdomain.net/"。您可以通过查看在调用 Web 服务期间传递的不记名令牌(@ jwt.io 或 jwt.ms)中找到的 ISS 值来验证是否需要尾随“/”。