Skip to content

Instantly share code, notes, and snippets.

@jellebens
Last active December 22, 2015 10:59
Show Gist options
  • Save jellebens/6462446 to your computer and use it in GitHub Desktop.
Save jellebens/6462446 to your computer and use it in GitHub Desktop.
Windows Identity framework SignOut
public class AuthenticationController : Controller
{
ILogger _Logger = NullLogger.Instance;
public AuthenticationController(ILoggerFactory loggerfactory) {
loggerfactory.Create(Loggers.Security);
}
[AllowAnonymous]
public ActionResult Index()
{
return View();
}
//To trigger redirect to login
[Authorize]
public ActionResult SignIn()
{
return RedirectToAction("Index", "Home");
}
public void SignOut()
{
WsFederationConfiguration fc = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration;
string request = System.Web.HttpContext.Current.Request.Url.ToString();
string wreply = request.Substring(0, request.Length - 7);
SignOutRequestMessage soMessage = new SignOutRequestMessage(new Uri(fc.Issuer), wreply);
soMessage.SetParameter("wtrealm", fc.Realm);
SessionAuthenticationModule sam = FederatedAuthentication.SessionAuthenticationModule;
if (sam != null) {
_Logger.Debug("Calling SessionAuthenticationModule signout");
sam.SignOut();
sam.DeleteSessionTokenCookie();
}
WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule;
if (fam != null) {
_Logger.Debug("Calling WSFederationAuthenticationModule.Signout()");
fam.SignOut();
}
_Logger.InfoFormat("Signed out. Redirecting...");
Response.Redirect(soMessage.WriteQueryString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment