diff --git a/AzureAdMvcExample/AzureAdMvcExample.csproj b/AzureAdMvcExample/AzureAdMvcExample.csproj index d884311..fad3fbc 100644 --- a/AzureAdMvcExample/AzureAdMvcExample.csproj +++ b/AzureAdMvcExample/AzureAdMvcExample.csproj @@ -141,6 +141,7 @@ + Global.asax @@ -176,6 +177,7 @@ + diff --git a/AzureAdMvcExample/Controllers/LogoutController.cs b/AzureAdMvcExample/Controllers/LogoutController.cs new file mode 100644 index 0000000..4e50efa --- /dev/null +++ b/AzureAdMvcExample/Controllers/LogoutController.cs @@ -0,0 +1,30 @@ +using System; +using System.IdentityModel.Services; +using System.Web.Mvc; + +namespace AzureAdMvcExample.Controllers +{ + public class LogoutController : Controller + { + public ActionResult Index() + { + var config = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration; + + var callbackUrl = Url.Action("Callback", "Logout", null, Request.Url.Scheme); + var signoutMessage = new SignOutRequestMessage(new Uri(config.Issuer), callbackUrl); + signoutMessage.SetParameter("wtrealm", config.Realm); + FederatedAuthentication.SessionAuthenticationModule.SignOut(); + + return new RedirectResult(signoutMessage.WriteQueryString()); + } + + [AllowAnonymous] + public ActionResult Callback() + { + if (Request.IsAuthenticated) + return RedirectToAction("Index", "Home"); + + return View(); + } + } +} \ No newline at end of file diff --git a/AzureAdMvcExample/Views/Logout/Callback.cshtml b/AzureAdMvcExample/Views/Logout/Callback.cshtml new file mode 100644 index 0000000..85da9a2 --- /dev/null +++ b/AzureAdMvcExample/Views/Logout/Callback.cshtml @@ -0,0 +1,7 @@ +@{ + ViewBag.Title = "Logged out"; +} + +

Logged out

+ +

You have successfully logged out of this site. @Html.ActionLink("Log back in", "Index", "Home").

diff --git a/AzureAdMvcExample/Views/Shared/_Layout.cshtml b/AzureAdMvcExample/Views/Shared/_Layout.cshtml index 9e7f719..e1251db 100644 --- a/AzureAdMvcExample/Views/Shared/_Layout.cshtml +++ b/AzureAdMvcExample/Views/Shared/_Layout.cshtml @@ -21,6 +21,10 @@