如何配置IdentityServerAuthenticationOptions.Authority以使用通配符

Moh*_*hin 3 identityserver4 asp.net-core-webapi

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

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

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

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

例如,如果我将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.
Run Code Online (Sandbox Code Playgroud)

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

更新资料

看来问题出在发行人身上,对此有什么想法吗?

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)
Run Code Online (Sandbox Code Playgroud)

Moh*_*hin 5

出乎意料的是,我所需要的只是为设置一个值(几乎所有值)IssuerUri

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    ////...

    var identiyBuilder = services.AddIdentityServer(options =>
    {
        options.RequireSsl = false;
        options.IssuerUri = "MyCompany";      
    });

    ////...
}
Run Code Online (Sandbox Code Playgroud)

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