Recently I’ve updated my front end website from Angular 12 to 15 after about 2 years and I redownloaded the packages again and I also had to reimplement Auth0 because now it uses a different codebase since the last time. I can log in with it fine, but trying to use it to authenticate with my C# Web API is completely broken.
The Quickstart for AuthModule is completely wrong. It doesn’t even use the correct variable name for one of them and there’s a missing comma. Even then, it was missing a redirect-uri, which caused it to throw an error after logging in. Now, no matter what settings I’ve used, I keep getting a 401 error whenever I try to call a private route in my API (anything with the [Authorize] tag), but public routes work normally. I cannot find any solution for this. I’ve checked my API configurations, and I don’t think that’s the case because it basically uses the same code as the last version.
Attached is my declaration for AuthModule in app.module.ts. I need a solution to this urgently.
AuthModule.forRoot({
domain: 'APP_DOMAIN',
clientId: 'APP_CLIENT_ID',
authorizationParams: {
audience: 'API_IDENTIFIER',
scope: 'read:messages',
redirect_uri: window.location.origin
},
httpInterceptor: {
allowedList: [
{
uri: 'API_IDENTIFIER/*',
tokenOptions: {
authorizationParams: {
audience: 'API_IDENTIFIER',
scope: 'read:messages'
}
}
}
]
}
}),
I even used the C# sample project and it gives me the same problems. Am I missing something. here?
var domain = $"https://{Configuration["Auth0:Domain"]}/";
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = domain;
options.Audience = Configuration["Auth0:Audience"];
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimTypes.NameIdentifier
};
});