Good day.
- I request an access token with IdentityServer
- I am accessing my API after starting the webapi server.
- After that, using the current access token, I can access my api, even if the IdentityServer is turned off.
My question: Is this the correct logic of work? Shouldn't the IdentityServer be called on every call to my api and check the access token?
If not, how can I refuse the access token if my user's credentials have been changed and I need to renew the token?
Startup.cs:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers().RequireAuthorization("ApiScope");
//.RequireAuthorization("AdminSecure");
});
}
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options =>
{
options.Authority = Configuration.GetValue<string>("IdentityServerUrl");
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false
};
});
services.AddAuthorization(options =>
{
options.AddPolicy("ApiScope", policy =>
policy.RequireClaim("client_id", "secret"));
options.AddPolicy("UserSecure", policy =>
policy.RequireClaim("roleType", "userCode"));
options.AddPolicy("AdminSecure", policy =>
policy.RequireClaim("roleType", "adminCode"));
});
}