You are here

public function TokenAuthUser::__construct in Simple OAuth (OAuth2) & OpenID Connect 5.x

Same name and namespace in other branches
  1. 8.4 src/Authentication/TokenAuthUser.php \Drupal\simple_oauth\Authentication\TokenAuthUser::__construct()
  2. 8 src/Authentication/TokenAuthUser.php \Drupal\simple_oauth\Authentication\TokenAuthUser::__construct()
  3. 8.2 src/Authentication/TokenAuthUser.php \Drupal\simple_oauth\Authentication\TokenAuthUser::__construct()
  4. 8.3 src/Authentication/TokenAuthUser.php \Drupal\simple_oauth\Authentication\TokenAuthUser::__construct()

Constructs a TokenAuthUser object.

Parameters

\Drupal\simple_oauth\Entity\Oauth2TokenInterface $token: The underlying token.

Throws

\League\OAuth2\Server\Exception\OAuthServerException When there is no user.

File

src/Authentication/TokenAuthUser.php, line 50

Class

TokenAuthUser
The decorated user class with token information.

Namespace

Drupal\simple_oauth\Authentication

Code

public function __construct(Oauth2TokenInterface $token) {
  $this->consumer = $token
    ->get('client')->entity;
  if (!($this->subject = $token
    ->get('auth_user_id')->entity)) {
    $this->subject = $this->consumer
      ->get('user_id')->entity;
  }
  if (!$this->subject) {
    $server_request = \Drupal::service('psr7.http_message_factory')
      ->createRequest(\Drupal::request());
    throw OAuthServerException::invalidClient($server_request);
  }
  $this->token = $token;
}