oauth2_protocol = $oauth2_protocol; $this->auth_service = $auth_service; $this->client_repository = $client_repository; } /** * Authorize HTTP Endpoint * The authorization server MUST support the use of the HTTP "GET" * method [RFC2616] for the authorization endpoint and MAY support the * use of the "POST" method as well. * @return mixed */ public function auth() { try { $response = $this->oauth2_protocol->authorize ( OAuth2AuthorizationRequestFactory::getInstance()->build ( new OAuth2Message ( Request::all() ) ) ); if ($response instanceof OAuth2Response) { $strategy = OAuth2ResponseStrategyFactoryMethod::buildStrategy ( $this->oauth2_protocol->getLastRequest(), $response ); return $strategy->handle($response); } return $response; } catch (OAuth2BaseException $ex1) { $payload = [ 'error' => $ex1->getError(), 'error_description' => $ex1->getMessage() ]; if (request()->isJson()) { return Response::json($payload, 400); } return Response::view ( 'errors.400', $payload, 400 ); } catch (Exception $ex) { Log::error($ex); $payload = [ 'error' => "Bad Request", 'error_description' => "Generic Error" ]; if (request()->isJson()) { return Response::json($payload, 400); } return Response::view ( 'errors.400', $payload, 400 ); } } /** * Token HTTP Endpoint * @return mixed */ public function token() { $response = $this->oauth2_protocol->token ( new OAuth2TokenRequest ( new OAuth2Message ( Request::all() ) ) ); if ($response instanceof OAuth2Response) { $strategy = OAuth2ResponseStrategyFactoryMethod::buildStrategy ( $this->oauth2_protocol->getLastRequest(), $response ); return $strategy->handle($response); } return $response; } /** * Revoke Token HTTP Endpoint * @return mixed */ public function revoke() { $response = $this->oauth2_protocol->revoke ( new OAuth2TokenRevocationRequest ( new OAuth2Message ( Request::all() ) ) ); if ($response instanceof OAuth2Response) { $strategy = OAuth2ResponseStrategyFactoryMethod::buildStrategy ( $this->oauth2_protocol->getLastRequest(), $response ); return $strategy->handle($response); } return $response; } /** * @see http://tools.ietf.org/html/draft-richer-oauth-introspection-04 * Introspection Token HTTP Endpoint * @return mixed */ public function introspection() { $response = $this->oauth2_protocol->introspection ( new OAuth2AccessTokenValidationRequest ( new OAuth2Message ( Request::all() ) ) ); if ($response instanceof OAuth2Response) { $strategy = OAuth2ResponseStrategyFactoryMethod::buildStrategy ( $this->oauth2_protocol->getLastRequest(), $response ); return $strategy->handle($response); } return $response; } /** * OP's JSON Web Key Set [JWK] document. * @return string */ public function certs() { $doc = $this->oauth2_protocol->getJWKSDocument(); $response = Response::make($doc, 200); $response->header('Content-Type', HttpContentType::Json); return $response; } public function discovery() { $doc = $this->oauth2_protocol->getDiscoveryDocument(); $response = Response::make($doc, 200); $response->header('Content-Type', HttpContentType::Json); return $response; } /** * @see http://openid.net/specs/openid-connect-session-1_0.html#OPiframe */ public function checkSessionIFrame() { $data = []; return View::make("oauth2.session.check-session", $data); } /** * @see http://openid.net/specs/openid-connect-session-1_0.html#RPLogout */ public function endSession() { $request = new OAuth2LogoutRequest ( new OAuth2Message ( Request::all() ) ); if (!$request->isValid()) { Log::error('invalid OAuth2LogoutRequest!'); return Response::view('errors.400', [ 'error' => 'Invalid logout request.', 'error_description' => $request->getLastValidationError() ], 400); } $response = $this->oauth2_protocol->endSession($request); if (!is_null($response) && $response instanceof OAuth2Response) { $strategy = OAuth2ResponseStrategyFactoryMethod::buildStrategy($request, $response); return $strategy->handle($response); } return View::make('oauth2.session.session-ended'); } }