OpenID Connect with ASP NET Core 3.1 没有众所周知的 URL

OpenID Connect with ASP NET Core 3.1 without well-known URL

我正在尝试以这种方式使用 ASP.NET Core 3.1 配置 OpenID Connect:

 .AddOpenIdConnect(cfg =>
                {
                    cfg.Authority = "https://myurl.io";
                    cfg.ClientId = "123455555";
                    cfg.ClientSecret = "11111";
                    cfg.ResponseType = "code";
                    cfg.Scope.Clear();
                    cfg.Scope.Add("openid");
                });

但是当我尝试启动应用程序时出现以下错误:

System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.

嗯,我知道这是因为我没有一个众所周知的medadataurl,有没有办法忽略这个url并在[=13]中手动填写信息=] ?

可以直接指定配置:

services
    .AddAuthentication()
    .AddOpenIdConnect(options => {
        options.Configuration = new OpenIdConnectConfiguration
        {
            JwksUri = "",
            AuthorizationEndpoint = "",
            TokenEndpoint = "",
            UserInfoEndpoint = "",
            Issuer = "",
            // ...
        };
    })

根据您的需要,您可能至少需要填写:

  • 授权端点
  • 令牌端点
  • 用户信息端点
  • 发行人
  • jwks 端点(或以不同方式执行验证)