Permalink
Browse files

Added ability to log out

  • Loading branch information...
robdmoore committed Jun 28, 2014
1 parent 992acae commit 636205bfd34ddb772aca801b776393a69974e3fa
@@ -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>
@@ -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>
@@ -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();
}
}
}
@@ -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>
@@ -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>

0 comments on commit 636205b

Please sign in to comment.