You are here

public function TokenAuthUser::__construct in Simple OAuth (OAuth2) & OpenID Connect 8.2

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.3 src/Authentication/TokenAuthUser.php \Drupal\simple_oauth\Authentication\TokenAuthUser::__construct()
  4. 5.x 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

\Exception When there is no user.

File

src/Authentication/TokenAuthUser.php, line 40

Class

TokenAuthUser
@internal

Namespace

Drupal\simple_oauth\Authentication

Code

public function __construct(Oauth2TokenInterface $token) {
  if (!($this->subject = $token
    ->get('auth_user_id')->entity)) {

    /** @var \Drupal\simple_oauth\Entity\Oauth2ClientInterface $client */
    if ($client = $token
      ->get('client')->entity) {
      $this->subject = $client
        ->getDefaultUser();
    }
  }
  if (!$this->subject) {
    throw OAuthServerException::invalidClient();
  }
  $this->token = $token;
}