OpenIdConnectOptions Validate Method Throwing Exception in ASP.NET 6.0

Sam 1 Reputation point

I have a new ASP.NET Core 6.0 web app, and I am trying to configure OpenID Connect (OIDC) in the Program.cs file. I am using "Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" in my .csproj file.

This is the code so far for my OIDC logic in my Program.cs file:

using Microsoft.IdentityModel.Protocols.OpenIdConnect;

var builder = WebApplication.CreateBuilder(args);

Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration oidcConfig = new OpenIdConnectConfiguration();
oidcConfig.TokenEndpoint = "";
oidcConfig.UserInfoEndpoint = "";
oidcConfig.JwksUri = "";

Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions oidcOptions = new Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions();
oidcOptions.Authority = "";
oidcOptions.MetadataAddress = "";
oidcOptions.Configuration = oidcConfig;
oidcOptions.ClientId = "xxxxxxxxxxxxxxx";
oidcOptions.ClientSecret = "xxxxxxxxxxxxxxx";
oidcOptions.ResponseType = OpenIdConnectResponseType.IdToken;
oidcOptions.GetClaimsFromUserInfoEndpoint = true;
oidcOptions.SaveTokens = true;

When I run my code and it gets to oidcOptions.Validate(), the following exception is thrown:

An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.AspNetCore.Authentication.OpenIdConnect.dll: 'Provide Authority, MetadataAddress, Configuration, or ConfigurationManager to OpenIdConnectOptions'

Why is this exception being thrown? When I run my code in debug mode, I can see that my oidcOptions object has the values I provided for Authority, MetadataAddress, and Configuration.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,175 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SurferOnWww 1,036 Reputation points

    The following document describes the settings in the Program.cs of ASP.NET Core MVC application when Duende IdentityServer is used:

    Interactive Applications with ASP.NET Core