You are here

public function UserInfo::handle in Simple OAuth (OAuth2) & OpenID Connect 5.x

The controller.

Return value

\Symfony\Component\HttpFoundation\Response The response.

Throws

\Symfony\Component\Serializer\Exception\ExceptionInterface

1 string reference to 'UserInfo::handle'
simple_oauth.routing.yml in ./simple_oauth.routing.yml
simple_oauth.routing.yml

File

src/Controller/UserInfo.php, line 79

Class

UserInfo
Controller for the User Info endpoint.

Namespace

Drupal\simple_oauth\Controller

Code

public function handle() {
  if (!$this->user instanceof TokenAuthUser) {
    throw new AccessDeniedHttpException('This route is only available for authenticated requests using OAuth2.');
  }
  if ($this->config
    ->get('disable_openid_connect')) {
    throw new NotFoundHttpException('Not Found');
  }
  assert($this->serializer instanceof NormalizerInterface);
  $identifier = $this->user
    ->id();
  $user_entity = new UserEntityWithClaims();
  $user_entity
    ->setIdentifier($identifier);
  $data = $this->serializer
    ->normalize($user_entity, 'json', [
    $identifier => $this->user,
  ]);
  return JsonResponse::create($data);
}