You are here

class W3CTokenAuth in W3C Validator 8

Oauth authentication provider.

Hierarchy

Expanded class hierarchy of W3CTokenAuth

1 string reference to 'W3CTokenAuth'
w3c_validator.services.yml in ./w3c_validator.services.yml
w3c_validator.services.yml
1 service uses W3CTokenAuth
w3c.authentication.token_auth in ./w3c_validator.services.yml
Drupal\w3c_validator\Authentication\Provider\W3CTokenAuth

File

src/Authentication/Provider/W3CTokenAuth.php, line 14

Namespace

Drupal\w3c_validator\Authentication\Provider
View 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

Namesort descending Modifiers Type Description Overrides
W3CTokenAuth::$logger protected property A logger instance.
W3CTokenAuth::$w3cTokenManager protected property A W3cTokenManager instance.
W3CTokenAuth::applies public function Checks whether suitable authentication credentials are on the request. Overrides AuthenticationProviderInterface::applies
W3CTokenAuth::authenticate public function Authenticates the user. Overrides AuthenticationProviderInterface::authenticate
W3CTokenAuth::__construct public function Constructs a W3CSubscriber object.