class KnownClientsRepository in Simple OAuth (OAuth2) & OpenID Connect 8.4
Same name and namespace in other branches
- 8.3 src/KnownClientsRepository.php \Drupal\simple_oauth\KnownClientsRepository
- 5.x src/KnownClientsRepository.php \Drupal\simple_oauth\KnownClientsRepository
Default implementation for the known clients repository.
Hierarchy
- class \Drupal\simple_oauth\KnownClientsRepository implements KnownClientsRepositoryInterface
Expanded class hierarchy of KnownClientsRepository
1 string reference to 'KnownClientsRepository'
1 service uses KnownClientsRepository
File
- src/
KnownClientsRepository.php, line 10
Namespace
Drupal\simple_oauthView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KnownClientsRepository:: |
protected | property | The user data service. | |
KnownClientsRepository:: |
public | function |
Checks if a given user authorized a client for a given set of scopes. Overrides KnownClientsRepositoryInterface:: |
|
KnownClientsRepository:: |
public | function |
Store a client with a set of scopes as authorized for a given user. Overrides KnownClientsRepositoryInterface:: |
|
KnownClientsRepository:: |
public | function | KnownClientsRepository constructor. |