1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\components\openidconnect\server; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; |
6
|
|
|
use League\OAuth2\Server\ResponseTypes\BearerTokenResponse; |
7
|
|
|
use rhertogh\Yii2Oauth2Server\helpers\OpenIdConnectHelper; |
|
|
|
|
8
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\request\Oauth2OidcAuthenticationRequestInterface; |
9
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\scope\Oauth2OidcScopeInterface; |
10
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\server\Oauth2OidcBearerTokenResponseInterface; |
11
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\models\external\user\Oauth2OidcUserInterface; |
12
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2AccessTokenInterface; |
13
|
|
|
use rhertogh\Yii2Oauth2Server\Oauth2Module; |
14
|
|
|
use Yii; |
15
|
|
|
use yii\base\InvalidArgumentException; |
16
|
|
|
use yii\base\InvalidConfigException; |
17
|
|
|
|
18
|
|
|
class Oauth2OidcBearerTokenResponse extends BearerTokenResponse implements Oauth2OidcBearerTokenResponseInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var Oauth2Module |
22
|
|
|
*/ |
23
|
|
|
protected $_module; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritDoc |
27
|
|
|
*/ |
28
|
7 |
|
public function __construct(Oauth2Module $module) |
29
|
|
|
{ |
30
|
7 |
|
$this->_module = $module; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritDoc |
35
|
|
|
*/ |
36
|
3 |
|
public function getModule() |
37
|
|
|
{ |
38
|
3 |
|
return $this->_module; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritDoc |
43
|
|
|
* @param Oauth2AccessTokenInterface $accessToken |
44
|
|
|
* @return array |
45
|
|
|
* @throws InvalidConfigException |
46
|
|
|
*/ |
47
|
3 |
|
protected function getExtraParams(AccessTokenEntityInterface $accessToken) |
48
|
|
|
{ |
49
|
3 |
|
$scopeIdentifiers = array_map(fn($scope) => $scope->getIdentifier(), $accessToken->getScopes()); |
50
|
|
|
|
51
|
|
|
// Not a OpenId Connect request if OpenId scope is not present. |
52
|
3 |
|
if (!in_array(Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_OPENID, $scopeIdentifiers)) { |
53
|
1 |
|
return []; |
54
|
|
|
} |
55
|
|
|
|
56
|
2 |
|
$module = $this->getModule(); |
57
|
|
|
|
58
|
2 |
|
$user = $module->getUserRepository()->getUserEntityByIdentifier($accessToken->getUserIdentifier()); |
59
|
2 |
|
if ($user === null) { |
60
|
1 |
|
throw new InvalidArgumentException( |
61
|
1 |
|
'No user with identifier "' . $accessToken->getUserIdentifier() . '" found.' |
62
|
1 |
|
); |
63
|
|
|
} |
64
|
1 |
|
if (!($user instanceof Oauth2OidcUserInterface)) { |
65
|
|
|
throw new InvalidConfigException( |
66
|
|
|
get_class($user) . ' must implement ' . Oauth2OidcUserInterface::class |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
$nonce = Yii::$app->request->post(Oauth2OidcAuthenticationRequestInterface::REQUEST_PARAMETER_NONCE); |
71
|
|
|
|
72
|
1 |
|
$token = $module->generateOpenIdConnectUserClaimsToken( |
73
|
1 |
|
$user, |
74
|
1 |
|
$accessToken->getClient()->getIdentifier(), |
75
|
1 |
|
$this->privateKey, |
76
|
1 |
|
$scopeIdentifiers, |
|
|
|
|
77
|
1 |
|
$nonce, |
|
|
|
|
78
|
1 |
|
$accessToken->getExpiryDateTime() |
79
|
1 |
|
); |
80
|
|
|
|
81
|
1 |
|
return [ |
82
|
1 |
|
static::TOKEN_RESPONSE_ID_TOKEN => $token->toString() |
83
|
1 |
|
]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths