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: