settings = $settings; } public function handle(ServerRequestInterface $request): ResponseInterface { $actor = RequestUtil::getActor($request); $actor->assertRegistered(); if (!$actor->hasPermission('rhodes-island-oauth-center.use-oauth')) { // TODO: i18n description return new JsonResponse([ 'error' => 'no_permission', 'error_description' => 'Don\'t have the permissions of oauth' ]); } $params = $request->getParsedBody(); $oauth = new OAuth($this->settings); $server = $oauth->server(); $request = $oauth->request()::createFromGlobals(); $response = $oauth->response(); if (!$server->validateAuthorizeRequest($request, $response)) { return new JsonResponse($response->getParameters(), $response->getStatusCode(), $response->getHttpHeaders()); } $is_authorized = Arr::get($params, 'is_authorized', 0); $server->handleAuthorizeRequest($request, $response, $is_authorized, $actor->id); if ($is_authorized) { /*Record::create([ 'client_id' => Arr::get($params, 'client_id'), 'user_id' => $actor->id, 'authorized_at' => date('Y-m-d H:i:s') ]);*/ return new JsonResponse([ "redirect" => $response->getHttpHeader("Location") ]); } return new JsonResponse($response->getParameters(), $response->getStatusCode(), $response->getHttpHeaders()); } }