Auth0 SPA+.net8

Ready to post? :mag: First, try searching for your answer.
I am using auth0 react SDK and following the React+.net.

I am using .net 8 and dependency injection to add authentication. All my code is similar to the one in SDK quickstart but I am unable to get the application working. I deployed frontend and backend on the same port. Added cross origins inside the server.

I am using organisation auth0 tenant.

builder.Services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;

}).AddJwtBearer(o =>
{
    //Auth0
    o.Authority = jwtAuth.Issuer;//Domain
    o.RequireHttpsMetadata = false;
    o.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateAudience = false,
        ValidateIssuerSigningKey = true
    };
    o.Events = new JwtBearerEvents()
    {
        OnAuthenticationFailed = c =>
        {
            string logFilePath = "log.txt";

            // Create a StreamWriter to write logs to a text file
            using (StreamWriter writer = new StreamWriter(logFilePath, append: true))
            {
                writer.WriteLine(c.Exception.ToString());
                writer.WriteLine(c.Options.Audience);
                writer.WriteLine(c.Options.Authority);
                writer.WriteLine(c.Options.TokenValidationParameters.AuthenticationType);
                writer.WriteLine(c.Options.ClaimsIssuer);
                // Add more log entries as needed
            }
            Console.WriteLine(c.Exception.ToString());
            return Task.CompletedTask;
        }
    };
});

I am getting two errors for the same.

  1. IDX14100: JWT is not well formed, there are no dots (.)
  2. IDX10609: Decryption failed. No Keys tried:

Please help.

Audience parameter is mandatory while sending these requests from frontend. It works after adding the audience.

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