@@ -105,7 +105,14 @@ private function getKeys() {
105105 }
106106
107107 private function createAuthServerConfig () {
108- $ clientId = isset ($ _GET ['client_id ' ]) ? $ _GET ['client_id ' ] : null ;
108+ $ clientId = null ;
109+ if (isset ($ _GET ['client_id ' ])) {
110+ $ clientId = $ _GET ['client_id ' ];
111+ } else if (isset ($ _POST ['client_id ' ])) {
112+ if (isset ($ _POST ['refresh_token ' ])) { // FIXME: Why does the test suite break without this?
113+ $ clientId = $ _POST ['client_id ' ];
114+ }
115+ }
109116 $ client = $ this ->getClient ($ clientId );
110117 $ keys = $ this ->getKeys ();
111118 try {
@@ -316,7 +323,25 @@ public function session() {
316323 */
317324 public function token () {
318325 $ request = \Laminas \Diactoros \ServerRequestFactory::fromGlobals ($ _SERVER , $ _GET , $ _POST , $ _COOKIE , $ _FILES );
319- $ code = $ request ->getParsedBody ()['code ' ];
326+ $ grantType = $ request ->getParsedBody ()['grant_type ' ];
327+ switch ($ grantType ) {
328+ case "authorization_code " :
329+ $ code = $ request ->getParsedBody ()['code ' ];
330+ // FIXME: not sure if decoding this here is the way to go.
331+ // FIXME: because this is a public page, the nonce from the session is not available here.
332+ $ codeInfo = $ this ->tokenGenerator ->getCodeInfo ($ code );
333+ $ userId = $ codeInfo ['user_id ' ];
334+ break ;
335+ case "refresh_token " :
336+ $ refreshToken = $ request ->getParsedBody ()['refresh_token ' ];
337+ $ tokenInfo = $ this ->tokenGenerator ->getCodeInfo ($ refreshToken ); // FIXME: getCodeInfo should be named 'decrypt' or 'getInfo'?
338+ $ userId = $ tokenInfo ['user_id ' ];
339+ break ;
340+ default :
341+ $ userId = false ;
342+ break ;
343+ }
344+
320345 $ clientId = $ request ->getParsedBody ()['client_id ' ];
321346
322347 $ httpDpop = $ request ->getServerParams ()['HTTP_DPOP ' ];
@@ -325,17 +350,16 @@ public function token() {
325350 $ server = new \Pdsinterop \Solid \Auth \Server ($ this ->authServerFactory , $ this ->authServerConfig , $ response );
326351 $ response = $ server ->respondToAccessTokenRequest ($ request );
327352
328- // FIXME: not sure if decoding this here is the way to go.
329- // FIXME: because this is a public page, the nonce from the session is not available here.
330- $ codeInfo = $ this ->tokenGenerator ->getCodeInfo ($ code );
331- $ response = $ this ->tokenGenerator ->addIdTokenToResponse (
332- $ response ,
333- $ clientId ,
334- $ codeInfo ['user_id ' ],
335- ($ _SESSION ['nonce ' ] ?? '' ),
336- $ this ->config ->getPrivateKey (),
337- $ httpDpop
338- );
353+ if ($ userId ) {
354+ $ response = $ this ->tokenGenerator ->addIdTokenToResponse (
355+ $ response ,
356+ $ clientId ,
357+ $ userId ,
358+ ($ _SESSION ['nonce ' ] ?? '' ),
359+ $ this ->config ->getPrivateKey (),
360+ $ httpDpop
361+ );
362+ }
339363
340364 return $ this ->respond ($ response ); // ->addHeader('Access-Control-Allow-Origin', '*');
341365 }
@@ -380,14 +404,7 @@ public function register() {
380404 $ clientData = $ this ->config ->saveClientRegistration ($ origin , $ clientData );
381405 $ registration = array (
382406 'client_id ' => $ clientData ['client_id ' ],
383- /*
384- FIXME: returning client_secret will trigger calls with basic auth to us. To get this to work, we need this patch:
385- // File /var/www/vhosts/solid-nextcloud/site/www/lib/base.php not changed so no update needed
386- // ($request->getRawPathInfo() !== '/apps/oauth2/api/v1/token') &&
387- // ($request->getRawPathInfo() !== '/apps/solid/token')
388- */
389- // 'client_secret' => $clientData['client_secret'], // FIXME: Returning this means we need to patch Nextcloud to accept tokens on calls to
390-
407+ 'client_secret ' => $ clientData ['client_secret ' ],
391408 'registration_client_uri ' => $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->linkToRoute ("solid.server.registeredClient " , array ("clientId " => $ clientData ['client_id ' ]))),
392409 'client_id_issued_at ' => $ clientData ['client_id_issued_at ' ],
393410 'redirect_uris ' => $ clientData ['redirect_uris ' ],
0 commit comments