Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var provider = new CookieAuthenticationProvider();
- provider.OnApplyRedirect = ctx =>
- {
- if (ctx.Request.Query["s"] != null)
- {
- var ticket = LoadTicket(ctx.Request.Query["s"]);
- var uri = RemoveQueryStringByKey(ctx.Request.Uri.ToString(), "s");
- ticket.Properties.IsPersistent = true;
- ctx.OwinContext.Authentication.SignIn(ticket.Properties, ticket.Identity);
- ctx.Response.Redirect(uri);
- return;
- }
- }
- public class SingleSignOnAuthenticationHandler : AuthenticationHandler<AuthenticationOptions>
- {
- protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
- {
- var sessionIdentifier = Request.Query["s"];
- if (sessionIdentifier == null)
- return Task.FromResult<AuthenticationTicket>(null);
- var ticket = LoadTicket(sessionIdentifier);
- if (ticket == null)
- return Task.FromResult<AuthenticationTicket>(null);
- Context.Authentication.SignIn(ticket.Properties, ticket.Identity);
- return Task.FromResult(new AuthenticationTicket(ticket.Identity, ticket.Properties));
- }
- }
- app.UseCookieAuthentication(new CookieAuthenticationOptions
- {
- AuthenticationType = "ApplicationCookie", // <--- THIS STRING
- LoginPath = new PathString(VirtualPathUtility.ToAbsolute("~/Account/Login")),
- Provider = provider
- });
- public class SingleSignOnAuthenticationHandler : AuthenticationHandler<AuthenticationOptions>
- {
- protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
- {
- var sessionIdentifier = Request.Query["s"];
- if (sessionIdentifier == null)
- return Task.FromResult<AuthenticationTicket>(null);
- var ticket = LoadTicket(sessionIdentifier);
- if (ticket == null)
- return Task.FromResult<AuthenticationTicket>(null);
- ticket.Properties.IsPersistent = true;
- // ** LOOK HERE **
- //new identity, but with the correct authentication type
- var identity = new ClaimsIdentity(ticket.Identity.Claims, "ApplicationCookie", ClaimTypes.Name, ClaimTypes.Role);
- Context.Authentication.SignIn(ticket.Properties, identity);
- return Task.FromResult(new AuthenticationTicket(identity, ticket.Properties));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement