Created
March 28, 2017 09:08
-
-
Save vadymberkut/00a4e635f135528d10c08f03e367e9c9 to your computer and use it in GitHub Desktop.
AspNetCore Auth config
This file contains 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
COOKIE AUTH | |
//Auth | |
app.UseCookieAuthentication(new CookieAuthenticationOptions | |
{ | |
AutomaticAuthenticate = true, | |
AutomaticChallenge = true, | |
LoginPath = new PathString("/Account/Login"), | |
Events = new CookieAuthenticationEvents() | |
{ | |
OnRedirectToLogin = ctx => | |
{ | |
if (ctx.Request.Path.StartsWithSegments("/api") && | |
ctx.Response.StatusCode == (int)HttpStatusCode.OK) | |
{ | |
ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized; | |
} | |
else if (ctx.Request.Path.StartsWithSegments("/api") && | |
ctx.Response.StatusCode == (int)HttpStatusCode.Unauthorized) | |
{ | |
ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized; | |
} | |
else | |
{ | |
//Redirect to login | |
//ctx.Response.Redirect(ctx.RedirectUri); | |
//Do not redirect to login - ALWAYS retutn 401 | |
ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized; | |
} | |
return Task.FromResult(0); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment