Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] retrieving resource owner from JWT if no oidcEndpointUserInfo is set #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Classes/Service/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,26 @@ protected function authenticateWithResourceOwnerPasswordCredentials(string $user
protected function getUserFromAccessToken(OAuthService $service, AccessToken $accessToken)
{
// Using the access token, we may look up details about the resource owner
try {
$this->logger->debug('Retrieving resource owner');
$resourceOwner = $service->getResourceOwner($accessToken)->toArray();
$this->logger->debug('Resource owner retrieved', $resourceOwner);
} catch (IdentityProviderException $e) {
$this->logger->error('Could not retrieve resource owner', ['exception' => $e]);
return false;
if ($this->config['oidcEndpointUserInfo'] !== '') {
try {
$this->logger->debug('Retrieving resource owner');
$resourceOwner = $service->getResourceOwner($accessToken)->toArray();
$this->logger->debug('Resource owner retrieved', $resourceOwner);
} catch (IdentityProviderException $e) {
$this->logger->error('Could not retrieve resource owner', ['exception' => $e]);
return false;
}
} else {
$this->logger->debug('UserInfo Endpoint is not set, retrie resource owner form JSON Web Token');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retrieVE resource owner fROm

$jwt = $accessToken->getToken();
$jwtDecoded = base64_decode(str_replace('_', '/', str_replace('-','+',explode('.', $jwt)[1])));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing blank spaces on that line between some arguments.

$resourceOwner = json_decode($jwtDecoded, true);
if (json_last_error() !== JSON_ERROR_NONE) {
$this->logger->error('Could not retrieve resource owner from JSON Web Token', ['Failed to parse JSON response: %s' => json_last_error_msg()]);
return false;
}
}

if (empty($resourceOwner['sub'])) {
$this->logger->error('No "sub" found in resource owner, revoking access token');
try {
Expand Down