Conditions | 17 |
Paths | 160 |
Total Lines | 67 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
62 | public function handle(ServerRequestInterface $request, ResourceOwnerInterface $resourceOwner, |
||
63 | RegisteredClient $client, ?array $scope = null, ?array $extendedResponseTypes = null): array |
||
64 | { |
||
65 | $data = $request->getMethod() === 'GET' ? $request->getQueryParams() : $request->getParsedBody(); |
||
66 | |||
67 | // Get required claims |
||
68 | $claims = [ |
||
69 | 'iss' => $this->configurationRepository->getConfig(Config::OPENID_ISSUER), |
||
70 | 'sub' => $resourceOwner->getIdentifier(), |
||
71 | 'aud' => $client->getIdentifier(), |
||
72 | 'exp' => time() + $this->idTokenStorage->getLifetime(), |
||
73 | 'iat' => time() |
||
74 | ]; |
||
75 | |||
76 | // todo, include if auth_time is marked as an essential claim by the client otherwise it is optional (conf ?) |
||
77 | if(isset($data['max_age']) && $data['max_age']) { |
||
78 | $claims['auth_time'] = $resourceOwner->getTimeWhenAuthenticationOccured(); |
||
79 | } |
||
80 | |||
81 | if(isset($data['nonce']) && !is_null($data['nonce'])) { |
||
82 | $claims['nonce'] = $data['nonce']; |
||
83 | } |
||
84 | |||
85 | if(empty($extendedResponseTypes)) { |
||
86 | $standardClaims = $this->userInfoClaimsStorage->getClaims($resourceOwner); |
||
87 | |||
88 | foreach ($this->userInfoClaimsStorage->getClaimsByScope($scope) as $claimRequested) { |
||
89 | if(isset($standardClaims[$claimRequested]) && $standardClaims[$claimRequested]) { |
||
90 | $claims[$claimRequested] = $standardClaims[$claimRequested]; |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | |||
95 | if(isset($extendedResponseTypes['code'])) { |
||
96 | //c_hash |
||
97 | /** |
||
98 | * @var \OAuth2OLD\ResponseTypes\ResponseTypeInterface $responseType |
||
99 | */ |
||
100 | $responseType = $extendedResponseTypes['code']; |
||
101 | $code = $responseType->handle($request, $resourceOwner, $client, $scope)['code']; |
||
102 | $result['code'] = $code; |
||
|
|||
103 | $claims['c_hash'] = 'todo'; //todo |
||
104 | } |
||
105 | |||
106 | if(isset($extendedResponseTypes['token'])) { |
||
107 | //at_hash |
||
108 | /** |
||
109 | * @var \OAuth2OLD\ResponseTypes\ResponseTypeInterface $responseType |
||
110 | */ |
||
111 | $responseType = $extendedResponseTypes['token']; |
||
112 | $token = $responseType->handle($request, $resourceOwner, $client, $scope)['token']; |
||
113 | $result['token'] = $token; |
||
114 | $claims['at_hash'] = 'todo'; //todo |
||
115 | } |
||
116 | else { |
||
117 | $requestedScopes = isset($data['scope']) ? explode(' ', $data['scope']) : []; |
||
118 | |||
119 | if ((empty($requestedScopes) && !is_null($scope)) || (is_array($scope) && !empty(array_diff($requestedScopes, $scope)))) { |
||
120 | $data['scope'] = implode(' ', $scope); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | |||
125 | // $idToken = new IdToken($claims); |
||
126 | $key = 'mykey'; // todo |
||
127 | $result['id_token'] = JWT::encode($claims, $key); |
||
128 | return $result; |
||
129 | } |
||
180 | } |