Share via

OpenIdConnectOptions Validate Method Throwing Exception in ASP.NET 6.0

Anonymous
2022-04-01T16:18:40+00:00

I have a simple 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 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.

Windows for home | Windows 10 | Security and privacy

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-04-02T02:32:44+00:00

    Hi, Sam_937

    Welcome to the Microsoft Community.

    Sorry, this question is beyond our capabilities, we suggest you post your question to:

    Developer tools, technical documentation and coding examples | Microsoft Docs

    There are more specialized experts out there who can help you.

    Thank you for your understanding and support.

    Best regards

    Hinata

    Microsoft Community Support Specialist

    Was this answer helpful?

    0 comments No comments