Skip to content

Commit

Permalink
Stop using the ClaimsIdentity constructor accepting a single string p…
Browse files Browse the repository at this point in the history
…arameter and use explicit claim types
  • Loading branch information
kevinchalet committed Jan 23, 2024
1 parent 0a2d1d4 commit b386b78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/OpenIddict.Client/OpenIddictClientHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,11 @@ public ValueTask HandleAsync(ProcessAuthenticationContext context)
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));

// Create a new principal that will be used to store the client assertion claims.
var principal = new ClaimsPrincipal(new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType));
var principal = new ClaimsPrincipal(new ClaimsIdentity(
authenticationType: TokenValidationParameters.DefaultAuthenticationType,
nameType: Claims.Name,
roleType: Claims.Role));

principal.SetCreationDate(DateTimeOffset.UtcNow);

var lifetime = context.Options.ClientAssertionLifetime;
Expand Down Expand Up @@ -4019,7 +4023,10 @@ ClaimsPrincipal CreateMergedPrincipal(params ClaimsPrincipal?[] principals)
context.Registration.TokenValidationParameters.AuthenticationType,
context.Registration.TokenValidationParameters.NameClaimType,
context.Registration.TokenValidationParameters.RoleClaimType) :
new ClaimsIdentity(context.Registration.TokenValidationParameters.AuthenticationType);
new ClaimsIdentity(
context.Registration.TokenValidationParameters.AuthenticationType,
nameType: ClaimTypes.Name,
roleType: ClaimTypes.Role);

foreach (var principal in principals)
{
Expand Down Expand Up @@ -5479,7 +5486,11 @@ public ValueTask HandleAsync(ProcessChallengeContext context)
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));

// Create a new principal that will be used to store the client assertion claims.
var principal = new ClaimsPrincipal(new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType));
var principal = new ClaimsPrincipal(new ClaimsIdentity(
authenticationType: TokenValidationParameters.DefaultAuthenticationType,
nameType: Claims.Name,
roleType: Claims.Role));

principal.SetCreationDate(DateTimeOffset.UtcNow);

var lifetime = context.Options.ClientAssertionLifetime;
Expand Down
6 changes: 5 additions & 1 deletion src/OpenIddict.Validation/OpenIddictValidationHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ public ValueTask HandleAsync(ProcessAuthenticationContext context)
Debug.Assert(context.Configuration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));

// Create a new principal that will be used to store the client assertion claims.
var principal = new ClaimsPrincipal(new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType));
var principal = new ClaimsPrincipal(new ClaimsIdentity(
authenticationType: TokenValidationParameters.DefaultAuthenticationType,
nameType: Claims.Name,
roleType: Claims.Role));

principal.SetCreationDate(DateTimeOffset.UtcNow);

var lifetime = context.Options.ClientAssertionLifetime;
Expand Down

0 comments on commit b386b78

Please sign in to comment.