Skip to content

Commit

Permalink
Added logOut capability and included it in the sample
Browse files Browse the repository at this point in the history
  • Loading branch information
SharePointRadi committed Mar 13, 2016
1 parent cb3edc4 commit 17ffb6d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<li><a asp-controller="Home" asp-action="Index">Home</a></li>
<li><a asp-controller="Home" asp-action="About">Secured Page</a></li>
<li><a asp-controller="Home" asp-action="Contact">Unsecured Page</a></li>
<li><a asp-controller="WindowsAuthentication" asp-route-returnUrl="/Home" asp-action="LogOut">Log Out</a></li>
<li style="color:white"><a asp-controller="Home" asp-action="Index">Hello @User.Identity.Name !</a></li>
<li style="color:white"><a asp-controller="Home" asp-action="Index">Authenticated: @User.Identity.IsAuthenticated </a></li>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,11 @@ protected override Task<bool> HandleForbiddenAsync(ChallengeContext context)
{
return base.HandleForbiddenAsync(context);
}

protected override async Task HandleSignOutAsync(SignOutContext context)
{
await Context.Authentication.SignOutAsync(Options.Cookies.ApplicationCookie.AuthenticationScheme);
await base.HandleSignOutAsync(context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class WindowsAuthenticationController : Controller
{
[AllowAnonymous]
[HttpGet]
public async Task<IActionResult> Ntlm(string returnUrl)
public async Task<IActionResult> Ntlm(string returnUrl = null)
{
if (this.User.Identity.IsAuthenticated == false)
{
Expand All @@ -27,10 +27,21 @@ public async Task<IActionResult> Ntlm(string returnUrl)
else
{
if (string.IsNullOrWhiteSpace(returnUrl))
return Redirect("/");
return new HttpOkResult();
else
return Redirect(returnUrl);
}
}

[AllowAnonymous]
public async Task<IActionResult> LogOut(string returnUrl = null)
{
var context = this.Request.HttpContext;
await context.Authentication.SignOutAsync(ActiveDirectoryOptions.DefaultAuthenticationScheme);
if (string.IsNullOrWhiteSpace(returnUrl))
return new HttpOkResult();
else
return Redirect(returnUrl);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.6-*",
"version": "1.0.7-*",
"description": "Authentication middleware for Active Directory with WIA, Ntlm and Kerberos support.",
"authors": [ "Radi Atanassov" ],
"tags": [ "authentication", "aspnet", "identity", "activedirectory" ],
Expand Down

0 comments on commit 17ffb6d

Please sign in to comment.