public IdentityCookieOptions() { // Configure all of the cookie middlewares ApplicationCookie = new CookieAuthenticationOptions { AuthenticationScheme = ApplicationCookieAuthenticationScheme, AutomaticAuthentication = true, LoginPath = new PathString("/Account/Login"), Events = new CookieAuthenticationEvents { OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync } }; ExternalCookie = new CookieAuthenticationOptions { AuthenticationScheme = ExternalCookieAuthenticationScheme, CookieName = ExternalCookieAuthenticationScheme, ExpireTimeSpan = TimeSpan.FromMinutes(5) }; TwoFactorRememberMeCookie = new CookieAuthenticationOptions { AuthenticationScheme = TwoFactorRememberMeCookieAuthenticationScheme, CookieName = TwoFactorRememberMeCookieAuthenticationScheme }; TwoFactorUserIdCookie = new CookieAuthenticationOptions { AuthenticationScheme = TwoFactorUserIdCookieAuthenticationScheme, CookieName = TwoFactorUserIdCookieAuthenticationScheme, ExpireTimeSpan = TimeSpan.FromMinutes(5) }; }
public BaseCookieContext( HttpContext context, CookieAuthenticationOptions options) : base(context) { if (options == null) { throw new ArgumentNullException(nameof(options)); } Options = options; }
/// <summary> /// Creates a new instance of the context object. /// </summary> /// <param name="context">The HTTP request context</param> /// <param name="options">The middleware options</param> /// <param name="authenticationScheme">Initializes AuthenticationScheme property</param> /// <param name="principal">Initializes Principal property</param> /// <param name="properties">Initializes Properties property</param> public CookieSignedInContext( HttpContext context, CookieAuthenticationOptions options, string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties) : base(context, options) { AuthenticationScheme = authenticationScheme; Principal = principal; Properties = properties; }
/// <summary> /// Adds the <see cref="CookieAuthenticationMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables cookie authentication capabilities. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> /// <param name="options">A <see cref="JwtBearerOptions"/> that specifies options for the middleware.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IApplicationBuilder UseCookieAuthentication(this IApplicationBuilder app, CookieAuthenticationOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return app.UseMiddleware<CookieAuthenticationMiddleware>(options); }
/// <summary> /// Adds the <see cref="CookieAuthenticationMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables cookie authentication capabilities. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> /// <param name="configureOptions">An action delegate to configure the provided <see cref="CookieAuthenticationOptions"/>.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IApplicationBuilder UseCookieAuthentication(this IApplicationBuilder app, Action<CookieAuthenticationOptions> configureOptions) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var options = new CookieAuthenticationOptions(); if (configureOptions != null) { configureOptions(options); } return app.UseCookieAuthentication(options); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="options"></param> /// <param name="cookieOptions"></param> public CookieSigningOutContext(HttpContext context, CookieAuthenticationOptions options, CookieOptions cookieOptions) : base(context, options) { CookieOptions = cookieOptions; }
public CookieRedirectContext(HttpContext context, CookieAuthenticationOptions options, string redirectUri) : base(context, options) { RedirectUri = redirectUri; }
// Configure is called after ConfigureServices is called. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // Configure the HTTP request pipeline. // Add the following to the request pipeline only in development environment. if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); //app.UseDatabaseErrorPage(); } else { // Add Error handling middleware which catches all application specific errors and // sends the request to the following path or controller action. app.UseExceptionHandler("/Home/Error"); } // Add the platform handler to the request pipeline. app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); // Add static files to the request pipeline. app.UseStaticFiles(); // Add cookie-based authentication to the request pipeline. var ApplicationCookie = new CookieAuthenticationOptions { AuthenticationScheme = "application", CookieName = "application", AutomaticAuthenticate = true, AutomaticChallenge = true, LoginPath = new PathString("/FakeAccount/Index"), Events = new CookieAuthenticationEvents { //OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync } }; app.UseCookieAuthentication(ApplicationCookie); // Add MVC to the request pipeline. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
/// <summary> /// Creates a new instance of the context object. /// </summary> /// <param name="context"></param> /// <param name="ticket">Contains the initial values for identity and extra data</param> /// <param name="options"></param> public CookieValidatePrincipalContext(HttpContext context, AuthenticationTicket ticket, CookieAuthenticationOptions options) : base(context, options) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (ticket == null) { throw new ArgumentNullException(nameof(ticket)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } Principal = ticket.Principal; Properties = ticket.Properties; }
// 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, IOptions<SimpleAuthSettings> authSettingsAccessor ) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseStaticFiles(); // Add cookie-based authentication to the request pipeline SimpleAuthSettings authSettings = authSettingsAccessor.Value; var ApplicationCookie = new CookieAuthenticationOptions { AuthenticationScheme = authSettings.AuthenticationScheme, CookieName = authSettings.AuthenticationScheme, AutomaticAuthenticate = true, AutomaticChallenge = true, LoginPath = new PathString("/Login/Index") }; app.UseCookieAuthentication(ApplicationCookie); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }