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

Enable user claim storage in OpenID payload #1060

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 16 additions & 1 deletion src/OAuth2/OpenID/Controller/AuthorizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace OAuth2\OpenID\Controller;

use OAuth2\Controller\AuthorizeController as BaseAuthorizeController;
use OAuth2\OpenID\Storage\UserClaimsInterface;
use OAuth2\RequestInterface;
use OAuth2\ResponseInterface;
use OAuth2\Storage\ClientInterface;
use OAuth2\ScopeInterface;

/**
* @see OAuth2\Controller\AuthorizeControllerInterface
Expand All @@ -26,6 +29,17 @@ class AuthorizeController extends BaseAuthorizeController implements AuthorizeCo
*/
protected $code_challenge_method;

/**
* @var mixed
*/
protected $userClaimsStorage;

public function __construct(ClientInterface $clientStorage, UserClaimsInterface $userClaimsStorage, array $responseTypes = array(), array $config = array(), ScopeInterface $scopeUtil = null)
{
parent::__construct($clientStorage, $responseTypes, $config, $scopeUtil);
$this->userClaimsStorage = $userClaimsStorage;
}

/**
* Set not authorized response
*
Expand Down Expand Up @@ -69,7 +83,8 @@ protected function buildAuthorizeParameters($request, $response, $user_id)

// Generate an id token if needed.
if ($this->needsIdToken($this->getScope()) && $this->getResponseType() == self::RESPONSE_TYPE_AUTHORIZATION_CODE) {
$params['id_token'] = $this->responseTypes['id_token']->createIdToken($this->getClientId(), $user_id, $this->nonce);
$userClaims = $this->userClaimsStorage->getUserClaims($user_id, $params['scope']);
$params['id_token'] = $this->responseTypes['id_token']->createIdToken($this->getClientId(), $user_id, $this->nonce, $userClaims );
}

// add the nonce to return with the redirect URI
Expand Down
2 changes: 1 addition & 1 deletion src/OAuth2/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ protected function createDefaultAuthorizeController()
$config = array_intersect_key($this->config, array_flip(explode(' ', 'allow_implicit enforce_state require_exact_redirect_uri enforce_pkce')));

if ($this->config['use_openid_connect']) {
return new OpenIDAuthorizeController($this->storages['client'], $this->responseTypes, $config, $this->getScopeUtil());
return new OpenIDAuthorizeController($this->storages['client'], $this->storages['user_claims'], $this->responseTypes, $config, $this->getScopeUtil());
}

return new AuthorizeController($this->storages['client'], $this->responseTypes, $config, $this->getScopeUtil());
Expand Down