@@ -180,108 +180,4 @@ public static function respondToLogin() {
180180 header ("Location: /login/ " );
181181 }
182182 }
183-
184- public static function respondToRegister () {
185- $ postData = file_get_contents ("php://input " );
186- $ clientData = json_decode ($ postData , true );
187- if (!isset ($ clientData )) {
188- header ("HTTP/1.1 400 Bad request " );
189- return ;
190- }
191- $ parsedOrigin = parse_url ($ clientData ['redirect_uris ' ][0 ]);
192- $ origin = $ parsedOrigin ['scheme ' ] . ':// ' . $ parsedOrigin ['host ' ];
193- if (isset ($ parsedOrigin ['port ' ])) {
194- $ origin .= ": " . $ parsedOrigin ['port ' ];
195- }
196-
197-
198- $ generatedClientId = md5 (random_bytes (32 ));
199- $ generatedClientSecret = md5 (random_bytes (32 ));
200-
201- $ clientData ['client_id_issued_at ' ] = time ();
202- $ clientData ['client_id ' ] = $ generatedClientId ;
203- $ clientData ['client_secret ' ] = $ generatedClientSecret ;
204- $ clientData ['origin ' ] = $ origin ;
205- ClientRegistration::saveClientRegistration ($ clientData );
206-
207- $ client = ClientRegistration::getRegistration ($ generatedClientId );
208-
209- $ responseData = array (
210- 'redirect_uris ' => $ client ['redirect_uris ' ],
211- 'client_id ' => $ client ['client_id ' ],
212- 'client_secret ' => $ client ['client_secret ' ],
213- 'response_types ' => array ('code ' ),
214- 'grant_types ' => array ('authorization_code ' , 'refresh_token ' ),
215- 'application_type ' => $ client ['application_type ' ] ?? 'web ' ,
216- 'client_name ' => $ client ['client_name ' ] ?? $ client ['client_id ' ],
217- 'id_token_signed_response_alg ' => 'RS256 ' ,
218- 'token_endpoint_auth_method ' => 'client_secret_basic ' ,
219- 'client_id_issued_at ' => $ client ['client_id_issued_at ' ],
220- 'client_secret_expires_at ' => 0
221- );
222- header ("HTTP/1.1 201 Created " );
223- header ("Content-type: application/json " );
224- echo json_encode ($ responseData , JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR );
225- }
226-
227- public static function respondToSharing () {
228- $ user = User::getUser (Session::getLoggedInUser ());
229- $ clientId = $ _POST ['client_id ' ];
230- $ userId = $ user ['userId ' ];
231- if ($ _POST ['consent ' ] === 'true ' ) {
232- User::allowClientForUser ($ clientId , $ userId );
233- }
234- $ returnUrl = urldecode ($ _POST ['returnUrl ' ]);
235- header ("Location: $ returnUrl " );
236- }
237-
238- public static function respondToToken () {
239- $ authServer = Server::getAuthServer ();
240- $ tokenGenerator = Server::getTokenGenerator ();
241-
242- $ requestFactory = new \Laminas \Diactoros \ServerRequestFactory ();
243- $ request = $ requestFactory ->fromGlobals ($ _SERVER , $ _GET , $ _POST , $ _COOKIE , $ _FILES );
244- $ requestBody = $ request ->getParsedBody ();
245-
246- $ grantType = $ requestBody ['grant_type ' ] ?? null ;
247- $ clientId = $ requestBody ['client_id ' ] ?? null ;
248- switch ($ grantType ) {
249- case "authorization_code " :
250- $ code = $ requestBody ['code ' ];
251- $ codeInfo = $ tokenGenerator ->getCodeInfo ($ code );
252- $ userId = $ codeInfo ['user_id ' ];
253- if (!$ clientId ) {
254- $ clientId = $ codeInfo ['client_id ' ];
255- }
256- break ;
257- case "refresh_token " :
258- $ refreshToken = $ requestBody ['refresh_token ' ];
259- $ tokenInfo = $ tokenGenerator ->getCodeInfo ($ refreshToken ); // FIXME: getCodeInfo should be named 'decrypt' or 'getInfo'?
260- $ userId = $ tokenInfo ['user_id ' ];
261- if (!$ clientId ) {
262- $ clientId = $ tokenInfo ['client_id ' ];
263- }
264- break ;
265- default :
266- $ userId = false ;
267- break ;
268- }
269-
270- $ httpDpop = $ request ->getServerParams ()['HTTP_DPOP ' ];
271-
272- $ response = $ authServer ->respondToAccessTokenRequest ($ request );
273-
274- if (isset ($ userId )) {
275- $ response = $ tokenGenerator ->addIdTokenToResponse (
276- $ response ,
277- $ clientId ,
278- $ userId ,
279- ($ _SESSION ['nonce ' ] ?? '' ),
280- Server::getKeys ()['privateKey ' ],
281- $ httpDpop
282- );
283- }
284-
285- Server::respond ($ response );
286- }
287183 }
0 commit comments