You are here

class KnownClientsRepository in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same name and namespace in other branches
  1. 8.3 src/KnownClientsRepository.php \Drupal\simple_oauth\KnownClientsRepository
  2. 5.x src/KnownClientsRepository.php \Drupal\simple_oauth\KnownClientsRepository

Default implementation for the known clients repository.

Hierarchy

Expanded class hierarchy of KnownClientsRepository

1 string reference to 'KnownClientsRepository'
simple_oauth.services.yml in ./simple_oauth.services.yml
simple_oauth.services.yml
1 service uses KnownClientsRepository
simple_oauth.known_clients in ./simple_oauth.services.yml
\Drupal\simple_oauth\KnownClientsRepository

File

src/KnownClientsRepository.php, line 10

Namespace

Drupal\simple_oauth
View source
class KnownClientsRepository implements KnownClientsRepositoryInterface {

  /**
   * The user data service.
   *
   * @var \Drupal\user\UserDataInterface
   */
  protected $userData;

  /**
   * KnownClientsRepository constructor.
   *
   * @param \Drupal\user\UserDataInterface $user_data
   *   The user data service.
   */
  public function __construct(UserDataInterface $user_data) {
    $this->userData = $user_data;
  }

  /**
   * {@inheritdoc}
   */
  public function isAuthorized($uid, $client_id, array $scopes) {
    $name = 'client:' . $client_id;
    $authorized_scopes = $this->userData
      ->get('simple_oauth', $uid, $name);

    // Access is allowed if all the requested scopes are part of the alrady
    // authorized scopes.
    if (is_array($authorized_scopes) && !array_diff($scopes, $authorized_scopes)) {
      return TRUE;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function rememberClient($uid, $client_id, array $scopes) {
    $name = 'client:' . $client_id;
    $existing_scopes = (array) $this->userData
      ->get('simple_oauth', $uid, $name);
    $scopes = array_unique(array_merge($scopes, $existing_scopes));
    $this->userData
      ->set('simple_oauth', $uid, $name, $scopes);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KnownClientsRepository::$userData protected property The user data service.
KnownClientsRepository::isAuthorized public function Checks if a given user authorized a client for a given set of scopes. Overrides KnownClientsRepositoryInterface::isAuthorized
KnownClientsRepository::rememberClient public function Store a client with a set of scopes as authorized for a given user. Overrides KnownClientsRepositoryInterface::rememberClient
KnownClientsRepository::__construct public function KnownClientsRepository constructor.