Hi, I’m trying to use User Access token with postman in order to execute my Web Api in .Net Core 5.0 .
- I have created Api in auth0 with Identifier is my local address and port where my Web Api is running.
- In my Web Api I have followed the steps from Quick Start in my Auth0 Api. So in ConfigureServices(IServiceCollection services) I have:
var domain = $"https://{Configuration["Auth0:Domain"]}/";
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority ={Configuration["Auth0:Authority"]};
options.Audience = "http://localhost:12390/";
});
services.AddAuthorization(options =>
{
options.AddPolicy("Administrator", policy => policy.Requirements.Add(new HasScopeRequirement("Administrator", domain)));
});
services.AddSingleton<IAuthorizationHandler, HasScopeHandler>();
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
and in Configure(IApplicationBuilder app, IWebHostEnvironment env) I have
app.UseAuthentication();
app.UseAuthorization();
- I have decorated my controllers with [Authorize]
Now whenever I try to use user token (this one has the User Id in sub) in Postman I’m getting Unauthorized 401. And I really need to know the user that is logged in so that I can do other customizations. Please advice what I need to do in order to get my user Id in sub and be able to use user access tokens?
Please help