25 OpenIDAuthorizationCodeInterface
45 $this->config = array_merge(array(
46 'client_key' =>
'oauth_clients:',
47 'access_token_key' =>
'oauth_access_tokens:',
48 'refresh_token_key' =>
'oauth_refresh_tokens:',
49 'code_key' =>
'oauth_authorization_codes:',
50 'user_key' =>
'oauth_users:',
51 'jwt_key' =>
'oauth_jwt:',
52 'scope_key' =>
'oauth_scopes:',
58 if ( isset($this->cache[$key]) ) {
59 return $this->cache[$key];
61 $value = $this->redis->get($key);
62 if ( isset($value) ) {
63 return json_decode($value,
true);
69 protected function setValue($key, $value, $expire=0)
71 $this->cache[$key] = $value;
72 $str = json_encode($value);
74 $seconds = $expire -
time();
75 $ret = $this->redis->setex($key, $seconds, $str);
77 $ret = $this->redis->set($key, $str);
82 return is_bool(
$ret) ?
$ret :
$ret->getPayload() ==
'OK';
87 unset($this->cache[$key]);
89 return $this->redis->del($key);
95 return $this->
getValue($this->config[
'code_key'] . $code);
98 public function setAuthorizationCode($authorization_code, $client_id, $user_id, $redirect_uri, $expires, $scope =
null, $id_token =
null)
101 $this->config[
'code_key'] . $authorization_code,
102 compact(
'authorization_code',
'client_id',
'user_id',
'redirect_uri',
'expires',
'scope',
'id_token'),
109 $key = $this->config[
'code_key'] . $code;
110 unset($this->cache[$key]);
120 return $user && $user[
'password'] === $password;
125 return $this->
getUser($username);
130 if (!$userInfo = $this->
getValue($this->config[
'user_key'] . $username)) {
135 return array_merge(array(
136 'user_id' => $username,
140 public function setUser($username, $password, $first_name =
null, $last_name =
null)
143 $this->config[
'user_key'] . $username,
144 compact(
'username',
'password',
'first_name',
'last_name')
155 return isset($client[
'client_secret'])
156 && $client[
'client_secret'] == $client_secret;
165 return empty($result[
'client_secret']);
171 return $this->
getValue($this->config[
'client_key'] . $client_id);
174 public function setClientDetails($client_id, $client_secret =
null, $redirect_uri =
null, $grant_types =
null, $scope =
null, $user_id =
null)
177 $this->config[
'client_key'] . $client_id,
178 compact(
'client_id',
'client_secret',
'redirect_uri',
'grant_types',
'scope',
'user_id')
185 if (isset($details[
'grant_types'])) {
186 $grant_types = explode(
' ', $details[
'grant_types']);
188 return in_array($grant_type, (array) $grant_types);
198 return $this->
getValue($this->config[
'refresh_token_key'] . $refresh_token);
201 public function setRefreshToken($refresh_token, $client_id, $user_id, $expires, $scope =
null)
204 $this->config[
'refresh_token_key'] . $refresh_token,
205 compact(
'refresh_token',
'client_id',
'user_id',
'expires',
'scope'),
212 return $this->
expireValue($this->config[
'refresh_token_key'] . $refresh_token);
218 return $this->
getValue($this->config[
'access_token_key'].$access_token);
221 public function setAccessToken($access_token, $client_id, $user_id, $expires, $scope =
null)
224 $this->config[
'access_token_key'].$access_token,
225 compact(
'access_token',
'client_id',
'user_id',
'expires',
'scope'),
232 return $this->
expireValue($this->config[
'access_token_key'] . $access_token);
238 $scope = explode(
' ', $scope);
240 $result = $this->
getValue($this->config[
'scope_key'].
'supported:global');
242 $supportedScope = explode(
' ', (
string) $result);
244 return (count(array_diff($scope, $supportedScope)) == 0);
249 if (is_null($client_id) || !$result = $this->
getValue($this->config[
'scope_key'].
'default:'.$client_id)) {
250 $result = $this->
getValue($this->config[
'scope_key'].
'default:global');
256 public function setScope($scope, $client_id =
null, $type =
'supported')
258 if (!in_array($type, array(
'default',
'supported'))) {
259 throw new \InvalidArgumentException(
'"$type" must be one of "default", "supported"');
262 if (is_null($client_id)) {
263 $key = $this->config[
'scope_key'].$type.
':global';
265 $key = $this->config[
'scope_key'].$type.
':'.$client_id;
268 return $this->
setValue($key, $scope);
274 if (!$jwt = $this->
getValue($this->config[
'jwt_key'] . $client_id)) {
278 if (isset($jwt[
'subject']) && $jwt[
'subject'] == $subject) {
287 return $this->
setValue($this->config[
'jwt_key'] . $client_id, array(
289 'subject' => $subject
299 if (isset($clientDetails[
'scope'])) {
300 return $clientDetails[
'scope'];
306 public function getJti($client_id, $subject, $audience, $expiration, $jti)
309 throw new \Exception(
'getJti() for the Redis driver is currently unimplemented.');
312 public function setJti($client_id, $subject, $audience, $expiration, $jti)
315 throw new \Exception(
'setJti() for the Redis driver is currently unimplemented.');