You are here

public function KeyAuth::authenticate in Key auth 8

Authenticates the user.

Parameters

\Symfony\Component\HttpFoundation\Request|null $request: The request object.

Return value

\Drupal\Core\Session\AccountInterface|null AccountInterface - in case of a successful authentication. NULL - in case where authentication failed.

Overrides AuthenticationProviderInterface::authenticate

File

src/Authentication/Provider/KeyAuth.php, line 41

Class

KeyAuth
Key authentication provider.

Namespace

Drupal\key_auth\Authentication\Provider

Code

public function authenticate(Request $request) {

  // Get the provided key.
  if ($key = $this->keyAuth
    ->getKey($request)) {

    // Find the linked user.
    if ($user = $this->keyAuth
      ->getUserByKey($key)) {

      // Check access.
      if ($this->keyAuth
        ->access($user)) {

        // Return the user.
        return $user;
      }
    }
  }
  return NULL;
}