Browse Source

Update the samples to store the provider name in the authentication cookie

pull/1880/head
Kévin Chalet 2 years ago
parent
commit
8f9c641dd6
  1. 4
      sandbox/OpenIddict.Sandbox.AspNet.Client/Controllers/AuthenticationController.cs
  2. 4
      sandbox/OpenIddict.Sandbox.AspNet.Client/Views/Home/Index.cshtml
  3. 4
      sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AuthenticationController.cs
  4. 7
      sandbox/OpenIddict.Sandbox.AspNetCore.Client/Controllers/AuthenticationController.cs
  5. 3
      sandbox/OpenIddict.Sandbox.AspNetCore.Client/Views/Home/Index.cshtml
  6. 5
      sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/AuthenticationController.cs

4
sandbox/OpenIddict.Sandbox.AspNet.Client/Controllers/AuthenticationController.cs

@ -175,9 +175,9 @@ namespace OpenIddict.Sandbox.AspNet.Client.Controllers
// in the cookie can be filtered out or mapped to different names depending the claim name or its issuer.
var claims = result.Identity.Claims.Where(claim => claim.Type is ClaimTypes.NameIdentifier or ClaimTypes.Name
//
// Preserve the registration identifier to be able to resolve it later.
// Preserve the registration details to be able to resolve them later.
//
or Claims.Private.RegistrationId
or Claims.Private.RegistrationId or Claims.Private.ProviderName
//
// The ASP.NET 4.x antiforgery module requires preserving the "identityprovider" claim.
//

4
sandbox/OpenIddict.Sandbox.AspNet.Client/Views/Home/Index.cshtml

@ -2,6 +2,7 @@
@using Microsoft.Owin
@using Microsoft.Owin.Security
@using Microsoft.Owin.Security.Cookies
@using OpenIddict.Abstractions
@using OpenIddict.Client.Owin
@model string
@ -22,8 +23,7 @@
<h3>Payload returned by the controller: @Model</h3>
}
if (User is ClaimsPrincipal principal &&
principal.FindFirst(ClaimTypes.NameIdentifier)?.Issuer is "https://localhost:44349/")
if (User is ClaimsPrincipal principal && principal.FindFirst(OpenIddictConstants.Claims.Private.ProviderName)?.Value is "Local")
{
<form action="/message" method="post">
@Html.AntiForgeryToken()

4
sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AuthenticationController.cs

@ -62,9 +62,9 @@ namespace OpenIddict.Sandbox.AspNet.Server.Controllers
// in the cookie can be filtered out or mapped to different names depending the claim name or its issuer.
var claims = result.Identity.Claims.Where(claim => claim.Type is ClaimTypes.NameIdentifier or ClaimTypes.Name
//
// Preserve the registration identifier to be able to resolve it later.
// Preserve the registration details to be able to resolve them later.
//
or Claims.Private.RegistrationId
or Claims.Private.RegistrationId or Claims.Private.ProviderName
//
// The ASP.NET 4.x antiforgery module requires preserving the "identityprovider" claim.
//

7
sandbox/OpenIddict.Sandbox.AspNetCore.Client/Controllers/AuthenticationController.cs

@ -172,9 +172,10 @@ public class AuthenticationController : Controller
identity.SetClaim(ClaimTypes.Email, result.Principal.GetClaim(ClaimTypes.Email))
.SetClaim(ClaimTypes.Name, result.Principal.GetClaim(ClaimTypes.Name))
.SetClaim(ClaimTypes.NameIdentifier, result.Principal.GetClaim(ClaimTypes.NameIdentifier));
// Preserve the registration identifier to be able to resolve it later.
identity.SetClaim(Claims.Private.RegistrationId, result.Principal.GetClaim(Claims.Private.RegistrationId));
// Preserve the registration details to be able to resolve them later.
identity.SetClaim(Claims.Private.RegistrationId, result.Principal.GetClaim(Claims.Private.RegistrationId))
.SetClaim(Claims.Private.ProviderName, result.Principal.GetClaim(Claims.Private.ProviderName));
// Build the authentication properties based on the properties that were added when the challenge was triggered.
var properties = new AuthenticationProperties(result.Properties.Items)

3
sandbox/OpenIddict.Sandbox.AspNetCore.Client/Views/Home/Index.cshtml

@ -1,6 +1,7 @@
@using System.Security.Claims
@using Microsoft.AspNetCore.Authentication;
@using OpenIddict.Client.AspNetCore;
@using static OpenIddict.Abstractions.OpenIddictConstants;
@model string
<div class="jumbotron">
@ -20,7 +21,7 @@
<h3>Payload returned by the controller: @Model</h3>
}
if (User.FindFirst(ClaimTypes.NameIdentifier)?.Issuer is "https://localhost:44395/")
if (User.FindFirst(Claims.Private.ProviderName)?.Value is "Local")
{
<form asp-action="GetMessage" asp-controller="Home" method="post">
<button class="btn btn-lg btn-warning" type="submit">Query the resource controller</button>

5
sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/AuthenticationController.cs

@ -60,8 +60,9 @@ public class AuthenticationController : Controller
.SetClaim(ClaimTypes.Name, result.Principal.GetClaim(ClaimTypes.Name))
.SetClaim(ClaimTypes.NameIdentifier, result.Principal.GetClaim(ClaimTypes.NameIdentifier));
// Preserve the registration identifier to be able to resolve it later.
identity.SetClaim(Claims.Private.RegistrationId, result.Principal.GetClaim(Claims.Private.RegistrationId));
// Preserve the registration details to be able to resolve them later.
identity.SetClaim(Claims.Private.RegistrationId, result.Principal.GetClaim(Claims.Private.RegistrationId))
.SetClaim(Claims.Private.ProviderName, result.Principal.GetClaim(Claims.Private.ProviderName));
// Build the authentication properties based on the properties that were added when the challenge was triggered.
var properties = new AuthenticationProperties(result.Properties.Items)

Loading…
Cancel
Save