Browse Source
Add `sid` claim to openiddict's `principal`.
pull/23196/head
maliming
1 year ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
3 changed files with
46 additions and
4 deletions
-
modules/openiddict/app/OpenIddict.Demo.Client.Mvc/Pages/Index.cshtml
-
modules/openiddict/app/OpenIddict.Demo.Server/Pages/Index.cshtml
-
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AuthorizeController.cs
|
|
|
@ -15,17 +15,38 @@ |
|
|
|
@if (HttpContext.User.Identity != null && HttpContext.User.Identity.IsAuthenticated) |
|
|
|
{ |
|
|
|
<ul class="list-group mt-3 text-start"> |
|
|
|
<p>Current User</p> |
|
|
|
@foreach (var claim in HttpContext.User.Claims) |
|
|
|
{ |
|
|
|
<li class="list-group-item">@claim.Type : @claim.Value</li> |
|
|
|
} |
|
|
|
</ul> |
|
|
|
|
|
|
|
<ul class="list-group mt-3 text-start"> |
|
|
|
<p>oidc</p> |
|
|
|
@{ |
|
|
|
var oidc = await HttpContext.AuthenticateAsync("oidc"); |
|
|
|
if (oidc.Principal != null) |
|
|
|
{ |
|
|
|
foreach (var claim in oidc.Principal.Claims) |
|
|
|
{ |
|
|
|
<li class="list-group-item">@claim.Type : @claim.Value</li> |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</ul> |
|
|
|
|
|
|
|
|
|
|
|
<p>HttpContext.GetTokenAsync("access_token") |
|
|
|
<br/> |
|
|
|
@await HttpContext.GetTokenAsync("access_token") |
|
|
|
</p> |
|
|
|
|
|
|
|
<p>HttpContext.GetTokenAsync("id_token") |
|
|
|
<br/> |
|
|
|
@await HttpContext.GetTokenAsync("id_token") |
|
|
|
</p> |
|
|
|
|
|
|
|
var client = new HttpClient(); |
|
|
|
var request = new HttpRequestMessage(HttpMethod.Get, "https://localhost:44303/api/claims"); |
|
|
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await HttpContext.GetTokenAsync("access_token")); |
|
|
|
|
|
|
|
@ -4,7 +4,13 @@ |
|
|
|
ViewData["Title"] = "Home page"; |
|
|
|
} |
|
|
|
|
|
|
|
<div class="text-center"> |
|
|
|
<h1 class="display-4">Welcome</h1> |
|
|
|
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> |
|
|
|
</div> |
|
|
|
@if (HttpContext.User.Identity != null && HttpContext.User.Identity.IsAuthenticated) |
|
|
|
{ |
|
|
|
<ul class="list-group mt-3 text-start"> |
|
|
|
<p>Current User</p> |
|
|
|
@foreach (var claim in HttpContext.User.Claims) |
|
|
|
{ |
|
|
|
<li class="list-group-item">@claim.Type : @claim.Value</li> |
|
|
|
} |
|
|
|
</ul> |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IdentityModel.Tokens.Jwt; |
|
|
|
using System.Linq; |
|
|
|
using System.Security.Claims; |
|
|
|
using System.Text.Encodings.Web; |
|
|
|
@ -148,6 +149,13 @@ public class AuthorizeController : AbpOpenIdDictControllerBase |
|
|
|
case OpenIddictConstants.ConsentTypes.Explicit when authorizations.Any() && !request.HasPromptValue(OpenIddictConstants.PromptValues.Consent): |
|
|
|
var principal = await SignInManager.CreateUserPrincipalAsync(user); |
|
|
|
|
|
|
|
var sid = dynamicPrincipal.FindFirst(JwtRegisteredClaimNames.Sid); |
|
|
|
if (sid != null) |
|
|
|
{ |
|
|
|
principal.RemoveClaims(JwtRegisteredClaimNames.Sid); |
|
|
|
principal.AddClaim(JwtRegisteredClaimNames.Sid, sid.Value); |
|
|
|
} |
|
|
|
|
|
|
|
if (result.Properties != null && result.Properties.IsPersistent) |
|
|
|
{ |
|
|
|
var claim = new Claim(AbpClaimTypes.RememberMe, true.ToString()).SetDestinations(OpenIddictConstants.Destinations.AccessToken); |
|
|
|
@ -247,6 +255,13 @@ public class AuthorizeController : AbpOpenIdDictControllerBase |
|
|
|
|
|
|
|
var principal = await SignInManager.CreateUserPrincipalAsync(user); |
|
|
|
|
|
|
|
var sid = User.FindFirst(JwtRegisteredClaimNames.Sid); |
|
|
|
if (sid != null) |
|
|
|
{ |
|
|
|
principal.RemoveClaims(JwtRegisteredClaimNames.Sid); |
|
|
|
principal.AddClaim(JwtRegisteredClaimNames.Sid, sid.Value); |
|
|
|
} |
|
|
|
|
|
|
|
var result = await HttpContext.AuthenticateAsync(IdentityConstants.ApplicationScheme); |
|
|
|
if (result.Succeeded && result.Properties != null && result.Properties.IsPersistent) |
|
|
|
{ |
|
|
|
|