Umbraco-OpenIdConnect-Example icon indicating copy to clipboard operation
Umbraco-OpenIdConnect-Example copied to clipboard

/signin-oidc - OpenIdConnectAuthenticationHandler: message.State is null or empty.

Open chrisbrasington opened this issue 2 years ago • 2 comments

Hey first off this code sample is fantastic, definitely gets me up and running.

I noticed an oddity - when I tried to implement an OpenIdConnect provider (before reading umbraco documentation and using member auto-linking), I hit a snag where my AuthenticationMiddleware and the default callback path of /signin-oidc error.

I noticed this project also exhibits the same error where navigation to /signin-oidc has an exception reproudicble by just running this project.

Do you know more about why this may be or an adjustment that can be made during AddOpenIdConnect? Using IUmbracoBuilder.AddMemberExternalLogins was just slightly different enough from a non-umbraco sample I had working, so this threw me off for some time until I found this project.

Exception: OpenIdConnectAuthenticationHandler: message.State is null or empty.

Unknown location Exception: An error was encountered while handling the remote login.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()

Exception: An error was encountered while handling the remote login.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in MiniProfilerMiddleware.cs
Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass6_1+<<UseMiddlewareInterface>b__1>d.MoveNext()
Umbraco.Cms.Web.Common.Middleware.PreviewAuthenticationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass6_1+<<UseMiddlewareInterface>b__1>d.MoveNext()
Umbraco.Cms.Web.Common.Middleware.UmbracoRequestLoggingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass6_1+<<UseMiddlewareInterface>b__1>d.MoveNext()
SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext httpContext, bool retry)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

chrisbrasington avatar Aug 31 '23 19:08 chrisbrasington

image

chrisbrasington avatar Aug 31 '23 19:08 chrisbrasington

Hi,

I think adding options.UseSecurityTokenValidator = true; have solved the issue for me.

logins.AddMemberLogin(
    memberAuthenticationBuilder =>
    {
        memberAuthenticationBuilder.AddOpenIdConnect(
            // The scheme must be set with this method to work for the umbraco members
            memberAuthenticationBuilder.SchemeForMembers(OpenIdConnectMemberExternalLoginProviderOptions.SchemeName),
            options =>
            {
                // START To fix error when going to /signin.oidc - see https://stackoverflow.com/questions/72922593/asp-net-core-openidconnect-message-state-is-null-or-empty
                //options.SkipUnrecognizedRequests = true;
                options.UseSecurityTokenValidator = true;
                // END

                var config = builder.Config;

alispire avatar Sep 11 '24 11:09 alispire