1414
1515class TokenGenerator
1616{
17- use CryptTrait;
1817 ////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
1918
19+ use CryptTrait;
20+
2021 /** @var Config */
2122 public $ config ;
2223
@@ -28,7 +29,7 @@ final public function __construct(
2829 $ this ->config = $ config ;
2930 $ this ->setEncryptionKey ($ this ->config ->getKeys ()->getEncryptionKey ());
3031 }
31-
32+
3233 public function generateRegistrationAccessToken ($ clientId , $ privateKey ) {
3334 $ issuer = $ this ->config ->getServer ()->get (OidcMeta::ISSUER );
3435
@@ -42,7 +43,7 @@ public function generateRegistrationAccessToken($clientId, $privateKey) {
4243
4344 return $ token ->toString ();
4445 }
45-
46+
4647 public function generateIdToken ($ accessToken , $ clientId , $ subject , $ nonce , $ privateKey , $ dpopKey =null ) {
4748 $ issuer = $ this ->config ->getServer ()->get (OidcMeta::ISSUER );
4849
@@ -75,7 +76,7 @@ public function generateIdToken($accessToken, $clientId, $subject, $nonce, $priv
7576 ->getToken ($ jwtConfig ->signer (), $ jwtConfig ->signingKey ());
7677 return $ token ->toString ();
7778 }
78-
79+
7980 public function respondToRegistration ($ registration , $ privateKey ) {
8081 /*
8182 Expects in $registration:
@@ -94,10 +95,10 @@ public function respondToRegistration($registration, $privateKey) {
9495 'token_endpoint_auth_method ' => 'client_secret_basic ' ,
9596 'registration_access_token ' => $ registration_access_token ,
9697 );
97-
98+
9899 return array_merge ($ registrationBase , $ registration );
99100 }
100-
101+
101102 public function addIdTokenToResponse ($ response , $ clientId , $ subject , $ nonce , $ privateKey , $ dpopKey =null ) {
102103 if ($ response ->hasHeader ("Location " )) {
103104 $ value = $ response ->getHeaderLine ("Location " );
@@ -111,7 +112,7 @@ public function addIdTokenToResponse($response, $clientId, $subject, $nonce, $pr
111112 $ privateKey ,
112113 $ dpopKey
113114 );
114- $ value = preg_replace ("/#access_token=(.*?)&/ " , "#access_token= \$1&id_token= $ idToken& " , $ value );
115+ $ value = preg_replace ("/#access_token=(.*?)&/ " , "#access_token= \$1&id_token= $ idToken& " , $ value );
115116 $ response = $ response ->withHeader ("Location " , $ value );
116117 } else if (preg_match ("/code=(.*?)&/ " , $ value , $ matches )) {
117118 $ idToken = $ this ->generateIdToken (
@@ -153,12 +154,13 @@ public function addIdTokenToResponse($response, $clientId, $subject, $nonce, $pr
153154 public function getCodeInfo ($ code ) {
154155 return json_decode ($ this ->decrypt ($ code ), true );
155156 }
157+
156158 ///////////////////////////// HELPER FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
157159
158160 private function generateJti () {
159161 return substr (md5 ((string )time ()), 12 ); // FIXME: generate unique jti values
160162 }
161-
163+
162164 private function generateTokenHash ($ accessToken ) {
163165 $ atHash = hash ('sha256 ' , $ accessToken );
164166 $ atHash = substr ($ atHash , 0 , 32 );
0 commit comments