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