public static IAppBuilder UseFormsAuthentication(this IAppBuilder app, Action <FormsAuthenticationOptions> configuration) { var options = new FormsAuthenticationOptions(); configuration(options); return(UseFormsAuthentication(app, options)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var section = Configuration.GetSection("FormsAuthentication"); var faOptions = new FormsAuthenticationOptions() { DecryptionKey = section.GetValue <string>("DecryptionKey"), ValidationKey = section.GetValue <string>("ValidationKey"), EncryptionMethod = section.GetValue <EncryptionMethod>("EncryptionMethod"), ValidationMethod = section.GetValue <ValidationMethod>("ValidationMethod"), }; services.AddMvc(option => option.EnableEndpointRouting = false); services .AddAuthentication(options => { options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) .AddCookie(options => { options.Cookie.Name = section.GetValue <string>("CookieName"); options.AccessDeniedPath = "/Login/"; options.LoginPath = "/Login/"; options.ReturnUrlParameter = "returnurl"; options.TicketDataFormat = new FormsAuthenticationDataFormat <AuthenticationTicket>( faOptions, FormsAuthHelper.ConvertCookieToTicket, FormsAuthHelper.ConvertTicketToCookie ); options.SlidingExpiration = false; options.Events.OnRedirectToAccessDenied = context => FormsAuthHelper.RedirectToAccessDenied(context, section.GetValue <string>("BaseAuthUrl")); options.Events.OnRedirectToLogin = context => FormsAuthHelper.RedirectToLogin(context, section.GetValue <string>("BaseAuthUrl")); }); services.AddMvc(); }
public static IAppBuilder UseFormsAuthentication(this IAppBuilder app, FormsAuthenticationOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var cookieOptions = new CookieAuthenticationOptions { AuthenticationMode = AuthenticationMode.Active, AuthenticationType = FormsAuthenticationConstants.AuthenticationType, CookieDomain = FormsAuthentication.CookieDomain, CookieHttpOnly = true, CookieName = FormsAuthentication.FormsCookieName, CookiePath = FormsAuthentication.FormsCookiePath, CookieSecure = CookieSecureOption.SameAsRequest, ExpireTimeSpan = FormsAuthentication.Timeout, LoginPath = new PathString(FormsAuthentication.LoginUrl), ReturnUrlParameter = "ReturnUrl", SlidingExpiration = FormsAuthentication.SlidingExpiration }; cookieOptions.TicketDataFormat = new FormsAuthenticationTicketFormat(cookieOptions); if (options != null) { cookieOptions.CookieManager = options.CookieManager; cookieOptions.CookieSecure = options.CookieSecure; cookieOptions.Description = options.Description; cookieOptions.LogoutPath = options.LogoutPath; cookieOptions.Provider = options.Provider; cookieOptions.ReturnUrlParameter = options.ReturnUrlParameter; //cookieOptions.SessionStore = options.SessionStore; cookieOptions.SystemClock = options.SystemClock; } return(app.UseCookieAuthentication(cookieOptions)); }
// the only required parameter is 'machineKeySection'; other parameters are just used for unit testing internal MasterKeyProvider(FormsAuthenticationOptions machineKeySection) { _options = machineKeySection; }
public static IAppBuilder UseFormsAuthentication(this IAppBuilder app, FormsAuthenticationOptions options) { app.Use(typeof(FormsAuthenticationMiddleware), app, options); app.UseStageMarkerAuthenticate(); return(app); }
public CryptoAlgorithmFactory(FormsAuthenticationOptions options) { _options = options; }
public static AspNetCryptoServiceProvider GetCryptoServiceProvider(FormsAuthenticationOptions options) { return(new AspNetCryptoServiceProvider( new CryptoAlgorithmFactory(options), new MasterKeyProvider(options))); }