public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IUserClaimsExtender userClaimsExtender) { JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = "Cookies" }); app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions { AuthenticationScheme = "oidc", SignInScheme = "Cookies", Authority = "http://localhost:5000", RequireHttpsMetadata = false, ClientId = "mvc", ClientSecret = "secret", ResponseType = "code id_token", Scope = { "api1", "offline_access" }, GetClaimsFromUserInfoEndpoint = true, SaveTokens = true, Events = new OpenIdConnectEvents() { OnTicketReceived = (context) => { context.Principal = userClaimsExtender.TransformClaims(context.Ticket.Principal); return(Task.CompletedTask); } } }); //app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IUserClaimsExtender userClaimsExtender) { JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = "Cookies" }); var openIdConnectOptions = Configuration.GetSection("Authentication:OpenIdConnectOptions").Get <OpenIdConnectOptions>(); if (openIdConnectOptions == null || string.IsNullOrEmpty(openIdConnectOptions.Authority)) { throw new Exception("Missing open id connect options from config file"); } openIdConnectOptions.Events = new OpenIdConnectEvents() { OnTicketReceived = (context) => { context.Principal = userClaimsExtender.TransformClaims(context.Ticket.Principal); return(Task.CompletedTask); } }; app.UseOpenIdConnectAuthentication(openIdConnectOptions); //app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }