| Conditions | 7 |
| Paths | 9 |
| Total Lines | 74 |
| Code Lines | 25 |
| 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 |
||
| 131 | public function getAccessToken($grant, array $options = []) |
||
| 132 | { |
||
| 133 | /** @var Token $token */ |
||
| 134 | $accessToken = parent::getAccessToken($grant, $options); |
||
| 135 | |||
| 136 | if (null === $accessToken) { |
||
| 137 | throw new InvalidTokenException('Invalid access token.'); |
||
| 138 | } |
||
| 139 | |||
| 140 | $token = $accessToken->getIdToken(); |
||
|
|
|||
| 141 | |||
| 142 | // id_token is empty. |
||
| 143 | if (null === $token) { |
||
| 144 | throw new InvalidTokenException('Expected an id_token but did not receive one from the authorization server.'); |
||
| 145 | } |
||
| 146 | |||
| 147 | // If the ID Token is received via direct communication between the Client and the Token Endpoint |
||
| 148 | // (which it is in this flow), the TLS server validation MAY be used to validate the issuer in place of checking |
||
| 149 | // the token signature. The Client MUST validate the signature of all other ID Tokens according to JWS [JWS] |
||
| 150 | // using the algorithm specified in the JWT alg Header Parameter. The Client MUST use the keys provided by |
||
| 151 | // the Issuer. |
||
| 152 | // |
||
| 153 | // The alg value SHOULD be the default of RS256 or the algorithm sent by the Client in the |
||
| 154 | // id_token_signed_response_alg parameter during Registration. |
||
| 155 | if (false === $token->verify($this->signer, $this->getPublicKey())) { |
||
| 156 | throw new InvalidTokenException('Received an invalid id_token from authorization server.'); |
||
| 157 | } |
||
| 158 | |||
| 159 | // validations |
||
| 160 | // @see http://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation |
||
| 161 | // validate the iss (issuer) |
||
| 162 | // - The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery) |
||
| 163 | // MUST exactly match the value of the iss (issuer) Claim. |
||
| 164 | // validate the aud |
||
| 165 | // - The Client MUST validate that the aud (audience) Claim contains its client_id value registered at the Issuer |
||
| 166 | // identified by the iss (issuer) Claim as an audience. The aud (audience) Claim MAY contain an array with more |
||
| 167 | // than one element. The ID Token MUST be rejected if the ID Token does not list the Client as a valid audience, |
||
| 168 | // or if it contains additional audiences not trusted by the Client. |
||
| 169 | // - If a nonce value was sent in the Authentication Request, a nonce Claim MUST be present and its value checked |
||
| 170 | // to verify that it is the same value as the one that was sent in the Authentication Request. The Client SHOULD |
||
| 171 | // check the nonce value for replay attacks. The precise method for detecting replay attacks is Client specific. |
||
| 172 | // - If the auth_time Claim was requested, either through a specific request for this Claim or by using |
||
| 173 | // the max_age parameter, the Client SHOULD check the auth_time Claim value and request re-authentication if it |
||
| 174 | // determines too much time has elapsed since the last End-User authentication. |
||
| 175 | // TODO |
||
| 176 | // If the acr Claim was requested, the Client SHOULD check that the asserted Claim Value is appropriate. |
||
| 177 | // The meaning and processing of acr Claim Values is out of scope for this specification. |
||
| 178 | $currentTime = time(); |
||
| 179 | $data = [ |
||
| 180 | 'iss' => $this->getIdTokenIssuer(), |
||
| 181 | 'exp' => $currentTime, |
||
| 182 | 'auth_time' => $currentTime, |
||
| 183 | 'iat' => $currentTime, |
||
| 184 | 'nbf' => $currentTime, |
||
| 185 | 'aud' => $this->clientId, |
||
| 186 | ]; |
||
| 187 | |||
| 188 | // If the ID Token contains multiple audiences, the Client SHOULD verify that an azp Claim is present. |
||
| 189 | // If an azp (authorized party) Claim is present, the Client SHOULD verify that its client_id is the Claim Value. |
||
| 190 | if ($token->hasClaim('azp')) { |
||
| 191 | $data['azp'] = $this->clientId; |
||
| 192 | } |
||
| 193 | |||
| 194 | if (false === $this->validatorChain->validate($data, $token)) { |
||
| 195 | throw new InvalidTokenException('The id_token did not pass validation.'); |
||
| 196 | } |
||
| 197 | |||
| 198 | if ($this->useSession) { |
||
| 199 | $_SESSION['access_token'] = $accessToken->getToken(); |
||
| 200 | $_SESSION['refresh_token'] = $accessToken->getRefreshToken(); |
||
| 201 | $_SESSION['id_token'] = $accessToken->getIdTokenHint(); |
||
| 202 | } |
||
| 203 | |||
| 204 | return $accessToken; |
||
| 205 | } |
||
| 309 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.