Unable to unprotect the message.State when using two Auth0 clients in one ASP.NET Core app

I configured 2 Auth0 clients in a ASP.NET Core application in the startup:

   // Configure authentication for Auth0 for students
            // Scope:
            // - openid:  to indicate that the application intends to use OIDC to verify the user's identity (always).
            // - profile: to get name, nickname, and picture
            // - email:   to get email and email_verified
            services.AddAuth0WebAppAuthentication(CPConstants.AuthenticationSchemeStudent, options =>
            {
                options.Domain = Configuration["Auth0Student:Domain"];
                options.ClientId = Configuration["Auth0Student:ClientId"];
                options.ClientSecret = Configuration["Auth0Student:ClientSecret"];
                options.Scope = "openid profile email";
                options.ResponseType = "code";
                options.MaxAge = new TimeSpan(3, 0, 0);
                options.CookieAuthenticationScheme = CPConstants.CookieAuthenticationSchemeStudent;
            });

            // Configure authentication for Auth0 for external users
            // Scope:
            // - openid:  to indicate that the application intends to use OIDC to verify the user's identity (always).
            // - profile: to get name, nickname, and picture
            // - email:   to get email and email_verified
            services.AddAuth0WebAppAuthentication(CPConstants.AuthenticationSchemeExternalUser, options =>
            {
                options.Domain = Configuration["Auth0ExternalUser:Domain"];
                options.ClientId = Configuration["Auth0ExternalUser:ClientId"];
                options.ClientSecret = Configuration["Auth0ExternalUser:ClientSecret"];
                options.Scope = "openid profile email";
                options.ResponseType = "code";
                options.MaxAge = new TimeSpan(3, 0, 0);
                options.CookieAuthenticationScheme = CPConstants.CookieAuthenticationSchemeExternalUser;
            });

The first one works well. When I add the second (ExternalUser) as Authorize attribute on another controller:

   [Authorize(AuthenticationSchemes = CPConstants.AuthenticationSchemeExternalUser)]

And do a succesfull login when redirected to Auth0, it returns to my MVC application with the following error:

Were you able to solve this?

Hi mario, it is fixed and I think it had to do with the CallbackPath (configure that in Auth0 as well), in startup ConfigureServices we now have this:

           // Configure authentication for Auth0 for students
            // Scope:
            // - openid:  to indicate that the application intends to use OIDC to verify the user's identity (always).
            // - profile: to get name, nickname, and picture
            // - email:   to get email and email_verified
            services.AddAuth0WebAppAuthentication(CPConstants.AuthenticationSchemeStudent, options =>
            {
                options.CookieAuthenticationScheme = CPConstants.CookieAuthenticationSchemeStudent;
                options.CallbackPath = "/Student/callback";
                options.Domain = Configuration["Auth0Student:Domain"];
                options.ClientId = Configuration["Auth0Student:ClientId"];
                options.ClientSecret = Configuration["Auth0Student:ClientSecret"];
                options.Scope = "openid profile email";
                options.ResponseType = "code";
                options.MaxAge = new TimeSpan(3, 0, 0);
            });

            // Configure authentication for Auth0 for external users
            // Scope:
            // - openid:  to indicate that the application intends to use OIDC to verify the user's identity (always).
            // - profile: to get name, nickname, and picture
            // - email:   to get email and email_verified
            services.AddAuth0WebAppAuthentication(CPConstants.AuthenticationSchemeExternalUser, options =>
            {
                options.CookieAuthenticationScheme = CPConstants.CookieAuthenticationSchemeExternalUser;
                options.CallbackPath = "/ExternalUser/callback";
                options.Domain = Configuration["Auth0ExternalUser:Domain"];
                options.ClientId = Configuration["Auth0ExternalUser:ClientId"];
                options.ClientSecret = Configuration["Auth0ExternalUser:ClientSecret"];
                options.Scope = "openid profile email";
                options.ResponseType = "code";
                options.MaxAge = new TimeSpan(3, 0, 0);
     });
1 Like