class UserInfo in Simple OAuth (OAuth2) & OpenID Connect 5.x
Controller for the User Info endpoint.
Hierarchy
- class \Drupal\simple_oauth\Controller\UserInfo implements ContainerInjectionInterface
Expanded class hierarchy of UserInfo
File
- src/
Controller/ UserInfo.php, line 20
Namespace
Drupal\simple_oauth\ControllerView source
class UserInfo implements ContainerInjectionInterface {
/**
* The authenticated user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
private $user;
/**
* The serializer.
*
* @var \Symfony\Component\Serializer\SerializerInterface
*/
private $serializer;
/**
* The configuration object.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
private $config;
/**
* UserInfo constructor.
*
* @param \Drupal\Core\Session\AccountProxyInterface $user
* The user.
* @param \Symfony\Component\Serializer\SerializerInterface $serializer
* The serializer service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
private function __construct(AccountProxyInterface $user, SerializerInterface $serializer, ConfigFactoryInterface $config_factory) {
$this->user = $user
->getAccount();
$this->serializer = $serializer;
$this->config = $config_factory
->get('simple_oauth.settings');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('current_user'), $container
->get('serializer'), $container
->get('config.factory'));
}
/**
* The controller.
*
* @return \Symfony\Component\HttpFoundation\Response
* The response.
*
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UserInfo:: |
private | property | The configuration object. | |
UserInfo:: |
private | property | The serializer. | |
UserInfo:: |
private | property | The authenticated user. | |
UserInfo:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
UserInfo:: |
public | function | The controller. | |
UserInfo:: |
private | function | UserInfo constructor. |