Skip to content

Commit

Permalink
Added ability to log out
Browse files Browse the repository at this point in the history
  • Loading branch information
robdmoore committed Jun 29, 2014
1 parent 992acae commit 636205b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions AzureAdMvcExample/AzureAdMvcExample.csproj
Expand Up @@ -141,6 +141,7 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\Startup.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\LogoutController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
Expand Down Expand Up @@ -176,6 +177,7 @@
<Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\Home\Index.cshtml" />
<Content Include="Scripts\jquery-1.10.2.min.map" />
<Content Include="Views\Logout\Callback.cshtml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions 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();
}
}
}
7 changes: 7 additions & 0 deletions AzureAdMvcExample/Views/Logout/Callback.cshtml
@@ -0,0 +1,7 @@
@{
ViewBag.Title = "Logged out";
}

<h1>Logged out</h1>

<p>You have successfully logged out of this site. @Html.ActionLink("Log back in", "Index", "Home").</p>
4 changes: 4 additions & 0 deletions AzureAdMvcExample/Views/Shared/_Layout.cshtml
Expand Up @@ -21,6 +21,10 @@
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
@if (User.Identity.IsAuthenticated)
{
<li>@Html.ActionLink("Logout", "Index", "Logout")</li>
}
</ul>
</div>
</div>
Expand Down

0 comments on commit 636205b

Please sign in to comment.