-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#44 complete
- Loading branch information
Showing
13 changed files
with
116 additions
and
25 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
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
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
25 changes: 25 additions & 0 deletions
25
...le.Template/content/Calabonga.Microservice.IdentityModule.Web/Pages/Connect/Logout.cshtml
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,25 @@ | ||
@page | ||
@using Microsoft.AspNetCore.Mvc.TagHelpers | ||
@using Microsoft.Extensions.Primitives | ||
@model Calabonga.Microservice.IdentityModule.Web.Pages.Connect.LogoutModel | ||
@{ | ||
var items = HttpContext.Request.HasFormContentType | ||
? (IEnumerable<KeyValuePair<string, StringValues>>)HttpContext.Request.Form | ||
: HttpContext.Request.Query; | ||
} | ||
<div class="col-md-4 offset-4 text-center"> | ||
|
||
<p class="lead">Are you sure you want to exit?</p> | ||
|
||
<form method="post"> | ||
|
||
@foreach (var parameter in items) | ||
{ | ||
<input type="hidden" name="@parameter.Key" value="@parameter.Value" /> | ||
} | ||
|
||
<input class="btn btn-lg btn-success" name="Confirm" type="submit" value="Yes" /> | ||
|
||
</form> | ||
|
||
</div> |
50 changes: 50 additions & 0 deletions
50
...Template/content/Calabonga.Microservice.IdentityModule.Web/Pages/Connect/Logout.cshtml.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,50 @@ | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using OpenIddict.Client.AspNetCore; | ||
using OpenIddict.Server.AspNetCore; | ||
|
||
namespace Calabonga.Microservice.IdentityModule.Web.Pages.Connect; | ||
|
||
public class LogoutModel : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
} | ||
|
||
public async Task<IActionResult> OnPost(string returnUrl) | ||
{ | ||
// Retrieve the identity stored in the local authentication cookie. If it's not available, | ||
// this indicate that the user is already logged out locally (or has not logged in yet). | ||
// | ||
// For scenarios where the default authentication handler configured in the ASP.NET Core | ||
// authentication options shouldn't be used, a specific scheme can be specified here. | ||
var result = await HttpContext.AuthenticateAsync(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme); | ||
if (result is not { Succeeded: true }) | ||
{ | ||
// Only allow local return URLs to prevent open redirect attacks. | ||
return Redirect(Url.IsLocalUrl(returnUrl) ? returnUrl : "/"); | ||
} | ||
|
||
// Remove the local authentication cookie before triggering a redirection to the remote server. | ||
// | ||
// For scenarios where the default sign-out handler configured in the ASP.NET Core | ||
// authentication options shouldn't be used, a specific scheme can be specified here. | ||
await HttpContext.SignOutAsync(); | ||
|
||
var properties = new AuthenticationProperties(new Dictionary<string, string> | ||
{ | ||
// While not required, the specification encourages sending an id_token_hint | ||
// parameter containing an identity token returned by the server for this user. | ||
[OpenIddictClientAspNetCoreConstants.Properties.IdentityTokenHint] = result.Properties.GetTokenValue(OpenIddictClientAspNetCoreConstants.Tokens.BackchannelIdentityToken) | ||
}) | ||
{ | ||
// Only allow local return URLs to prevent open redirect attacks. | ||
RedirectUri = Url.IsLocalUrl(returnUrl) ? returnUrl : "/" | ||
}; | ||
|
||
// Ask the OpenIddict client middleware to redirect the user agent to the identity provider. | ||
return SignOut(properties, 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
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