Try our conversational search powered by Generative AI!

services.AddOpenIDConnectUI() misses JSON configuration settings

Vote:
 

Hello,

I have a very dumb issue and I really cannot find any info on any website regarding the error.

First, I've added OpenIDConnect like this:

        services.AddCmsAspNetIdentity<SiteUser>(options =>
        {
        });

        services.AddOpenIDConnect<SiteUser>(
            useDevelopmentCertificate: true,
            createSchema: true,
            configureOptions: configureOptions =>
            {
                if (String.IsNullOrEmpty(configureOptions.ConnectionStringOptions?.ConnectionString))
                {
                    configureOptions.ConnectionStringOptions = new ConnectionStringOptions()
                    {
                        Name = "EcfSqlConnection",
                        ConnectionString = this.configurationProvider.GetConnectionString("EcfSqlConnection")
                    };
                }
                
                var application = new OpenIDConnectApplication()
                {
                    ClientId = "postman-client",
                    ClientSecret = "postman",
                    Scopes =
                    {
                        ContentDeliveryApiOptionsDefaults.Scope,
                        ContentManagementApiOptionsDefaults.Scope,
                        ContentDefinitionsApiOptionsDefaults.Scope,
                        ServiceApiOptionsDefaults.Scope
                    }
                };                  
                
                application.RedirectUris.Add(new Uri("https://oauth.pstmn.io/v1/callback"));
                
                configureOptions.Applications.Add(application);     
                
            }, configureSqlServerOptions: null);

Then, I've added all the possible configurations for the service API:

        services.ConfigureContentApiOptions(options =>
        {
            options.EnablePreviewFeatures = true;
            options.IncludeEmptyContentProperties = true;
            options.FlattenPropertyModel = false;
            options.IncludeMasterLanguage = false; 
                
        });

        services.AddContentDeliveryApi(
                OpenIDConnectOptionsDefaults.AuthenticationScheme, options =>
                {
                    options.SiteDefinitionApiEnabled = true;
                })
            .WithFriendlyUrl()
            .WithSiteBasedCors();

        services.AddCommerceApi<SiteUser>(OpenIDConnectOptionsDefaults.AuthenticationScheme, o =>
        {
            o.DisableScopeValidation = true;
        });
        
        // Content Definitions API
        services.AddContentDefinitionsApi(options =>
        {
            // Accept anonymous calls
            options.DisableScopeValidation = true;
        });

        // Content Management
        services.AddContentManagementApi(OpenIDConnectOptionsDefaults.AuthenticationScheme, options =>
        {
            // Accept anonymous calls
            options.DisableScopeValidation = true;
        });

        // Service API configuration
        services.AddServiceApiAuthorization(OpenIDConnectOptionsDefaults.AuthenticationScheme, options =>
        {
            options.DisableScopeValidation = true;
        });

        services.AddCors(options =>
        {
            options.AddPolicy(name: "Standard Policy", builder =>
            {
                builder
                    .AllowAnyHeader()
                    .AllowAnyOrigin()
                    .AllowAnyMethod();
            });
        });

        services.ConfigureContentDeliveryApiSerializer(settings =>
            settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore);
        
        services.AddOpenIDConnectUI();

The problem is that if I navigate to the admin interface in the Settings / OpenIDConnect page, I don't see any registered applications and in the log I get the following error:

 System.TypeInitializationException: The type initializer for 'EPiServer.OpenIDConnect.UI.Conventions.JsonOutputFormatterFilter' threw an exception.
       ---> System.InvalidOperationException: JsonSerializerOptions instance must specify a TypeInfoResolver setting before being marked as read-only.
         at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerOptionsNoTypeInfoResolverSpecified()
         at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter..ctor(JsonSerializerOptions jsonSerializerOptions)
         at EPiServer.OpenIDConnect.UI.Conventions.JsonOutputFormatterFilter..cctor()
         --- End of inner exception stack trace ---
         at EPiServer.OpenIDConnect.UI.Conventions.JsonOutputFormatterFilter.OnActionExecuted(ActionExecutedContext context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at Mediachase.Commerce.Anonymous.Internal.AnonymousIdMiddleware.Invoke(HttpContext httpContext)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Is there someone who understands where is the issue?

Thank you,

Evdin

#321398
May 02, 2024 12:40
Vote:
 

Do you happen to be on .NET 8? If so -- I believe there's a known issue with .NET 8 + the OpenIdConnect package: 

https://world.optimizely.com/support/bug-list/bug/CMS-33404 

#321410
May 02, 2024 16:53
Vote:
 

Thank you very much. Yes, indeed, I'm using .net 8 and I really don't plan to go back to .net 6 - do you or anyone else knows when an update or fix can arrive?

Thanks,

Evdin

#321412
May 02, 2024 19:27
Daniel Isaacs - May 03, 2024 17:04
I don't know the timeline, but will update here if/when I get one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.