// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(LogLevel.Debug); app.UseDeveloperExceptionPage(); app.UseIdentityServer(); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme, AutomaticAuthenticate = false, AutomaticChallenge = false }); /// /// Setup Custom Data Format /// var schemeName = "oidc"; var dataProtectionProvider = app.ApplicationServices.GetRequiredService <IDataProtectionProvider>(); var distributedCache = app.ApplicationServices.GetRequiredService <IDistributedCache>(); var dataProtector = dataProtectionProvider.CreateProtector( typeof(OpenIdConnectMiddleware).FullName, typeof(string).FullName, schemeName, "v1"); var dataFormat = new CachedPropertiesDataFormat(distributedCache, dataProtector); /// /// Azure AD Configuration /// var clientId = Configuration["oidc:ClientId"]; var tenantId = Configuration["oidc:Tenant"]; var authority = string.Format(Configuration["oidc:AadInstance"], tenantId); app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions { AuthenticationScheme = schemeName, DisplayName = "Office 365", SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme, SignOutScheme = IdentityServerConstants.SignoutScheme, ClientId = clientId, Authority = authority, ResponseType = OpenIdConnectResponseType.IdToken, StateDataFormat = dataFormat }); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }
public static AuthenticationBuilder AddWeChat(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action <WeChatOptions> configureOptions) { builder.Services.TryAddTransient <ISecureDataFormat <AuthenticationProperties> >((provider) => { var dataProtectionProvider = provider.GetRequiredService <IDataProtectionProvider>(); var distributedCache = provider.GetRequiredService <IDistributedCache>(); var dataProtector = dataProtectionProvider.CreateProtector( typeof(WeChatHandler).FullName, typeof(string).FullName, WeChatDefaults.AuthenticationScheme, "v1"); var dataFormat = new CachedPropertiesDataFormat(distributedCache, dataProtector); return(dataFormat); }); return(builder.AddOAuth <WeChatOptions, WeChatHandler>(authenticationScheme, displayName, configureOptions)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(LogLevel.Debug); InitializeDatabase(app); app.UseCors(builder => builder .WithOrigins( "http://localhost:5200", "http://juliofranciscodeiriarte166.org", "http://wordpress.juliofranciscodeiriarte166.org", "https://wordpress.salesianos.cotillo-corp.com") .AllowAnyHeader() .AllowAnyMethod()); app.UseDeveloperExceptionPage(); app.UseIdentity(); app.UseIdentityServer(); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme, AutomaticAuthenticate = false, AutomaticChallenge = false }); /// /// Setup Custom Data Format /// var schemeName = "oidc"; var dataProtectionProvider = app.ApplicationServices.GetRequiredService <IDataProtectionProvider>(); var distributedCache = app.ApplicationServices.GetRequiredService <IDistributedCache>(); var dataProtector = dataProtectionProvider.CreateProtector( typeof(OpenIdConnectMiddleware).FullName, typeof(string).FullName, schemeName, "v1"); var dataFormat = new CachedPropertiesDataFormat(distributedCache, dataProtector); /// /// Azure AD Configuration /// var clientId = Configuration["oidc-salesianos:ClientId"]; var tenantId = Configuration["oidc-salesianos:Tenant"]; var authority = string.Format(Configuration["oidc-salesianos:AadInstance"], tenantId); app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions { AuthenticationScheme = schemeName, DisplayName = "Office 365", SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme, SignOutScheme = IdentityServerConstants.SignoutScheme, ClientId = clientId, Authority = authority, ResponseType = OpenIdConnectResponseType.IdToken, StateDataFormat = dataFormat }); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }