Angular -> C# authorization failure

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
        };
    });

Hey there!

Can you share precisely what quickstart or SDK are you trying to use in your implementation so we can try to help you? Thank you!

I followed this.

I’ve tried using the generated code in the page and I downloaded the sample app, too, and neither of them work.

Can I ask you to raise this as a GitHub issue here:

so we can work on that directly with the quickstart maintainer directly? Once you have a link to it you can share it here so we can ping them. Thank you!

Raised the issue.

1 Like

Thank you! I’ll ping the repo maintainers in a few minutes!

So I got it fixed, and it had to do with my application using the wrong settings.

But now I have another problem. After I upload my Web API (it’s hosted on AWS Elastic Beanstalk) and call a private route there, the authorization fails. If I run it locally, authorization works fine.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.