// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { IFactoriesManager factoriesManager = new FactoriesManager(); IDatabaseManager databaseManager = new DatabasesManager(); ConfigureCustomServices(factoriesManager, databaseManager); services.AddSingleton(typeof(IFactoriesManager), factoriesManager); services.AddSingleton(typeof(IDatabaseManager), databaseManager); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer( options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = true, ValidIssuer = AuthOptions.ISSUER, ValidateAudience = true, ValidAudience = AuthOptions.AUDIENCE, ValidateLifetime = true, LifetimeValidator = AuthOptions.GetLifeTimeValidationDel(), IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(), ValidateIssuerSigningKey = true }; }); services.AddMvc(options => options.EnableEndpointRouting = false) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddControllers(); }
public static void SetAuthentication(this IServiceCollection services) { services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer( options => { options.RequireHttpsMetadata = true; options.TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = true, ValidIssuer = AuthOptions.ISSUER, ValidateAudience = true, ValidAudience = AuthOptions.AUDIENCE, ValidateLifetime = true, LifetimeValidator = AuthOptions.GetLifeTimeValidationDel(), IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(), ValidateIssuerSigningKey = true }; }); }