Skip to content

Instantly share code, notes, and snippets.

@shawnweisfeld
Created July 20, 2016 20:53
Show Gist options
  • Save shawnweisfeld/597a01d3860195c2d0853fee34b41f22 to your computer and use it in GitHub Desktop.
Save shawnweisfeld/597a01d3860195c2d0853fee34b41f22 to your computer and use it in GitHub Desktop.
public void SignIn(string authType)
{
// Send an OpenID Connect sign-in request.
if (!Request.IsAuthenticated)
{
string callbackUrl = Url.Action("SignInCallback", "Account", routeValues: new { authType = authType }, protocol: Request.Url.Scheme);
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = callbackUrl },
authType);
}
}
public ActionResult SignInCallback(string authType)
{
//NOTE: I am throwing the value into session state
//depending on your application you will probably want to store this in something more durable (i.e. Redis Cache)
Session["AuthType"] = authType;
return RedirectToAction("Index", "Home");
}
public void SignOut()
{
string callbackUrl = Url.Action("SignOutCallback", "Account", routeValues: null, protocol: Request.Url.Scheme);
HttpContext.GetOwinContext().Authentication.SignOut(
new AuthenticationProperties { RedirectUri = callbackUrl },
Session["AuthType"].ToString(), CookieAuthenticationDefaults.AuthenticationType);
}
public ActionResult SignOutCallback()
{
return RedirectToAction("Index", "Home");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment