@@ -297,7 +297,25 @@ public function session() {
297297 */
298298 public function token () {
299299 $ request = \Laminas \Diactoros \ServerRequestFactory::fromGlobals ($ _SERVER , $ _GET , $ _POST , $ _COOKIE , $ _FILES );
300- $ code = $ request ->getParsedBody ()['code ' ];
300+ $ grantType = $ request ->getParsedBody ()['grant_type ' ];
301+ switch ($ grantType ) {
302+ case "authorization_code " :
303+ $ code = $ request ->getParsedBody ()['code ' ];
304+ // FIXME: not sure if decoding this here is the way to go.
305+ // FIXME: because this is a public page, the nonce from the session is not available here.
306+ $ codeInfo = $ this ->tokenGenerator ->getCodeInfo ($ code );
307+ $ userId = $ codeInfo ['user_id ' ];
308+ break ;
309+ case "refresh_token " :
310+ $ refreshToken = $ request ->getParsedBody ()['refresh_token ' ];
311+ $ tokenInfo = $ this ->tokenGenerator ->getRefreshTokenInfo ($ refreshToken );
312+ $ userId = $ tokenInfo ['user_id ' ];
313+ break ;
314+ default :
315+ $ userId = false ;
316+ break ;
317+ }
318+
301319 $ clientId = $ request ->getParsedBody ()['client_id ' ];
302320
303321 $ httpDpop = $ request ->getServerParams ()['HTTP_DPOP ' ];
@@ -306,17 +324,16 @@ public function token() {
306324 $ server = new \Pdsinterop \Solid \Auth \Server ($ this ->authServerFactory , $ this ->authServerConfig , $ response );
307325 $ response = $ server ->respondToAccessTokenRequest ($ request );
308326
309- // FIXME: not sure if decoding this here is the way to go.
310- // FIXME: because this is a public page, the nonce from the session is not available here.
311- $ codeInfo = $ this ->tokenGenerator ->getCodeInfo ($ code );
312- $ response = $ this ->tokenGenerator ->addIdTokenToResponse (
313- $ response ,
314- $ clientId ,
315- $ codeInfo ['user_id ' ],
316- ($ _SESSION ['nonce ' ] ?? '' ),
317- $ this ->config ->getPrivateKey (),
318- $ httpDpop
319- );
327+ if ($ userId ) {
328+ $ response = $ this ->tokenGenerator ->addIdTokenToResponse (
329+ $ response ,
330+ $ clientId ,
331+ $ userId ,
332+ ($ _SESSION ['nonce ' ] ?? '' ),
333+ $ this ->config ->getPrivateKey (),
334+ $ httpDpop
335+ );
336+ }
320337
321338 return $ this ->respond ($ response ); // ->addHeader('Access-Control-Allow-Origin', '*');
322339 }
0 commit comments