KnownClientsRepository.php in Simple OAuth (OAuth2) & OpenID Connect 8.4
File
src/KnownClientsRepository.php
View source
<?php
namespace Drupal\simple_oauth;
use Drupal\user\UserDataInterface;
class KnownClientsRepository implements KnownClientsRepositoryInterface {
protected $userData;
public function __construct(UserDataInterface $user_data) {
$this->userData = $user_data;
}
public function isAuthorized($uid, $client_id, array $scopes) {
$name = 'client:' . $client_id;
$authorized_scopes = $this->userData
->get('simple_oauth', $uid, $name);
if (is_array($authorized_scopes) && !array_diff($scopes, $authorized_scopes)) {
return TRUE;
}
return FALSE;
}
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);
}
}