@@ -105,7 +105,13 @@ private function createAuthServerConfig() {
105105 * @NoCSRFRequired
106106 */
107107 public function cors ($ path ) {
108- return true ;
108+ $ origin = $ _SERVER ['HTTP_ORIGIN ' ];
109+ error_log ('Allowing in OPTIONS: ' . $ origin );
110+ return (new DataResponse ('OK ' ))
111+ ->addHeader ('Access-Control-Allow-Origin ' , $ origin )
112+ ->addHeader ('Access-Control-Allow-Headers ' , 'Content-Type, Authorization ' )
113+ ->addHeader ('Access-Control-Allow-Methods ' , 'POST ' )
114+ ->addHeader ('Access-Control-Allow-Credentials ' , 'true ' );
109115 }
110116
111117 /**
@@ -117,7 +123,7 @@ public function openid() {
117123 $ response = new \Laminas \Diactoros \Response ();
118124 $ server = new \Pdsinterop \Solid \Auth \Server ($ this ->authServerFactory , $ this ->authServerConfig , $ response );
119125 $ response = $ server ->respondToOpenIdMetadataRequest ();
120- return $ this ->respond ($ response );
126+ return $ this ->respond ($ response-> addHeader ( ' Access-Control-Allow-Origin ' , ' * ' ) );
121127 }
122128
123129 /**
@@ -129,7 +135,7 @@ public function authorize() {
129135 if (!$ this ->userManager ->userExists ($ this ->userId )) {
130136 $ result = new JSONResponse ('Authorization required ' );
131137 $ result ->setStatus (401 );
132- return $ result ;
138+ return $ result-> addHeader ( ' Access-Control-Allow-Origin ' , ' * ' ) ;
133139 }
134140
135141 $ parser = new \Lcobucci \JWT \Parser ();
@@ -154,7 +160,7 @@ public function authorize() {
154160 } catch (\Exception $ e ) {
155161 $ result = new JSONResponse ('Bad request, missing redirect uri ' );
156162 $ result ->setStatus (400 );
157- return $ result ;
163+ return $ result-> addHeader ( ' Access-Control-Allow-Origin ' , ' * ' ) ;
158164 }
159165 }
160166 $ clientId = $ getVars ['client_id ' ];
@@ -164,7 +170,7 @@ public function authorize() {
164170 $ result ->setStatus (302 );
165171 $ approvalUrl = $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->linkToRoute ("solid.page.approval " , array ("clientId " => $ clientId , "returnUrl " => $ _SERVER ['REQUEST_URI ' ])));
166172 $ result ->addHeader ("Location " , $ approvalUrl );
167- return $ result ;
173+ return $ result-> addHeader ( ' Access-Control-Allow-Origin ' , ' * ' ) ;
168174 }
169175
170176 $ user = new \Pdsinterop \Solid \Auth \Entity \User ();
@@ -177,7 +183,7 @@ public function authorize() {
177183 $ response = $ server ->respondToAuthorizationRequest ($ request , $ user , $ approval );
178184 $ response = $ this ->tokenGenerator ->addIdTokenToResponse ($ response , $ clientId , $ this ->getProfilePage (), $ this ->session ->get ("nonce " ), $ this ->config ->getPrivateKey ());
179185
180- return $ this ->respond ($ response );
186+ return $ this ->respond ($ response )-> addHeader ( ' Access-Control-Allow-Origin ' , ' * ' ) ;
181187 }
182188
183189 private function checkApproval ($ clientId ) {
@@ -250,7 +256,7 @@ public function token() {
250256 $ codeInfo = $ this ->tokenGenerator ->getCodeInfo ($ code );
251257 $ response = $ this ->tokenGenerator ->addIdTokenToResponse ($ response , $ clientId , $ codeInfo ['user_id ' ], $ _SESSION ['nonce ' ], $ this ->config ->getPrivateKey (), $ dpopKey );
252258
253- return $ this ->respond ($ response );
259+ return $ this ->respond ($ response )-> addHeader ( ' Access-Control-Allow-Origin ' , ' * ' ) ;
254260 }
255261
256262 /**
@@ -271,7 +277,7 @@ public function logout() {
271277 $ this ->userService ->logout ();
272278 return new JSONResponse ("ok " );
273279 }
274-
280+
275281 /**
276282 * @PublicPage
277283 * @NoAdminRequired
@@ -285,7 +291,7 @@ public function register() {
285291 }
286292 $ clientData ['client_id_issued_at ' ] = time ();
287293 $ parsedOrigin = parse_url ($ clientData ['redirect_uris ' ][0 ]);
288- $ origin = $ parsedOrigin ['host ' ];
294+ $ origin = ' https:// ' . $ parsedOrigin ['host ' ];
289295
290296 $ clientId = $ this ->config ->saveClientRegistration ($ origin , $ clientData );
291297 $ registration = array (
@@ -294,10 +300,11 @@ public function register() {
294300 'client_id_issued_at ' => $ clientData ['client_id_issued_at ' ],
295301 'redirect_uris ' => $ clientData ['redirect_uris ' ],
296302 );
297-
303+ error_log ( ' allowingin POST: ' . $ origin );
298304 $ registration = $ this ->tokenGenerator ->respondToRegistration ($ registration , $ this ->config ->getPrivateKey ());
299-
300- return new JSONResponse ($ registration );
305+ return (new JSONResponse ($ registration ))
306+ ->addHeader ('Access-Control-Allow-Origin ' , $ origin )
307+ ->addHeader ('Access-Control-Allow-Methods ' , 'POST ' );
301308 }
302309
303310 /**
@@ -348,6 +355,7 @@ private function respond($response) {
348355 }
349356 }
350357 $ result ->setStatus ($ statusCode );
358+ $ result ->addHeader ('Access-Control-Allow-Origin ' , '* ' );
351359 return $ result ;
352360 }
353361
0 commit comments