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\external\user\Oauth2UserInterface; |
13
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2AccessTokenInterface; |
14
|
|
|
use rhertogh\Yii2Oauth2Server\Oauth2Module; |
15
|
|
|
use Yii; |
16
|
|
|
use yii\base\InvalidArgumentException; |
17
|
|
|
use yii\base\InvalidConfigException; |
18
|
|
|
|
19
|
|
|
class Oauth2OidcBearerTokenResponse extends BearerTokenResponse implements Oauth2OidcBearerTokenResponseInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Oauth2Module |
23
|
|
|
*/ |
24
|
|
|
protected $_module; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
*/ |
29
|
7 |
|
public function __construct(Oauth2Module $module) |
30
|
|
|
{ |
31
|
7 |
|
$this->_module = $module; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritDoc |
36
|
|
|
*/ |
37
|
3 |
|
public function getModule() |
38
|
|
|
{ |
39
|
3 |
|
return $this->_module; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritDoc |
44
|
|
|
* @param Oauth2AccessTokenInterface $accessToken |
45
|
|
|
* @return array |
46
|
|
|
* @throws InvalidConfigException |
47
|
|
|
*/ |
48
|
3 |
|
protected function getExtraParams(AccessTokenEntityInterface $accessToken) |
49
|
|
|
{ |
50
|
3 |
|
$scopeIdentifiers = array_map(fn($scope) => $scope->getIdentifier(), $accessToken->getScopes()); |
51
|
|
|
|
52
|
|
|
// Not a OpenId Connect request if OpenId scope is not present. |
53
|
3 |
|
if (!in_array(Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_OPENID, $scopeIdentifiers)) { |
54
|
1 |
|
return []; |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
$module = $this->getModule(); |
58
|
|
|
|
59
|
2 |
|
$user = $module->getUserRepository()->getUserEntityByIdentifier($accessToken->getUserIdentifier()); |
60
|
2 |
|
if ($user === null) { |
61
|
1 |
|
throw new InvalidArgumentException( |
62
|
1 |
|
'No user with identifier "' . $accessToken->getUserIdentifier() . '" found.' |
63
|
|
|
); |
64
|
|
|
} |
65
|
1 |
|
if (!($user instanceof Oauth2OidcUserInterface)) { |
66
|
|
|
throw new InvalidConfigException( |
67
|
|
|
get_class($user) . ' must implement ' . Oauth2OidcUserInterface::class |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
$nonce = Yii::$app->request->post(Oauth2OidcAuthenticationRequestInterface::REQUEST_PARAMETER_NONCE); |
72
|
|
|
|
73
|
1 |
|
$token = $module->generateOpenIdConnectUserClaimsToken( |
74
|
|
|
$user, |
75
|
1 |
|
$accessToken->getClient()->getIdentifier(), |
76
|
1 |
|
$this->privateKey, |
77
|
|
|
$scopeIdentifiers, |
|
|
|
|
78
|
|
|
$nonce, |
|
|
|
|
79
|
1 |
|
$accessToken->getExpiryDateTime() |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
return [ |
83
|
1 |
|
static::TOKEN_RESPONSE_ID_TOKEN => $token->toString() |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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