public static void RegisterJWT(this IServiceCollection service, JWTConfigurationModel JwtSection) { service.AddScoped <ICurrentUser, CurrentUser>(); service.AddScoped <IJWTService>(provider => new JWTService(JwtSection)); var key = Encoding.ASCII.GetBytes(JwtSection.Secret); service.AddAuthentication(option => { option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; option.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(option => { option.RequireHttpsMetadata = false; option.SaveToken = true; option.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false, }; }); }
public JWTService(JWTConfigurationModel configuration) { this.configuration = configuration; }