Skip to content

Commit

Permalink
Add sub to OIDC user info response
Browse files Browse the repository at this point in the history
According to the specs sub (subject, user id) is a mandatory claim in the user info response.
  • Loading branch information
EreMaijala committed Oct 1, 2024
1 parent 0ee7d2b commit 71a44d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions module/VuFind/src/VuFind/Controller/OAuth2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ public function userInfoAction()
OAuthServerException::accessDenied('User does not exist anymore')
);
}
$result = $this->claimExtractor
->extract($scopes, $userEntity->getClaims());
$result = $this->claimExtractor->extract($scopes, $userEntity->getClaims());
// The sub claim must always be returned:
$result['sub'] = $userId;
return $this->getJsonResponse($result);
} catch (OAuthServerException $e) {
return $this->handleOAuth2Exception('User info request', $e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public function testOAuth2Authorization(): void
);

$userInfo = json_decode($response->getBody(), true);
$this->assertEquals($idToken->sub, $userInfo['sub']);
$this->assertEquals($nonce, $userInfo['nonce']);
$this->assertEquals('Tester McTestenson', $userInfo['name']);
$this->assertEquals('Tester', $userInfo['given_name']);
Expand Down

0 comments on commit 71a44d0

Please sign in to comment.