My React.js frontend is still sending JWE tokens back to my C# backend despite having set the correct audience and following all documentation and posts I have been able to find on this board.
Update: I went through my auth0 logs and it says everything is working properly. I am authenticating and then authorizing, but the token being sent is still a JWE. This is where I am calling the audience. Am i doing it wrong?
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = "MyAuthority";
options.Audience = "MyAudience";
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var authorizationHeader = context.Request.Headers.Authorization.FirstOrDefault();
Log.Information("Authorization Header: {AuthorizationHeader}", authorizationHeader);
return Task.CompletedTask;
},
OnTokenValidated = context =>
{
Log.Information("Token validated: {Token}", context.SecurityToken);
return Task.CompletedTask;
},
OnAuthenticationFailed = context =>
{
Log.Error("Authentication failed: {Exception}", context.Exception);
return Task.CompletedTask;
},
OnChallenge = context =>
{
Log.Warning("A challenge occurred: {Error}", context.Error);
return Task.CompletedTask;
}
};
});
[HttpGet("Endpoint")]
[Authorize]
public ActionResult<List<Dictionary<string, object>>> GetEndpoint()
{
List<Dictionary<string, object>> result = Service.GetEndpoint();
return Ok(result);
}