/** * @throws AbortException */ public function actionAuthorize() { if (!$this->getHttpRequest()->isMethod(IRequest::GET)) { $body = $this->createStream(); $body->write('Method not allowed'); $this->sendResponse($this->createResponse()->withStatus(IResponse::S405_METHOD_NOT_ALLOWED)->withBody($body)); } $response = $this->createResponse(); try { $this->getSession(self::SESSION_NAMESPACE)->authorizationRequest = $this->authorizationRequestSerializer->serialize($this->authorizationServer->validateAuthorizationRequest($this->createServerRequest())); if (!$this->getUser()->isLoggedIn()) { $this->redirect(...$this->redirectConfig->getLoginDestination()); } $this->redirect(...$this->redirectConfig->getApproveDestination()); } catch (AbortException $e) { throw $e; } catch (OAuthServerException $e) { $this->sendResponse($e->generateHttpResponse($response)); } catch (\Exception $e) { if ($this->logger) { $this->logger->error($e->getMessage(), ['exception' => $e]); } $body = $this->createStream(); $body->write('Unknown error'); $this->sendResponse($response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body)); } }
/** * Index handler. * * @param \Psr\Http\Message\ServerRequestInterface $psrRequest * @param \Laravel\Passport\ClientRepository $clients * * @return \Illuminate\Http\Response */ public function index(ServerRequestInterface $psrRequest, ClientRepository $clients) { return $this->withErrorHandling(function () use($psrRequest, $clients) { $this->request->session()->put('authRequest', $authRequest = $this->server->validateAuthorizationRequest($psrRequest)); $scopes = $this->parseScopes($authRequest); return $this->response->view('passport::authorize', ['client' => $clients->find($authRequest->getClient()->getIdentifier()), 'user' => $this->request->user(), 'scopes' => $scopes, 'request' => $this->request]); }); }