Last active
November 16, 2016 19:44
-
-
Save Legogris/ba36ea8ecd67afc548103a18cb1411a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void UseCactiCookieAuthentication(this IApplicationBuilder app, IHostingEnvironment environment) | |
| { | |
| var cookieName = "AuthCookie"; | |
| app.Use(next => context => | |
| { | |
| context.Response.OnStarting(state => | |
| { | |
| if(context.Items.ContainsKey("dontRenewAuthCookie")) | |
| { | |
| var response = (HttpResponse) state; | |
| // Omit Set-Cookie header with the offending cookie name | |
| var cookieHeader = response.Headers[HeaderNames.SetCookie].Where(s => !s.Contains(cookieName)).Aggregate(new StringValues(), (current, s) => StringValues.Concat(current, s)); | |
| response.Headers[HeaderNames.SetCookie] = cookieHeader; | |
| } | |
| return Task.CompletedTask; | |
| }, context.Response); | |
| return next(context); | |
| }); | |
| app.UseCookieAuthentication(new CookieAuthenticationOptions | |
| { | |
| AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme, | |
| CookiePath = "/", | |
| CookieName = cookieName, | |
| AutomaticAuthenticate = true, | |
| ExpireTimeSpan = TimeSpan.FromMinutes(20), | |
| AutomaticChallenge = true, | |
| SlidingExpiration = true, | |
| CookieSecure = CookieSecurePolicy.Always | |
| // Additional auth options... | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment