From 17ffb6d9b21afe4eb31df3c9df734e8b1d277ead Mon Sep 17 00:00:00 2001 From: "Radi A." Date: Sun, 13 Mar 2016 14:56:15 +0200 Subject: [PATCH] Added logOut capability and included it in the sample --- .../Views/Shared/_Layout.cshtml | 1 + .../NtlmAuthenticationHandler.cs | 6 ++++++ .../WindowsAuthenticationController.cs | 15 +++++++++++++-- .../project.json | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/samples/Sample-AspNet5.Mvc6.Ntlm/Views/Shared/_Layout.cshtml b/samples/Sample-AspNet5.Mvc6.Ntlm/Views/Shared/_Layout.cshtml index a516c52..9bda699 100644 --- a/samples/Sample-AspNet5.Mvc6.Ntlm/Views/Shared/_Layout.cshtml +++ b/samples/Sample-AspNet5.Mvc6.Ntlm/Views/Shared/_Layout.cshtml @@ -33,6 +33,7 @@
  • Home
  • Secured Page
  • Unsecured Page
  • +
  • Log Out
  • Hello @User.Identity.Name !
  • Authenticated: @User.Identity.IsAuthenticated
  • diff --git a/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/NtlmAuthenticationHandler.cs b/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/NtlmAuthenticationHandler.cs index 7cec0d9..24ad279 100644 --- a/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/NtlmAuthenticationHandler.cs +++ b/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/NtlmAuthenticationHandler.cs @@ -194,5 +194,11 @@ protected override Task 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); + } } } diff --git a/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/WindowsAuthenticationController.cs b/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/WindowsAuthenticationController.cs index cfa193b..be3cd97 100644 --- a/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/WindowsAuthenticationController.cs +++ b/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/WindowsAuthenticationController.cs @@ -9,7 +9,7 @@ public class WindowsAuthenticationController : Controller { [AllowAnonymous] [HttpGet] - public async Task Ntlm(string returnUrl) + public async Task Ntlm(string returnUrl = null) { if (this.User.Identity.IsAuthenticated == false) { @@ -27,10 +27,21 @@ public async Task Ntlm(string returnUrl) else { if (string.IsNullOrWhiteSpace(returnUrl)) - return Redirect("/"); + return new HttpOkResult(); else return Redirect(returnUrl); } } + + [AllowAnonymous] + public async Task 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); + } } } diff --git a/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/project.json b/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/project.json index f6f84b2..ea5ea81 100644 --- a/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/project.json +++ b/src/Microsoft.AspNetCore.Authentication.ActiveDirectory/project.json @@ -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" ],