public void ConfigureServices(IServiceCollection services) { services .AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryApiResources(IdentityConfig.GetApiResources()) .AddInMemoryClients(IdentityConfig.GetClients()) .AddTestUsers(IdentityConfig.GetUsers()); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddTemporarySigningCredential() .AddTestUsers(IdentityConfig.GetTestUsers()) .AddInMemoryApiResources(IdentityConfig.GetApiResources()) .AddInMemoryIdentityResources(IdentityConfig.GetIdentityResources()) .AddInMemoryClients(IdentityConfig.GetClients()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IConfiguration>(Configuration); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) .AddAzureAd(Configuration.GetSection("IdentityProvider:AzureAd").Get <AzureAdConfig>()) .AddAzureAdB2C(Configuration.GetSection("IdentityProvider:AzureAdB2C").Get <AzureAdB2CConfig>()) .AddCookie(options => { options.Events.OnRedirectToLogin = context => { context.Response.Headers["Location"] = context.RedirectUri; context.Response.StatusCode = 401; return(Task.CompletedTask); }; }); // Identity Server services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryPersistedGrants() .AddInMemoryIdentityResources(IdentityConfig.GetIdentityResources()) .AddInMemoryApiResources(IdentityConfig.GetApiResources(Configuration)) .AddInMemoryClients(IdentityConfig.GetClients(Configuration)) .AddProfileService <IdentityWithAdditionalClaimsProfileService>(); services.AddDistributedMemoryCache(); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromHours(1); options.Cookie.HttpOnly = true; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddSessionStateTempDataProvider();; }
public void ConfigureServices(IServiceCollection services) { services.AddMultiTenancy <TenantResolutionFromTokenValidationLibrary>(); services.AddEarlyLogging(out var earlyLogger); earlyLogger.LogInformation("starting to configure services..."); services.AddCors(options => options.AddPolicy("mycustomcorspolicy", b => b.WithOrigins("http://meinetollewebsite.de").AllowAnyMethod().AllowAnyHeader())); services.AddMvc(); services.AddSingleton <IConfigureOptions <CookieAuthenticationOptions>, ConfigureCookieOptions>(); services.AddIdentityServer() .AddSigningCredentialFromKeyVault(config, earlyLogger) .AddInMemoryIdentityResources(IdentityConfig.GetIdentityResources()) .AddInMemoryApiResources(IdentityConfig.GetApis()) .AddInMemoryApiScopes(IdentityConfig.GetScopes()) .AddInMemoryClients(IdentityConfig.GetClients()) .AddTestUsers(IdentityConfig.GetTestUsers()) ; services.AddScoped <DisposeTest>(); services.AddAuthentication(); services.AddAuthorization(o => { o.AddPolicy("default", b => { b.RequireAuthenticatedUser(); b.RequireClaim(JwtClaimTypes.Subject);//windows authenticated but no authenticated cookie (logged out) shouldbe treated as unauthenticated. }); }); services.AddTransient <RequestFromOnPremise>(); services.AddTransientDecorator <ICorsPolicyProvider, CorsPolicyProvider>(); services.AddTransientDecorator <IAuthorizeRequestValidator, ExtendedAuthorizeRequestValidator>(); services.AddSingleton <IResolvedTenant>(new ResolvedTenant("default")); earlyLogger.LogInformation("done configuring general services :)"); }