39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
![]() |
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|||
|
using Microsoft.Extensions.Configuration;
|
|||
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
using Microsoft.IdentityModel.Tokens;
|
|||
|
using System.Reflection;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace Hushian.Application
|
|||
|
{
|
|||
|
public static class ApplicationServicesRegistration
|
|||
|
{
|
|||
|
public static void ConfigureApplicationServices(this IServiceCollection services,
|
|||
|
IConfiguration configuration)
|
|||
|
{
|
|||
|
services.AddAutoMapper(Assembly.GetExecutingAssembly());
|
|||
|
services.AddAuthentication(options =>
|
|||
|
{
|
|||
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|||
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|||
|
})
|
|||
|
.AddJwtBearer(o =>
|
|||
|
{
|
|||
|
o.TokenValidationParameters = new TokenValidationParameters
|
|||
|
{
|
|||
|
ValidateIssuerSigningKey = true,
|
|||
|
ValidateIssuer = true,
|
|||
|
ValidateAudience = true,
|
|||
|
ValidateLifetime = true,
|
|||
|
ClockSkew = TimeSpan.Zero,
|
|||
|
ValidIssuer = configuration["JwtSettings:Issuer"],
|
|||
|
ValidAudience = configuration["JwtSettings:Audience"],
|
|||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JwtSettings:Key"]))
|
|||
|
};
|
|||
|
});
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|