I am using auth0 with .net core web api, below are my configuration.
-
In my ConfigureServices() I have
services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.Authority = "https://xxxxxxx.auth0.com/"; options.Audience = "https://localhost:5001"; });
-
In my Configure() method I have
// 2. Enable authentication middleware app.UseAuthentication(); app.UseMvc();
And finally in my HomeController.cs
[HttpGet("private")]
[Authorize]
public IActionResult Private()
{
return Ok(new
{
Message = "Hello from a private endpoint! You need to be authenticated to see this."
});
}
And when I try to access the endpoint, with the right access token, using postman or my react app I am getting 401 unauthorized or www-authenticate: Bearer error="invalid_token"
I followed the documentation for examples, cannot figure out what I am doing wrong here. Please advice.