Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Fix act claim chaining (#15)
Browse files Browse the repository at this point in the history
* fix: act claim chaining
  • Loading branch information
ademargoncalves authored Jul 19, 2022
1 parent 8448e4e commit 2bfd936
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ public IExtensionGrantResultBuilder WithError(TokenRequestErrors error, string e

private Claim BuildActClaim(IEnumerable<string> claimTypesToInclude)
{
var act = new Dictionary<string, object>();
var act = new Dictionary<string, object>
{
{ JwtClaimTypes.ClientId, this.actorClient.ClientId },
};

var existingActClaim = this.subjectUserClaims.Act();

Expand All @@ -147,11 +150,6 @@ private Claim BuildActClaim(IEnumerable<string> claimTypesToInclude)
lastClientId = actClaimObject.LastClientId;
}

if (existingActClaim.IsNullOrEmpty() || this.actorClient.ClientId != lastClientId)
{
act.Add(JwtClaimTypes.ClientId, this.actorClient.ClientId);
}

foreach (var claimType in claimTypesToInclude)
{
var claim = this.actorUserClaims.SingleOrDefault(c => claimType.Equals(c.Type));
Expand All @@ -161,10 +159,14 @@ private Claim BuildActClaim(IEnumerable<string> claimTypesToInclude)
}
}

if (!string.IsNullOrEmpty(existingActClaim) && this.actorClient.ClientId != lastClientId)
if (!string.IsNullOrEmpty(existingActClaim))
{
this.subjectUserClaims.Remove(this.subjectUserClaims.FirstOrDefault(c => TokenExchangeConstants.ClaimTypes.Act.Equals(c.Type)));
act.Add(TokenExchangeConstants.ClaimTypes.Act, JsonConvert.DeserializeObject(existingActClaim, this.jsonSettings));
if (this.actorClient.ClientId != lastClientId)
{
act.Add(TokenExchangeConstants.ClaimTypes.Act,
JsonConvert.DeserializeObject(existingActClaim, this.jsonSettings));
}
}

var existingClientActClaim = this.subjectUserClaims.ClientAct();
Expand Down

0 comments on commit 2bfd936

Please sign in to comment.