blob: ee113a0e57f0aff78c55624fa403ba6a5e680e1b [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2
3namespace OAuth2\OpenID\GrantType;
4
5use OAuth2\GrantType\AuthorizationCode as BaseAuthorizationCode;
6use OAuth2\ResponseType\AccessTokenInterface;
7
8/**
9 * @author Brent Shaffer <bshafs at gmail dot com>
10 */
11class AuthorizationCode extends BaseAuthorizationCode
12{
13 /**
14 * Create access token
15 *
16 * @param AccessTokenInterface $accessToken
17 * @param mixed $client_id - client identifier related to the access token.
18 * @param mixed $user_id - user id associated with the access token
19 * @param string $scope - scopes to be stored in space-separated string.
20 * @return array
21 */
22 public function createAccessToken(AccessTokenInterface $accessToken, $client_id, $user_id, $scope)
23 {
24 $includeRefreshToken = true;
25 if (isset($this->authCode['id_token'])) {
26 // OpenID Connect requests include the refresh token only if the
27 // offline_access scope has been requested and granted.
28 $scopes = explode(' ', trim($scope));
29 $includeRefreshToken = in_array('offline_access', $scopes);
30 }
31
32 $token = $accessToken->createAccessToken($client_id, $user_id, $scope, $includeRefreshToken);
33 if (isset($this->authCode['id_token'])) {
34 $token['id_token'] = $this->authCode['id_token'];
35 }
36
37 $this->storage->expireAuthorizationCode($this->authCode['code']);
38
39 return $token;
40 }
41}