private static IServiceCollection AddTokenValidationParameters(this IServiceCollection services, JwtSettings jwtSettings, out TokenValidationParameters tokenValidationParameters) { tokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = jwtSettings.Issuer, ValidateAudience = true, ValidAudience = jwtSettings.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Secret)), ValidateLifetime = true, RequireExpirationTime = true, ClockSkew = TimeSpan.Zero, }; services.AddSingleton(tokenValidationParameters); return(services); }
private static IServiceCollection AddJwtSettings(this IServiceCollection services, IConfiguration configuration, out JwtSettings jwtSettings) { jwtSettings = new JwtSettings(); configuration.Bind(nameof(JwtSettings), jwtSettings); services.AddSingleton(jwtSettings); return(services); }