ASP Net Core IdentityServer,生产环境中的“颁发者无效”

blo*_*low 6 bearer-token amazon-elastic-beanstalk identityserver4 jwt-auth asp.net-core-3.1

我正在尝试在生产(AWS Elasticbeanstalk 服务器)上部署一个使用 IdentityServer 的简单 asp 网络核心项目;我的测试项目基本上是启用了身份验证的 Visual Studio 2019 的 React.js 模板。

在开发中一切正常,但在生产中,当尝试使用 jwt 令牌对我的 api 进行身份验证时出现错误。

WWW-Authenticate: Bearer error="invalid_token", error_description="The issuer 'http://***.elasticbeanstalk.com' is invalid"
Run Code Online (Sandbox Code Playgroud)

使用的 access_token 是调用返回的内容

POST http://***.elasticbeanstalk.com/connect/token
Run Code Online (Sandbox Code Playgroud)

奇怪的行为是以下请求

GET http://***.elasticbeanstalk.com/connect/userinfo
Run Code Online (Sandbox Code Playgroud)

它正确返回了用户数据,这里使用了access_token,所以我认为令牌是正确的。

不幸的是,对我的 api 的请求因上述错误而失败。

我的Startup.cs代码是这样的:

WWW-Authenticate: Bearer error="invalid_token", error_description="The issuer 'http://***.elasticbeanstalk.com' is invalid"
Run Code Online (Sandbox Code Playgroud)

appsetting.json文件包含此:

POST http://***.elasticbeanstalk.com/connect/token
Run Code Online (Sandbox Code Playgroud)

小智 8

在您的启动中设置您的域地址

        services.AddIdentityServer(options =>
        {
            options.IssuerUri = "http://***.elasticbeanstalk.com";
        })
Run Code Online (Sandbox Code Playgroud)

  • 这似乎是正确的解决方案,但我不明白为什么需要设置它。[此处](http://docs.identityserver.io/en/3.1.0/reference/options.html)他们建议不要设置此属性,因为该值是由客户端请求推断的。 (3认同)