25 OpenIDAuthorizationCodeInterface
40 $params = array_merge(array(
41 'authorization_codes' => array(),
42 'user_credentials' => array(),
43 'client_credentials' => array(),
44 'refresh_tokens' => array(),
45 'access_tokens' => array(),
48 'default_scope' =>
null,
49 'supported_scopes' => array(),
53 $this->authorizationCodes = $params[
'authorization_codes'];
54 $this->userCredentials = $params[
'user_credentials'];
55 $this->clientCredentials = $params[
'client_credentials'];
56 $this->refreshTokens = $params[
'refresh_tokens'];
57 $this->accessTokens = $params[
'access_tokens'];
58 $this->jwt = $params[
'jwt'];
59 $this->jti = $params[
'jti'];
60 $this->supportedScopes = $params[
'supported_scopes'];
61 $this->defaultScope = $params[
'default_scope'];
62 $this->keys = $params[
'keys'];
68 if (!isset($this->authorizationCodes[$code])) {
72 return array_merge(array(
73 'authorization_code' => $code,
74 ), $this->authorizationCodes[$code]);
77 public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope =
null, $id_token =
null)
79 $this->authorizationCodes[$code] = compact(
'code',
'client_id',
'user_id',
'redirect_uri',
'expires',
'scope',
'id_token');
86 $this->authorizationCodes = $authorization_codes;
91 unset($this->authorizationCodes[$code]);
99 return $userDetails && $userDetails[
'password'] && $userDetails[
'password'] === $password;
102 public function setUser($username, $password, $firstName =
null, $lastName =
null)
104 $this->userCredentials[$username] = array(
105 'password' => $password,
106 'first_name' => $firstName,
107 'last_name' => $lastName,
115 if (!isset($this->userCredentials[$username])) {
119 return array_merge(array(
120 'user_id' => $username,
122 'first_name' =>
null,
124 ), $this->userCredentials[$username]);
134 $claims = explode(
' ', trim($claims));
135 $userClaims = array();
138 $validClaims = explode(
' ', self::VALID_CLAIMS);
139 foreach ($validClaims
as $validClaim) {
140 if (in_array($validClaim, $claims)) {
141 if ($validClaim ==
'address') {
143 $userClaims[
'address'] = $this->
getUserClaim($validClaim, $userDetails[
'address'] ?: $userDetails);
145 $userClaims = array_merge($this->
getUserClaim($validClaim, $userDetails));
155 $userClaims = array();
156 $claimValuesString = constant(sprintf(
'self::%s_CLAIM_VALUES', strtoupper($claim)));
157 $claimValues = explode(
' ', $claimValuesString);
159 foreach ($claimValues
as $value) {
160 $userClaims[$value] = isset($userDetails[$value]) ? $userDetails[$value] :
null;
169 return isset($this->clientCredentials[$client_id][
'client_secret']) && $this->clientCredentials[$client_id][
'client_secret'] === $client_secret;
174 if (!isset($this->clientCredentials[$client_id])) {
178 return empty($this->clientCredentials[$client_id][
'client_secret']);
184 if (!isset($this->clientCredentials[$client_id])) {
188 $clientDetails = array_merge(array(
189 'client_id' => $client_id,
190 'client_secret' =>
null,
191 'redirect_uri' =>
null,
193 ), $this->clientCredentials[$client_id]);
195 return $clientDetails;
200 if (isset($this->clientCredentials[$client_id][
'grant_types'])) {
201 $grant_types = explode(
' ', $this->clientCredentials[$client_id][
'grant_types']);
203 return in_array($grant_type, $grant_types);
210 public function setClientDetails($client_id, $client_secret =
null, $redirect_uri =
null, $grant_types =
null, $scope =
null, $user_id =
null)
212 $this->clientCredentials[$client_id] = array(
213 'client_id' => $client_id,
214 'client_secret' => $client_secret,
215 'redirect_uri' => $redirect_uri,
216 'grant_types' => $grant_types,
218 'user_id' => $user_id,
227 return isset($this->refreshTokens[$refresh_token]) ? $this->refreshTokens[$refresh_token] :
false;
230 public function setRefreshToken($refresh_token, $client_id, $user_id, $expires, $scope =
null)
232 $this->refreshTokens[$refresh_token] = compact(
'refresh_token',
'client_id',
'user_id',
'expires',
'scope');
239 unset($this->refreshTokens[$refresh_token]);
244 $this->refreshTokens = $refresh_tokens;
250 return isset($this->accessTokens[$access_token]) ? $this->accessTokens[$access_token] :
false;
253 public function setAccessToken($access_token, $client_id, $user_id, $expires, $scope =
null, $id_token =
null)
255 $this->accessTokens[$access_token] = compact(
'access_token',
'client_id',
'user_id',
'expires',
'scope',
'id_token');
262 unset($this->accessTokens[$access_token]);
267 $scope = explode(
' ', trim($scope));
269 return (count(array_diff($scope, $this->supportedScopes)) == 0);
280 if (isset($this->jwt[$client_id])) {
281 $jwt = $this->jwt[$client_id];
283 if (
$jwt[
"subject"] == $subject) {
298 if (isset($clientDetails[
'scope'])) {
299 return $clientDetails[
'scope'];
305 public function getJti($client_id, $subject, $audience, $expires,
$jti)
307 foreach ($this->jti
as $storedJti) {
308 if ($storedJti[
'issuer'] == $client_id && $storedJti[
'subject'] == $subject && $storedJti[
'audience'] == $audience && $storedJti[
'expires'] == $expires && $storedJti[
'jti'] ==
$jti) {
310 'issuer' => $storedJti[
'issuer'],
311 'subject' => $storedJti[
'subject'],
312 'audience' => $storedJti[
'audience'],
313 'expires' => $storedJti[
'expires'],
314 'jti' => $storedJti[
'jti']
322 public function setJti($client_id, $subject, $audience, $expires,
$jti)
324 $this->jti[] = array(
'issuer' => $client_id,
'subject' => $subject,
'audience' => $audience,
'expires' => $expires,
'jti' =>
$jti);
330 if (isset($this->keys[$client_id])) {
331 return $this->keys[$client_id][
'public_key'];
335 if (isset($this->keys[
'public_key'])) {
336 return $this->keys[
'public_key'];
344 if (isset($this->keys[$client_id])) {
345 return $this->keys[$client_id][
'private_key'];
349 if (isset($this->keys[
'private_key'])) {
350 return $this->keys[
'private_key'];
358 if (isset($this->keys[$client_id][
'encryption_algorithm'])) {
359 return $this->keys[$client_id][
'encryption_algorithm'];
363 if (isset($this->keys[
'encryption_algorithm'])) {
364 return $this->keys[
'encryption_algorithm'];