authorization
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
@@ -9,6 +10,7 @@ namespace TURN.Services.Chess
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
ConfigureSwagger(services);
|
||||
ConfigureAuthorization(services);
|
||||
_ = services.AddControllers();
|
||||
_ = services.AddControllers().AddNewtonsoftJson(jsonOptions =>
|
||||
{
|
||||
@@ -21,6 +23,8 @@ namespace TURN.Services.Chess
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
_ = app.UseRouting();
|
||||
_ = app.UseAuthentication();
|
||||
_ = app.UseAuthorization();
|
||||
_ = app.UseSwagger();
|
||||
_ = app.UseSwaggerUI();
|
||||
_ = app.UseEndpoints(endpoints =>
|
||||
@@ -47,5 +51,24 @@ namespace TURN.Services.Chess
|
||||
});
|
||||
_ = services.AddSwaggerGenNewtonsoftSupport();
|
||||
}
|
||||
|
||||
private void ConfigureAuthorization(IServiceCollection services)
|
||||
{
|
||||
_ = services.AddAuthentication()
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidIssuer = AuthOptions.ISSUER,
|
||||
ValidateAudience = true,
|
||||
ValidAudience = AuthOptions.AUDIENCE,
|
||||
ValidateLifetime = true,
|
||||
IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(),
|
||||
ValidateIssuerSigningKey = true,
|
||||
};
|
||||
});
|
||||
_ = services.AddAuthorization();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user