Home > Software engineering >  OpenID Connect with ASP NET Core 3.1 without well-known URL
OpenID Connect with ASP NET Core 3.1 without well-known URL

Time:09-22

I'm trying to configure OpenID Connect with ASP.NET Core 3.1 in this way:

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

But when I try to startup the application I got the following error:

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

Well, I know this is because I don't have a well-known medadata url, is there a way to ignore this url and fill in the information manually in Startup.cs ?

CodePudding user response:

You can specify the configuration directly:

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

Depending on your needs, you probably need to fill at least:

  • authorization endpoint
  • token endpoint
  • userinfo endpoint
  • issuer
  • jwks endpoint (or perform validation differently)
  • Related