@@ -11,23 +11,23 @@ |
||
11 | 11 | */ |
12 | 12 | class AuthorizationCode extends BaseAuthorizationCode |
13 | 13 | { |
14 | - public function createAccessToken(AccessTokenInterface $accessToken, $client_id, $user_id, $scope) |
|
15 | - { |
|
16 | - $includeRefreshToken = true; |
|
17 | - if (isset($this->authCode['id_token'])) { |
|
18 | - // OpenID Connect requests include the refresh token only if the |
|
19 | - // offline_access scope has been requested and granted. |
|
20 | - $scopes = explode(' ', trim($scope)); |
|
21 | - $includeRefreshToken = in_array('offline_access', $scopes); |
|
22 | - } |
|
14 | + public function createAccessToken(AccessTokenInterface $accessToken, $client_id, $user_id, $scope) |
|
15 | + { |
|
16 | + $includeRefreshToken = true; |
|
17 | + if (isset($this->authCode['id_token'])) { |
|
18 | + // OpenID Connect requests include the refresh token only if the |
|
19 | + // offline_access scope has been requested and granted. |
|
20 | + $scopes = explode(' ', trim($scope)); |
|
21 | + $includeRefreshToken = in_array('offline_access', $scopes); |
|
22 | + } |
|
23 | 23 | |
24 | - $token = $accessToken->createAccessToken($client_id, $user_id, $scope, $includeRefreshToken); |
|
25 | - if (isset($this->authCode['id_token'])) { |
|
26 | - $token['id_token'] = $this->authCode['id_token']; |
|
27 | - } |
|
24 | + $token = $accessToken->createAccessToken($client_id, $user_id, $scope, $includeRefreshToken); |
|
25 | + if (isset($this->authCode['id_token'])) { |
|
26 | + $token['id_token'] = $this->authCode['id_token']; |
|
27 | + } |
|
28 | 28 | |
29 | - $this->storage->expireAuthorizationCode($this->authCode['code']); |
|
29 | + $this->storage->expireAuthorizationCode($this->authCode['code']); |
|
30 | 30 | |
31 | - return $token; |
|
32 | - } |
|
31 | + return $token; |
|
32 | + } |
|
33 | 33 | } |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | interface AuthorizeControllerInterface |
6 | 6 | { |
7 | - const RESPONSE_TYPE_ID_TOKEN = 'id_token'; |
|
8 | - const RESPONSE_TYPE_ID_TOKEN_TOKEN = 'id_token token'; |
|
9 | - const RESPONSE_TYPE_CODE_ID_TOKEN = 'code id_token'; |
|
7 | + const RESPONSE_TYPE_ID_TOKEN = 'id_token'; |
|
8 | + const RESPONSE_TYPE_ID_TOKEN_TOKEN = 'id_token token'; |
|
9 | + const RESPONSE_TYPE_CODE_ID_TOKEN = 'code id_token'; |
|
10 | 10 | } |
@@ -16,43 +16,43 @@ |
||
16 | 16 | */ |
17 | 17 | class UserInfoController extends ResourceController implements UserInfoControllerInterface |
18 | 18 | { |
19 | - private $token; |
|
20 | - |
|
21 | - protected $tokenType; |
|
22 | - protected $tokenStorage; |
|
23 | - protected $userClaimsStorage; |
|
24 | - protected $config; |
|
25 | - protected $scopeUtil; |
|
26 | - |
|
27 | - public function __construct(TokenTypeInterface $tokenType, AccessTokenInterface $tokenStorage, UserClaimsInterface $userClaimsStorage, $config = array(), ScopeInterface $scopeUtil = null) |
|
28 | - { |
|
29 | - $this->tokenType = $tokenType; |
|
30 | - $this->tokenStorage = $tokenStorage; |
|
31 | - $this->userClaimsStorage = $userClaimsStorage; |
|
32 | - |
|
33 | - $this->config = array_merge(array( |
|
34 | - 'www_realm' => 'Service', |
|
35 | - ), $config); |
|
36 | - |
|
37 | - if (is_null($scopeUtil)) { |
|
38 | - $scopeUtil = new Scope(); |
|
39 | - } |
|
40 | - $this->scopeUtil = $scopeUtil; |
|
41 | - } |
|
42 | - |
|
43 | - public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response) |
|
44 | - { |
|
45 | - if (!$this->verifyResourceRequest($request, $response, 'openid')) { |
|
46 | - return; |
|
47 | - } |
|
48 | - |
|
49 | - $token = $this->getToken(); |
|
50 | - $claims = $this->userClaimsStorage->getUserClaims($token['user_id'], $token['scope']); |
|
51 | - // The sub Claim MUST always be returned in the UserInfo Response. |
|
52 | - // http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse |
|
53 | - $claims += array( |
|
54 | - 'sub' => $token['user_id'], |
|
55 | - ); |
|
56 | - $response->addParameters($claims); |
|
57 | - } |
|
19 | + private $token; |
|
20 | + |
|
21 | + protected $tokenType; |
|
22 | + protected $tokenStorage; |
|
23 | + protected $userClaimsStorage; |
|
24 | + protected $config; |
|
25 | + protected $scopeUtil; |
|
26 | + |
|
27 | + public function __construct(TokenTypeInterface $tokenType, AccessTokenInterface $tokenStorage, UserClaimsInterface $userClaimsStorage, $config = array(), ScopeInterface $scopeUtil = null) |
|
28 | + { |
|
29 | + $this->tokenType = $tokenType; |
|
30 | + $this->tokenStorage = $tokenStorage; |
|
31 | + $this->userClaimsStorage = $userClaimsStorage; |
|
32 | + |
|
33 | + $this->config = array_merge(array( |
|
34 | + 'www_realm' => 'Service', |
|
35 | + ), $config); |
|
36 | + |
|
37 | + if (is_null($scopeUtil)) { |
|
38 | + $scopeUtil = new Scope(); |
|
39 | + } |
|
40 | + $this->scopeUtil = $scopeUtil; |
|
41 | + } |
|
42 | + |
|
43 | + public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response) |
|
44 | + { |
|
45 | + if (!$this->verifyResourceRequest($request, $response, 'openid')) { |
|
46 | + return; |
|
47 | + } |
|
48 | + |
|
49 | + $token = $this->getToken(); |
|
50 | + $claims = $this->userClaimsStorage->getUserClaims($token['user_id'], $token['scope']); |
|
51 | + // The sub Claim MUST always be returned in the UserInfo Response. |
|
52 | + // http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse |
|
53 | + $claims += array( |
|
54 | + 'sub' => $token['user_id'], |
|
55 | + ); |
|
56 | + $response->addParameters($claims); |
|
57 | + } |
|
58 | 58 | } |
@@ -11,96 +11,96 @@ |
||
11 | 11 | */ |
12 | 12 | class AuthorizeController extends BaseAuthorizeController implements AuthorizeControllerInterface |
13 | 13 | { |
14 | - private $nonce; |
|
15 | - |
|
16 | - protected function setNotAuthorizedResponse(RequestInterface $request, ResponseInterface $response, $redirect_uri, $user_id = null) |
|
17 | - { |
|
18 | - $prompt = $request->query('prompt', 'consent'); |
|
19 | - if ($prompt == 'none') { |
|
20 | - if (is_null($user_id)) { |
|
21 | - $error = 'login_required'; |
|
22 | - $error_message = 'The user must log in'; |
|
23 | - } else { |
|
24 | - $error = 'interaction_required'; |
|
25 | - $error_message = 'The user must grant access to your application'; |
|
26 | - } |
|
27 | - } else { |
|
28 | - $error = 'consent_required'; |
|
29 | - $error_message = 'The user denied access to your application'; |
|
30 | - } |
|
31 | - |
|
32 | - $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $this->getState(), $error, $error_message); |
|
33 | - } |
|
34 | - |
|
35 | - protected function buildAuthorizeParameters($request, $response, $user_id) |
|
36 | - { |
|
37 | - if (!$params = parent::buildAuthorizeParameters($request, $response, $user_id)) { |
|
38 | - return; |
|
39 | - } |
|
40 | - |
|
41 | - // Generate an id token if needed. |
|
42 | - if ($this->needsIdToken($this->getScope()) && $this->getResponseType() == self::RESPONSE_TYPE_AUTHORIZATION_CODE) { |
|
43 | - $params['id_token'] = $this->responseTypes['id_token']->createIdToken($this->getClientId(), $user_id, $this->nonce); |
|
44 | - } |
|
45 | - |
|
46 | - // add the nonce to return with the redirect URI |
|
47 | - $params['nonce'] = $this->nonce; |
|
48 | - |
|
49 | - return $params; |
|
50 | - } |
|
51 | - |
|
52 | - public function validateAuthorizeRequest(RequestInterface $request, ResponseInterface $response) |
|
53 | - { |
|
54 | - if (!parent::validateAuthorizeRequest($request, $response)) { |
|
55 | - return false; |
|
56 | - } |
|
57 | - |
|
58 | - $nonce = $request->query('nonce'); |
|
59 | - |
|
60 | - // Validate required nonce for "id_token" and "id_token token" |
|
61 | - if (!$nonce && in_array($this->getResponseType(), array(self::RESPONSE_TYPE_ID_TOKEN, self::RESPONSE_TYPE_ID_TOKEN_TOKEN))) { |
|
62 | - $response->setError(400, 'invalid_nonce', 'This application requires you specify a nonce parameter'); |
|
63 | - |
|
64 | - return false; |
|
65 | - } |
|
66 | - |
|
67 | - $this->nonce = $nonce; |
|
68 | - |
|
69 | - return true; |
|
70 | - } |
|
71 | - |
|
72 | - protected function getValidResponseTypes() |
|
73 | - { |
|
74 | - return array( |
|
75 | - self::RESPONSE_TYPE_ACCESS_TOKEN, |
|
76 | - self::RESPONSE_TYPE_AUTHORIZATION_CODE, |
|
77 | - self::RESPONSE_TYPE_ID_TOKEN, |
|
78 | - self::RESPONSE_TYPE_ID_TOKEN_TOKEN, |
|
79 | - self::RESPONSE_TYPE_CODE_ID_TOKEN, |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns whether the current request needs to generate an id token. |
|
85 | - * |
|
86 | - * ID Tokens are a part of the OpenID Connect specification, so this |
|
87 | - * method checks whether OpenID Connect is enabled in the server settings |
|
88 | - * and whether the openid scope was requested. |
|
89 | - * |
|
90 | - * @param $request_scope |
|
91 | - * A space-separated string of scopes. |
|
92 | - * |
|
93 | - * @return |
|
94 | - * TRUE if an id token is needed, FALSE otherwise. |
|
95 | - */ |
|
96 | - public function needsIdToken($request_scope) |
|
97 | - { |
|
98 | - // see if the "openid" scope exists in the requested scope |
|
99 | - return $this->scopeUtil->checkScope('openid', $request_scope); |
|
100 | - } |
|
101 | - |
|
102 | - public function getNonce() |
|
103 | - { |
|
104 | - return $this->nonce; |
|
105 | - } |
|
14 | + private $nonce; |
|
15 | + |
|
16 | + protected function setNotAuthorizedResponse(RequestInterface $request, ResponseInterface $response, $redirect_uri, $user_id = null) |
|
17 | + { |
|
18 | + $prompt = $request->query('prompt', 'consent'); |
|
19 | + if ($prompt == 'none') { |
|
20 | + if (is_null($user_id)) { |
|
21 | + $error = 'login_required'; |
|
22 | + $error_message = 'The user must log in'; |
|
23 | + } else { |
|
24 | + $error = 'interaction_required'; |
|
25 | + $error_message = 'The user must grant access to your application'; |
|
26 | + } |
|
27 | + } else { |
|
28 | + $error = 'consent_required'; |
|
29 | + $error_message = 'The user denied access to your application'; |
|
30 | + } |
|
31 | + |
|
32 | + $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $this->getState(), $error, $error_message); |
|
33 | + } |
|
34 | + |
|
35 | + protected function buildAuthorizeParameters($request, $response, $user_id) |
|
36 | + { |
|
37 | + if (!$params = parent::buildAuthorizeParameters($request, $response, $user_id)) { |
|
38 | + return; |
|
39 | + } |
|
40 | + |
|
41 | + // Generate an id token if needed. |
|
42 | + if ($this->needsIdToken($this->getScope()) && $this->getResponseType() == self::RESPONSE_TYPE_AUTHORIZATION_CODE) { |
|
43 | + $params['id_token'] = $this->responseTypes['id_token']->createIdToken($this->getClientId(), $user_id, $this->nonce); |
|
44 | + } |
|
45 | + |
|
46 | + // add the nonce to return with the redirect URI |
|
47 | + $params['nonce'] = $this->nonce; |
|
48 | + |
|
49 | + return $params; |
|
50 | + } |
|
51 | + |
|
52 | + public function validateAuthorizeRequest(RequestInterface $request, ResponseInterface $response) |
|
53 | + { |
|
54 | + if (!parent::validateAuthorizeRequest($request, $response)) { |
|
55 | + return false; |
|
56 | + } |
|
57 | + |
|
58 | + $nonce = $request->query('nonce'); |
|
59 | + |
|
60 | + // Validate required nonce for "id_token" and "id_token token" |
|
61 | + if (!$nonce && in_array($this->getResponseType(), array(self::RESPONSE_TYPE_ID_TOKEN, self::RESPONSE_TYPE_ID_TOKEN_TOKEN))) { |
|
62 | + $response->setError(400, 'invalid_nonce', 'This application requires you specify a nonce parameter'); |
|
63 | + |
|
64 | + return false; |
|
65 | + } |
|
66 | + |
|
67 | + $this->nonce = $nonce; |
|
68 | + |
|
69 | + return true; |
|
70 | + } |
|
71 | + |
|
72 | + protected function getValidResponseTypes() |
|
73 | + { |
|
74 | + return array( |
|
75 | + self::RESPONSE_TYPE_ACCESS_TOKEN, |
|
76 | + self::RESPONSE_TYPE_AUTHORIZATION_CODE, |
|
77 | + self::RESPONSE_TYPE_ID_TOKEN, |
|
78 | + self::RESPONSE_TYPE_ID_TOKEN_TOKEN, |
|
79 | + self::RESPONSE_TYPE_CODE_ID_TOKEN, |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns whether the current request needs to generate an id token. |
|
85 | + * |
|
86 | + * ID Tokens are a part of the OpenID Connect specification, so this |
|
87 | + * method checks whether OpenID Connect is enabled in the server settings |
|
88 | + * and whether the openid scope was requested. |
|
89 | + * |
|
90 | + * @param $request_scope |
|
91 | + * A space-separated string of scopes. |
|
92 | + * |
|
93 | + * @return |
|
94 | + * TRUE if an id token is needed, FALSE otherwise. |
|
95 | + */ |
|
96 | + public function needsIdToken($request_scope) |
|
97 | + { |
|
98 | + // see if the "openid" scope exists in the requested scope |
|
99 | + return $this->scopeUtil->checkScope('openid', $request_scope); |
|
100 | + } |
|
101 | + |
|
102 | + public function getNonce() |
|
103 | + { |
|
104 | + return $this->nonce; |
|
105 | + } |
|
106 | 106 | } |
@@ -19,5 +19,5 @@ |
||
19 | 19 | */ |
20 | 20 | interface UserInfoControllerInterface |
21 | 21 | { |
22 | - public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response); |
|
22 | + public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response); |
|
23 | 23 | } |
@@ -8,31 +8,31 @@ |
||
8 | 8 | */ |
9 | 9 | interface UserClaimsInterface |
10 | 10 | { |
11 | - // valid scope values to pass into the user claims API call |
|
12 | - const VALID_CLAIMS = 'profile email address phone'; |
|
11 | + // valid scope values to pass into the user claims API call |
|
12 | + const VALID_CLAIMS = 'profile email address phone'; |
|
13 | 13 | |
14 | - // fields returned for the claims above |
|
15 | - const PROFILE_CLAIM_VALUES = 'name family_name given_name middle_name nickname preferred_username profile picture website gender birthdate zoneinfo locale updated_at'; |
|
16 | - const EMAIL_CLAIM_VALUES = 'email email_verified'; |
|
17 | - const ADDRESS_CLAIM_VALUES = 'formatted street_address locality region postal_code country'; |
|
18 | - const PHONE_CLAIM_VALUES = 'phone_number phone_number_verified'; |
|
14 | + // fields returned for the claims above |
|
15 | + const PROFILE_CLAIM_VALUES = 'name family_name given_name middle_name nickname preferred_username profile picture website gender birthdate zoneinfo locale updated_at'; |
|
16 | + const EMAIL_CLAIM_VALUES = 'email email_verified'; |
|
17 | + const ADDRESS_CLAIM_VALUES = 'formatted street_address locality region postal_code country'; |
|
18 | + const PHONE_CLAIM_VALUES = 'phone_number phone_number_verified'; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Return claims about the provided user id. |
|
22 | - * |
|
23 | - * Groups of claims are returned based on the requested scopes. No group |
|
24 | - * is required, and no claim is required. |
|
25 | - * |
|
26 | - * @param $user_id |
|
27 | - * The id of the user for which claims should be returned. |
|
28 | - * @param $scope |
|
29 | - * The requested scope. |
|
30 | - * Scopes with matching claims: profile, email, address, phone. |
|
31 | - * |
|
32 | - * @return |
|
33 | - * An array in the claim => value format. |
|
34 | - * |
|
35 | - * @see http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims |
|
36 | - */ |
|
37 | - public function getUserClaims($user_id, $scope); |
|
20 | + /** |
|
21 | + * Return claims about the provided user id. |
|
22 | + * |
|
23 | + * Groups of claims are returned based on the requested scopes. No group |
|
24 | + * is required, and no claim is required. |
|
25 | + * |
|
26 | + * @param $user_id |
|
27 | + * The id of the user for which claims should be returned. |
|
28 | + * @param $scope |
|
29 | + * The requested scope. |
|
30 | + * Scopes with matching claims: profile, email, address, phone. |
|
31 | + * |
|
32 | + * @return |
|
33 | + * An array in the claim => value format. |
|
34 | + * |
|
35 | + * @see http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims |
|
36 | + */ |
|
37 | + public function getUserClaims($user_id, $scope); |
|
38 | 38 | } |
@@ -12,26 +12,26 @@ |
||
12 | 12 | */ |
13 | 13 | interface AuthorizationCodeInterface extends BaseAuthorizationCodeInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * Take the provided authorization code values and store them somewhere. |
|
17 | - * |
|
18 | - * This function should be the storage counterpart to getAuthCode(). |
|
19 | - * |
|
20 | - * If storage fails for some reason, we're not currently checking for |
|
21 | - * any sort of success/failure, so you should bail out of the script |
|
22 | - * and provide a descriptive fail message. |
|
23 | - * |
|
24 | - * Required for OAuth2::GRANT_TYPE_AUTH_CODE. |
|
25 | - * |
|
26 | - * @param $code authorization code to be stored. |
|
27 | - * @param $client_id client identifier to be stored. |
|
28 | - * @param $user_id user identifier to be stored. |
|
29 | - * @param string $redirect_uri redirect URI(s) to be stored in a space-separated string. |
|
30 | - * @param int $expires expiration to be stored as a Unix timestamp. |
|
31 | - * @param string $scope OPTIONAL scopes to be stored in space-separated string. |
|
32 | - * @param string $id_token OPTIONAL the OpenID Connect id_token. |
|
33 | - * |
|
34 | - * @ingroup oauth2_section_4 |
|
35 | - */ |
|
36 | - public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = null, $id_token = null); |
|
15 | + /** |
|
16 | + * Take the provided authorization code values and store them somewhere. |
|
17 | + * |
|
18 | + * This function should be the storage counterpart to getAuthCode(). |
|
19 | + * |
|
20 | + * If storage fails for some reason, we're not currently checking for |
|
21 | + * any sort of success/failure, so you should bail out of the script |
|
22 | + * and provide a descriptive fail message. |
|
23 | + * |
|
24 | + * Required for OAuth2::GRANT_TYPE_AUTH_CODE. |
|
25 | + * |
|
26 | + * @param $code authorization code to be stored. |
|
27 | + * @param $client_id client identifier to be stored. |
|
28 | + * @param $user_id user identifier to be stored. |
|
29 | + * @param string $redirect_uri redirect URI(s) to be stored in a space-separated string. |
|
30 | + * @param int $expires expiration to be stored as a Unix timestamp. |
|
31 | + * @param string $scope OPTIONAL scopes to be stored in space-separated string. |
|
32 | + * @param string $id_token OPTIONAL the OpenID Connect id_token. |
|
33 | + * |
|
34 | + * @ingroup oauth2_section_4 |
|
35 | + */ |
|
36 | + public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = null, $id_token = null); |
|
37 | 37 | } |
@@ -11,50 +11,50 @@ |
||
11 | 11 | */ |
12 | 12 | class AuthorizationCode extends BaseAuthorizationCode implements AuthorizationCodeInterface |
13 | 13 | { |
14 | - public function __construct(AuthorizationCodeStorageInterface $storage, array $config = array()) |
|
15 | - { |
|
16 | - parent::__construct($storage, $config); |
|
17 | - } |
|
18 | - |
|
19 | - public function getAuthorizeResponse($params, $user_id = null) |
|
20 | - { |
|
21 | - // build the URL to redirect to |
|
22 | - $result = array('query' => array()); |
|
23 | - |
|
24 | - $params += array('scope' => null, 'state' => null, 'id_token' => null); |
|
25 | - |
|
26 | - $result['query']['code'] = $this->createAuthorizationCode($params['client_id'], $user_id, $params['redirect_uri'], $params['scope'], $params['id_token']); |
|
27 | - |
|
28 | - if (isset($params['state'])) { |
|
29 | - $result['query']['state'] = $params['state']; |
|
30 | - } |
|
31 | - |
|
32 | - return array($params['redirect_uri'], $result); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Handle the creation of the authorization code. |
|
37 | - * |
|
38 | - * @param $client_id |
|
39 | - * Client identifier related to the authorization code |
|
40 | - * @param $user_id |
|
41 | - * User ID associated with the authorization code |
|
42 | - * @param $redirect_uri |
|
43 | - * An absolute URI to which the authorization server will redirect the |
|
44 | - * user-agent to when the end-user authorization step is completed. |
|
45 | - * @param $scope |
|
46 | - * (optional) Scopes to be stored in space-separated string. |
|
47 | - * @param $id_token |
|
48 | - * (optional) The OpenID Connect id_token. |
|
49 | - * |
|
50 | - * @see http://tools.ietf.org/html/rfc6749#section-4 |
|
51 | - * @ingroup oauth2_section_4 |
|
52 | - */ |
|
53 | - public function createAuthorizationCode($client_id, $user_id, $redirect_uri, $scope = null, $id_token = null) |
|
54 | - { |
|
55 | - $code = $this->generateAuthorizationCode(); |
|
56 | - $this->storage->setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, time() + $this->config['auth_code_lifetime'], $scope, $id_token); |
|
57 | - |
|
58 | - return $code; |
|
59 | - } |
|
14 | + public function __construct(AuthorizationCodeStorageInterface $storage, array $config = array()) |
|
15 | + { |
|
16 | + parent::__construct($storage, $config); |
|
17 | + } |
|
18 | + |
|
19 | + public function getAuthorizeResponse($params, $user_id = null) |
|
20 | + { |
|
21 | + // build the URL to redirect to |
|
22 | + $result = array('query' => array()); |
|
23 | + |
|
24 | + $params += array('scope' => null, 'state' => null, 'id_token' => null); |
|
25 | + |
|
26 | + $result['query']['code'] = $this->createAuthorizationCode($params['client_id'], $user_id, $params['redirect_uri'], $params['scope'], $params['id_token']); |
|
27 | + |
|
28 | + if (isset($params['state'])) { |
|
29 | + $result['query']['state'] = $params['state']; |
|
30 | + } |
|
31 | + |
|
32 | + return array($params['redirect_uri'], $result); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Handle the creation of the authorization code. |
|
37 | + * |
|
38 | + * @param $client_id |
|
39 | + * Client identifier related to the authorization code |
|
40 | + * @param $user_id |
|
41 | + * User ID associated with the authorization code |
|
42 | + * @param $redirect_uri |
|
43 | + * An absolute URI to which the authorization server will redirect the |
|
44 | + * user-agent to when the end-user authorization step is completed. |
|
45 | + * @param $scope |
|
46 | + * (optional) Scopes to be stored in space-separated string. |
|
47 | + * @param $id_token |
|
48 | + * (optional) The OpenID Connect id_token. |
|
49 | + * |
|
50 | + * @see http://tools.ietf.org/html/rfc6749#section-4 |
|
51 | + * @ingroup oauth2_section_4 |
|
52 | + */ |
|
53 | + public function createAuthorizationCode($client_id, $user_id, $redirect_uri, $scope = null, $id_token = null) |
|
54 | + { |
|
55 | + $code = $this->generateAuthorizationCode(); |
|
56 | + $this->storage->setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, time() + $this->config['auth_code_lifetime'], $scope, $id_token); |
|
57 | + |
|
58 | + return $code; |
|
59 | + } |
|
60 | 60 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | |
7 | 7 | interface IdTokenInterface extends ResponseTypeInterface |
8 | 8 | { |
9 | - /** |
|
10 | - * Create the id token. |
|
11 | - * |
|
12 | - * If Authorization Code Flow is used, the id_token is generated when the |
|
13 | - * authorization code is issued, and later returned from the token endpoint |
|
14 | - * together with the access_token. |
|
15 | - * If the Implicit Flow is used, the token and id_token are generated and |
|
16 | - * returned together. |
|
17 | - * |
|
18 | - * @param string $client_id The client id. |
|
19 | - * @param string $user_id The user id. |
|
20 | - * @param string $nonce OPTIONAL The nonce. |
|
21 | - * @param string $userClaims OPTIONAL Claims about the user. |
|
22 | - * @param string $access_token OPTIONAL The access token, if known. |
|
23 | - * |
|
24 | - * @return string The ID Token represented as a JSON Web Token (JWT). |
|
25 | - * |
|
26 | - * @see http://openid.net/specs/openid-connect-core-1_0.html#IDToken |
|
27 | - */ |
|
28 | - public function createIdToken($client_id, $userInfo, $nonce = null, $userClaims = null, $access_token = null); |
|
9 | + /** |
|
10 | + * Create the id token. |
|
11 | + * |
|
12 | + * If Authorization Code Flow is used, the id_token is generated when the |
|
13 | + * authorization code is issued, and later returned from the token endpoint |
|
14 | + * together with the access_token. |
|
15 | + * If the Implicit Flow is used, the token and id_token are generated and |
|
16 | + * returned together. |
|
17 | + * |
|
18 | + * @param string $client_id The client id. |
|
19 | + * @param string $user_id The user id. |
|
20 | + * @param string $nonce OPTIONAL The nonce. |
|
21 | + * @param string $userClaims OPTIONAL Claims about the user. |
|
22 | + * @param string $access_token OPTIONAL The access token, if known. |
|
23 | + * |
|
24 | + * @return string The ID Token represented as a JSON Web Token (JWT). |
|
25 | + * |
|
26 | + * @see http://openid.net/specs/openid-connect-core-1_0.html#IDToken |
|
27 | + */ |
|
28 | + public function createIdToken($client_id, $userInfo, $nonce = null, $userClaims = null, $access_token = null); |
|
29 | 29 | } |