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 = "https://removed.com";
oidcConfig.UserInfoEndpoint = "https://removed.com";
oidcConfig.JwksUri = "https://removed.com";
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions oidcOptions = new Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions();
oidcOptions.Authority = "https://removed.com";
oidcOptions.MetadataAddress = "https://removed.com";
oidcOptions.Configuration = oidcConfig;
oidcOptions.ClientId = "xxxxxxxxxxxxxxx";
oidcOptions.ClientSecret = "xxxxxxxxxxxxxxx";
oidcOptions.ResponseType = OpenIdConnectResponseType.IdToken;
oidcOptions.GetClaimsFromUserInfoEndpoint = true;
oidcOptions.SaveTokens = true;
oidcOptions.Validate();
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.