// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddIdentityServer(Configuration, _environment, _logger); services.AddAuthentication(IdentityConstants.ApplicationScheme); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.Authority = "http://localhost:5000"; // Who do we trust? options.RequireHttpsMetadata = false; options.Audience = "api1"; // Who are we? }); services.AddCors(options => { options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); }); }); services.AddCors(o => { o.AddPolicy("CorsPolicy", _ => _.WithOrigins("http://localhost:5100", "http://localhost:5010", "https://localhost:5011", "https://localhost:5101").AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); IdentityModelEventSource.ShowPII = true; services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Title = "Protected api", Version = "v1" }); options.AddSecurityDefinition("oauth2", new OAuth2Scheme { Flow = "implicit", AuthorizationUrl = "https://localhost:5001/connect/authorize", Scopes = new Dictionary <string, string> { { "demo_api", "Demo API - full access" }, { "api1", "normal api" } } }); options.OperationFilter <AuthorizeCheckOperationFilter>(); }); RepositoryBootstraper.RegisterServices(services, Configuration); }
public void ConfigureServices(IServiceCollection services) { services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1); // Configure identity server services.AddIdentityServer(Configuration, Environment, _logger); services.AddAuthentication(IdentityConstants.ApplicationScheme); services.AddCors(options => { options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); }); }); RepositoryBootstraper.RegisterServices(services, Configuration); }