| Conditions | 8 |
| Paths | 12 |
| Total Lines | 68 |
| 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 |
||
| 44 | public function issueIdToken(RegisteredClient $client, |
||
| 45 | string $resourceOwnerIdentifier, |
||
| 46 | array $additionalClaims = []): string |
||
| 47 | { |
||
| 48 | $metadata = $client->getMetadata(); |
||
| 49 | |||
| 50 | $idToken = array_merge([ |
||
| 51 | 'iss' => $this->config->getIssuerIdentifier(), |
||
| 52 | 'sub' => $resourceOwnerIdentifier, |
||
| 53 | 'aud' => $client->getIdentifier(), |
||
| 54 | 'exp' => time() + $this->config->getIdTokenLifetime(), |
||
| 55 | 'iat' => time() |
||
| 56 | ], $additionalClaims); |
||
| 57 | |||
| 58 | $alg = 'RS256'; |
||
| 59 | if ($metadata instanceof ClientMetadataInterface) { |
||
| 60 | $alg = $metadata->getIdTokenSignedResponseAlg() ?: 'RS256'; |
||
| 61 | } |
||
| 62 | |||
| 63 | $keys=[]; |
||
| 64 | $jwks = $metadata->getJwks(); |
||
| 65 | |||
| 66 | if (!empty($jwks)) { |
||
| 67 | $jwks = JWKFactory::createFromValues($jwks); |
||
| 68 | if ($jwks instanceof JWKSet) { |
||
| 69 | foreach ($jwks->all() as $key) { |
||
| 70 | $keys[] = $key; |
||
| 71 | } |
||
| 72 | } else { |
||
| 73 | $keys[] = $jwks; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | $jwku = $metadata->getJwksUri(); |
||
| 78 | if (!is_null($jwku)) { |
||
| 79 | foreach (JWKFactory::createFromJKU($jwku) as $key) { |
||
| 80 | $keys[] = $key; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | $jwkSet = new JWKSet($keys); |
||
| 84 | |||
| 85 | $key = $jwkSet->selectKey('sig', $alg); |
||
| 86 | |||
| 87 | |||
| 88 | //var_dump($idToken);die; |
||
| 89 | $jws = JWSFactory::createJWS($idToken); |
||
| 90 | $jws = $jws->addSignatureInformation($key, |
||
| 91 | [ |
||
| 92 | 'alg' => $alg, |
||
| 93 | 'kid' => $key->get('kid') |
||
| 94 | ] |
||
| 95 | ); |
||
| 96 | $signer = Signer::createSigner([$alg]); |
||
| 97 | |||
| 98 | // Then we sign |
||
| 99 | $signer->sign($jws); |
||
| 100 | |||
| 101 | // var_dump($jws->toCompactJSON(0));die; |
||
| 102 | // echo '<pre>'; |
||
| 103 | // print_r($jws->getClaims()); |
||
| 104 | // print_r($jws->toCompactJSON(0)); |
||
| 105 | // echo '</pre>';die; |
||
| 106 | |||
| 107 | // var_dump($jws->toJSON()); |
||
| 108 | // die; |
||
| 109 | // $idToken = JWT::encode($idToken, $key, $alg); |
||
| 110 | |||
| 111 | return $jws->toCompactJSON(0); |
||
| 112 | } |
||
| 144 | } |