/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param int $limit * @param int $time * * @throws \League\OAuth2\Server\Exception\OAuthServerException * * @return mixed */ public function handle($request, Closure $next, $limit = 10, $time = 60) { try { $response = $this->server->respondToAccessTokenRequest($request, $response); } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (Exception $exception) { return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))->generateHttpResponse($response); } return $next($request); }
/** * @param \Psr\Http\Message\ServerRequestInterface $request * * @return \Illuminate\Http\Response */ public function issueToken(ServerRequestInterface $request) { $response = $this->withErrorHandling(function () use($request) { return $this->server->respondToAccessTokenRequest($request, new Psr7Response()); }); if ($response->getStatusCode() < 200 || $response->getStatusCode() > 299) { return $response; } $payload = json_decode($response->getBody()->__toString(), true); if (isset($payload['access_token'])) { $this->revokeOtherAccessTokens($payload); } return $response; }
/** * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable $next * * @return ResponseInterface */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { try { $response = $this->server->respondToAccessTokenRequest($request, $response); } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); // @codeCoverageIgnoreStart } catch (\Exception $exception) { return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))->generateHttpResponse($response); // @codeCoverageIgnoreEnd } // Pass the request and response on to the next responder in the chain return $next($request, $response); }
/** * @throws AbortException */ public function actionAccessToken() { if (!$this->getHttpRequest()->isMethod(IRequest::POST)) { $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->sendResponse($this->authorizationServer->respondToAccessTokenRequest($this->createServerRequest(), $response)); } 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)); } }