-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from EasyOC/ImplicitLogout
add ImplicitLogout module to EasyOC.Users
- Loading branch information
Showing
5 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Modules/EasyOC.Users/Controllers/EocOpenIdAccessController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using OpenIddict.Server.AspNetCore; | ||
using OrchardCore.Modules; | ||
using OrchardCore.OpenId; | ||
using OrchardCore.OpenId.ViewModels; | ||
|
||
namespace EasyOC.Users.Controllers | ||
{ | ||
[Authorize, Feature(OpenIdConstants.Features.Server)] | ||
public class EocOpenIdAccessController : Controller | ||
{ | ||
[AllowAnonymous, HttpGet, HttpPost, IgnoreAntiforgeryToken] | ||
public async Task<IActionResult> Logout() | ||
{ | ||
var response = HttpContext.GetOpenIddictServerResponse(); | ||
if (response != null) | ||
{ | ||
return View("Error", new ErrorViewModel | ||
{ | ||
Error = response.Error, | ||
ErrorDescription = response.ErrorDescription | ||
}); | ||
} | ||
|
||
var request = HttpContext.GetOpenIddictServerRequest(); | ||
if (request == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
// Warning: unlike the main Logout method, this method MUST NOT be decorated with | ||
// [IgnoreAntiforgeryToken] as we must be able to reject end session requests | ||
// sent by a malicious client that could abuse this interactive endpoint to silently | ||
// log the user out without the user explicitly approving the log out operation. | ||
|
||
await HttpContext.SignOutAsync(); | ||
|
||
// If no post_logout_redirect_uri was specified, redirect the user agent | ||
// to the root page, that should correspond to the home page in most cases. | ||
if (string.IsNullOrEmpty(request.PostLogoutRedirectUri)) | ||
{ | ||
return Redirect("~/"); | ||
} | ||
|
||
return SignOut(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters