@@ -162,6 +162,7 @@ public function authorize() {
162162 }
163163 $ clientId = $ _GET ['client_id ' ];
164164
165+ $ getVars = $ _GET ;
165166 if (isset ($ _GET ['request ' ])) {
166167 $ jwtConfig = Configuration::forSymmetricSigner (new Sha256 (), InMemory::plainText ($ this ->config ->getPrivateKey ()));
167168 try {
@@ -170,51 +171,51 @@ public function authorize() {
170171 } catch (\Exception $ e ) {
171172 $ this ->session ->set ("nonce " , $ _GET ['nonce ' ]);
172173 }
173- }
174174
175- $ getVars = $ _GET ;
176- if (!isset ($ getVars ['grant_type ' ])) {
177- $ getVars ['grant_type ' ] = 'implicit ' ;
178- }
179- $ getVars ['response_type ' ] = $ this ->getResponseType ();
180- $ getVars ['scope ' ] = "openid " ;
181-
182- if (!isset ($ getVars ['redirect_uri ' ])) {
183- if (!isset ($ token )) {
184- $ result = new JSONResponse ('Bad request, does not contain valid token ' );
185- $ result ->setStatus (400 );
186- return $ result ;
187- // return $result->addHeader('Access-Control-Allow-Origin', '*');
175+ if (!isset ($ getVars ['grant_type ' ])) {
176+ $ getVars ['grant_type ' ] = 'implicit ' ;
188177 }
189- try {
190- $ getVars ['redirect_uri ' ] = $ token ->claims ()->get ("redirect_uri " );
191- } catch (\Exception $ e ) {
192- $ result = new JSONResponse ('Bad request, missing redirect uri ' );
193- $ result ->setStatus (400 );
194- return $ result ;
195- // return $result->addHeader('Access-Control-Allow-Origin', '*');
178+ $ getVars ['response_type ' ] = $ this ->getResponseType ();
179+ $ getVars ['scope ' ] = "openid " ;
180+
181+ if (!isset ($ getVars ['redirect_uri ' ])) {
182+ if (!isset ($ token )) {
183+ return new JSONResponse ('Bad request, does not contain valid token ' , 400 );
184+ }
185+
186+ try {
187+ $ getVars ['redirect_uri ' ] = $ token ->claims ()->get ("redirect_uri " );
188+ } catch (\Exception $ e ) {
189+ return new JSONResponse ('Bad request, missing redirect uri ' , 400 );
190+ }
196191 }
197192 }
198193
199- if (preg_match ("/^http(s)?:/ " , $ getVars ['client_id ' ])) {
194+ $ request = \Laminas \Diactoros \ServerRequestFactory::fromGlobals ($ _SERVER , $ getVars , $ _POST , $ _COOKIE , $ _FILES );
195+ $ response = new \Laminas \Diactoros \Response ();
196+ $ authServer = new \Pdsinterop \Solid \Auth \Server ($ this ->authServerFactory , $ this ->authServerConfig , $ response );
197+
198+ // @FIXME: Check OIDC Spec for rules regarding Client updates
199+ if (preg_match ("/^http(s)?:/ " , $ clientId )) {
200200 $ parsedOrigin = parse_url ($ getVars ['redirect_uri ' ]);
201201 $ origin = $ parsedOrigin ['scheme ' ] . ':// ' . $ parsedOrigin ['host ' ];
202202 if (isset ($ parsedOrigin ['port ' ])) {
203203 $ origin .= ": " . $ parsedOrigin ['port ' ];
204204 }
205205 $ clientData = array (
206206 "client_id_issued_at " => time (),
207- "client_name " => $ getVars [ ' client_id ' ] ,
207+ "client_name " => $ clientId ,
208208 "origin " => $ origin ,
209209 "redirect_uris " => array (
210210 $ getVars ['redirect_uri ' ]
211211 )
212212 );
213- $ clientId = $ this ->config ->saveClientRegistration ($ origin , $ clientData )['client_id ' ];
214- $ clientId = $ this ->config ->saveClientRegistration ($ getVars ['client_id ' ], $ clientData )['client_id ' ];
213+
214+ $ this ->config ->saveClientRegistration ($ origin , $ clientData );
215+ $ clientId = $ this ->config ->saveClientRegistration ($ clientId , $ clientData )['client_id ' ];
216+
215217 $ returnUrl = $ getVars ['redirect_uri ' ];
216218 } else {
217- $ clientId = $ getVars ['client_id ' ];
218219 $ returnUrl = $ _SERVER ['REQUEST_URI ' ];
219220 }
220221
@@ -231,7 +232,8 @@ public function authorize() {
231232 $ result ->setStatus (302 );
232233 $ approvalUrl = $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->linkToRoute ("solid.page.approval " , array ("clientId " => $ clientId , "returnUrl " => $ returnUrl )));
233234 $ result ->addHeader ("Location " , $ approvalUrl );
234- return $ result ; // ->addHeader('Access-Control-Allow-Origin', '*');
235+
236+ return $ result ;
235237 }
236238
237239 if (isset ($ getVars ['redirect_uri ' ])) {
@@ -266,23 +268,21 @@ public function authorize() {
266268 return $ result ;
267269 }
268270
271+ $ webId = $ this ->getProfilePage ();
269272 $ user = new \Pdsinterop \Solid \Auth \Entity \User ();
270- $ user ->setIdentifier ($ this -> getProfilePage () );
273+ $ user ->setIdentifier ($ webId );
271274
272- $ request = \Laminas \Diactoros \ServerRequestFactory::fromGlobals ($ _SERVER , $ getVars , $ _POST , $ _COOKIE , $ _FILES );
273- $ response = new \Laminas \Diactoros \Response ();
274- $ server = new \Pdsinterop \Solid \Auth \Server ($ this ->authServerFactory , $ this ->authServerConfig , $ response );
275+ $ response = $ authServer ->respondToAuthorizationRequest ($ request , $ user , $ approval );
275276
276- $ response = $ server ->respondToAuthorizationRequest ($ request , $ user , $ approval );
277277 $ response = $ this ->tokenGenerator ->addIdTokenToResponse (
278278 $ response ,
279279 $ clientId ,
280- $ this -> getProfilePage () ,
280+ $ webId ,
281281 $ this ->session ->get ("nonce " ),
282282 $ this ->config ->getPrivateKey ()
283283 );
284284
285- return $ this ->respond ($ response ); // ->addHeader('Access-Control-Allow-Origin', '*');
285+ return $ this ->respond ($ response );
286286 }
287287
288288 private function checkApproval ($ clientId ) {
0 commit comments