I want to build a JWT Security Token Service(.net core 2+) to provide authentication and authorization to many APIs(.net core 2+) without using IdentityServer or OAuth because I want no redirections.
The "JWT Authenticator" is working fine and has the routes
- POST Account: register new user
- POST Auth/Login: return a jwt token if credentials are valid
- POST Token: refresh the token
- POST Token/Revoke: revoke the token
However, I'm struggling to provide steps 4 and 5. I tried many options at API1/Startup.cs -> ConfigureServices, and couldn't get any results but 404 when calling GET API1/Resource. The ConfigureServices method is still this:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.Authority = "http://localhost:6000"; // JWT Authenticator address
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = _configuration.GetValue<string>("JwtIssuer"),
ValidAudience = _configuration.GetValue<string>("JwtAudience"),
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(_configuration.GetValue<string>("JwtSecretKey"))),
ClockSkew = TimeSpan.Zero
};
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
Is it possible to configure steps 4 and 5 using a method like AddJwtBearer? If not, what should I do? Use an Authorization Filter to API1 to intercept requests and make a request to JWT Authenticator to validate the token/get claims/etc?