class W3CTokenAuth in W3C Validator 8
Oauth authentication provider.
Hierarchy
- class \Drupal\w3c_validator\Authentication\Provider\W3CTokenAuth implements AuthenticationProviderInterface
 
Expanded class hierarchy of W3CTokenAuth
1 string reference to 'W3CTokenAuth'
1 service uses W3CTokenAuth
File
- src/
Authentication/ Provider/ W3CTokenAuth.php, line 14  
Namespace
Drupal\w3c_validator\Authentication\ProviderView source
class W3CTokenAuth implements AuthenticationProviderInterface {
  /**
   * A logger instance.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;
  /**
   * A W3cTokenManager instance.
   *
   * @var \Drupal\w3c_validator\W3CTokenManager
   */
  protected $w3cTokenManager;
  /**
   * Constructs a W3CSubscriber object.
   *
   * @param \Drupal\w3c_validator\W3CTokenManager $w3c_token_manager
   *   The form builder service.
   * @param \Psr\Log\LoggerInterface $logger
   *   A logger instance.
   */
  public function __construct(W3CTokenManager $w3c_token_manager, LoggerInterface $logger) {
    $this->w3cTokenManager = $w3c_token_manager;
    $this->logger = $logger;
  }
  /**
   * {@inheritdoc}
   */
  public function applies(Request $request) {
    // Only check requests with the 'authorization' header starting with OAuth.
    $token = $request->query
      ->get('HTTP_W3C_VALIDATOR_TOKEN');
    return isset($token);
  }
  /**
   * {@inheritdoc}
   */
  public function authenticate(Request $request) {
    $token = $request->query
      ->get('HTTP_W3C_VALIDATOR_TOKEN');
    // If a token is there.
    if (!empty($token) && ($user = $this->w3cTokenManager
      ->getUserFromToken($token))) {
      // Retrieve the current accessed URL.
      $current_url = Url::fromRoute('<current>');
      // Log the access.
      $this->logger
        ->notice('Request to validate private page @url using token @token for user @user', [
        '@url' => $current_url
          ->toString(),
        '@token' => $token,
        '@user' => $user
          ->label(),
      ]);
      return $user;
    }
    return NULL;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            W3CTokenAuth:: | 
                  protected | property | A logger instance. | |
| 
            W3CTokenAuth:: | 
                  protected | property | A W3cTokenManager instance. | |
| 
            W3CTokenAuth:: | 
                  public | function | 
            Checks whether suitable authentication credentials are on the request. Overrides AuthenticationProviderInterface:: | 
                  |
| 
            W3CTokenAuth:: | 
                  public | function | 
            Authenticates the user. Overrides AuthenticationProviderInterface:: | 
                  |
| 
            W3CTokenAuth:: | 
                  public | function | Constructs a W3CSubscriber object. |