Skip to content

Commit

Permalink
bug #1133 #1083. Fixed issue with option user_id_claim. (Konstantin L…
Browse files Browse the repository at this point in the history
…itvinov)

This PR was merged into the 2.x branch.

Discussion
----------

#1083. Fixed issue with option user_id_claim.

Fixed issue with configuration option `user_id_claim`

Commits
-------

d5d2b6f #1083. Fixed issue with option user_id_claim.
  • Loading branch information
chalasr committed Apr 11, 2023
2 parents fa3a02a + d5d2b6f commit af19e10
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Services/JWTManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@ public function parse(string $jwtToken): array
*/
protected function addUserIdentityToPayload(UserInterface $user, array &$payload)
{
$accessor = PropertyAccess::createPropertyAccessor();
$accessor = PropertyAccess::createPropertyAccessor();
$identityField = $this->userIdClaim ?: $this->userIdentityField;

if ($user instanceof InMemoryUser && ('username' === $this->userIdClaim || 'username' === $this->userIdentityField)) {
$payload[$this->userIdClaim ?: $this->userIdentityField] = $accessor->getValue($user, 'userIdentifier');
if ($user instanceof InMemoryUser && 'username' === $identityField) {
$payload[$identityField] = $accessor->getValue($user, 'userIdentifier');

return;
}

$payload[$this->userIdClaim ?: $this->userIdentityField] = $accessor->getValue($user, $accessor->isReadable($user, $this->userIdentityField) ? $this->userIdentityField : 'user_identifier');
$payload[$identityField] = $accessor->getValue($user, $accessor->isReadable($user, $identityField) ? $identityField : 'user_identifier');
}

/**
Expand Down

0 comments on commit af19e10

Please sign in to comment.