You are here

class RouteAccess in OAuth2 Client 8.3

Custom access checking on oauth2_client routes.

@package Drupal\oauth2_client\Access

Hierarchy

Expanded class hierarchy of RouteAccess

1 string reference to 'RouteAccess'
oauth2_client.services.yml in ./oauth2_client.services.yml
oauth2_client.services.yml
1 service uses RouteAccess
oauth2_client.service.route_access in ./oauth2_client.services.yml
Drupal\oauth2_client\Access\RouteAccess

File

src/Access/RouteAccess.php, line 17

Namespace

Drupal\oauth2_client\Access
View source
class RouteAccess implements AccessInterface {

  /**
   * The OAuth2 Client plugin manager.
   *
   * @var \Drupal\oauth2_client\PluginManager\Oauth2ClientPluginManager
   */
  protected $pluginManager;

  /**
   * RouteAccess constructor.
   *
   * @param \Drupal\oauth2_client\PluginManager\Oauth2ClientPluginManager $pluginManager
   *   Injected service.
   */
  public function __construct(Oauth2ClientPluginManager $pluginManager) {
    $this->pluginManager = $pluginManager;
  }

  /**
   * Checks access to designated routes.
   *
   * Any route uses this access checker delegates the access check to the
   * relevant plugin, if that plugin desires to customize access.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
   *   The parametrized route.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(RouteMatchInterface $routeMatch, AccountInterface $account) {
    if ($routeMatch
      ->getRouteName() !== 'oauth2_client.code') {
      return AccessResult::neutral('This access check is for `oauth2_client.code` only.');
    }
    $pluginId = $routeMatch
      ->getParameter('plugin');
    $plugin = $this->pluginManager
      ->createInstance($pluginId);
    if ($plugin instanceof Oauth2ClientPluginAccessInterface) {
      return $plugin
        ->codeRouteAccess($account);
    }
    return AccessResult::allowedIfHasPermission($account, 'administer oauth2 clients');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteAccess::$pluginManager protected property The OAuth2 Client plugin manager.
RouteAccess::access public function Checks access to designated routes.
RouteAccess::__construct public function RouteAccess constructor.