You are here

class KeyAuth in Key auth 8

Same name in this branch
  1. 8 src/KeyAuth.php \Drupal\key_auth\KeyAuth
  2. 8 src/Authentication/Provider/KeyAuth.php \Drupal\key_auth\Authentication\Provider\KeyAuth

Key authentication provider.

Hierarchy

Expanded class hierarchy of KeyAuth

1 string reference to 'KeyAuth'
key_auth.services.yml in ./key_auth.services.yml
key_auth.services.yml
1 service uses KeyAuth
key_auth.authentication.key_auth in ./key_auth.services.yml
Drupal\key_auth\Authentication\Provider\KeyAuth

File

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

Namespace

Drupal\key_auth\Authentication\Provider
View source
class KeyAuth implements AuthenticationProviderInterface {

  /**
   * The key auth service.
   *
   * @var \Drupal\key_auth\KeyAuthInterface
   */
  protected $keyAuth;

  /**
   * Constructs a key authentication provider object.
   *
   * @param \Drupal\key_auth\KeyAuthInterface $key_auth
   *   The key auth service.
   */
  public function __construct(KeyAuthInterface $key_auth) {
    $this->keyAuth = $key_auth;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Request $request) {
    return (bool) $this->keyAuth
      ->getKey($request);
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyAuth::$keyAuth protected property The key auth service.
KeyAuth::applies public function Checks whether suitable authentication credentials are on the request. Overrides AuthenticationProviderInterface::applies
KeyAuth::authenticate public function Authenticates the user. Overrides AuthenticationProviderInterface::authenticate
KeyAuth::__construct public function Constructs a key authentication provider object.