【问题标题】:How to configure IdentityServerAuthenticationOptions.Authority to use wildcards如何配置 IdentityServerAuthenticationOptions.Authority 以使用通配符
【发布时间】:2016-08-30 15:58:32
【问题描述】:

我使用 ASP.NET Core 成功设置了 IdentityServer4。

作为默认配置,我有这个:

IdentityServerAuthenticationOptions options = new IdentityServerAuthenticationOptions()
{
    Authority = "http://localhost:5000",                
    ScopeName = "scope",
    ScopeSecret = "ScopeSecret",
    AutomaticAuthenticate = true,
    AutomaticChallenge = true,
    RequireHttpsMetadata = false,                
};

现在,使用这个 guide 我配置为从配置文件中读取,因此它们可以是生产中的任何数字。

例如,如果我将 API 设置为在 http://*:5000 运行,那么客户端可以通过服务 IP 地址连接到它,例如 http://192.168.1.100:5000

一旦客户端获得 Bearer 令牌并尝试使用它,就会出现 Internal Server Error 并出现以下异常:

Unable to obtain configuration from: 
'http://*:5000/.well-known/openid-configuration'. 
---> System.IO.IOException: IDX10804: Unable to retrieve document from: 'http://*:5000/.well-known/openid-configuration'. 
---> System.UriFormatException: Invalid URI: The hostname could not be parsed.

将IdS4配置为具有动态权限的正确方法是什么?

更新

似乎问题出在 Issuer 上,有什么想法吗?

Microsoft.IdentityModel.Tokens.SecurityTokenInvalidIssuerException: 

IDX10205: Issuer validation failed. Issuer: 'http://192.168.1.100:5000'. Did not match: validationParameters.ValidIssuer: 'http://localhost:5000' or validationParameters.ValidIssuers: 'null'.

   at Microsoft.IdentityModel.Tokens.Validators.ValidateIssuer(String issuer, SecurityToken securityToken, TokenValidationParameters validationParameters)

【问题讨论】:

    标签: identityserver4 asp.net-core-webapi


    【解决方案1】:

    让我大吃一惊的是,我只需要为IssuerUri 设置一个值(几乎是任何值):

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        ////...
    
        var identiyBuilder = services.AddIdentityServer(options =>
        {
            options.RequireSsl = false;
            options.IssuerUri = "MyCompany";      
        });
    
        ////...
    }
    

    现在,通过上述配置,我可以通过任何 IP 地址使用该服务。

    【讨论】:

      【解决方案2】:

      我没有发现我可以输入MyCompany

      但在我的日志文件中,我有以下内容:

        Bearer was not authenticated. Failure message: IDX10205: Issuer validation failed. Issuer: 'https://crm.example.com'. Did not match: validationParameters.ValidIssuer: 'MyCompany' or validationParameters.ValidIssuers: 'null'.
      

      我不太清楚“发行人”是什么意思,但我能够接受“https://crm.example.com”并让事情与此相关:

       options.IssuerUri = "https://crm.example.com";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-17
        • 2019-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多