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 ( Input::all() ) ) ); if ($response instanceof OAuth2Response) { $strategy = OAuth2ResponseStrategyFactoryMethod::buildStrategy ( $this->oauth2_protocol->getLastRequest(), $response ); return $strategy->handle($response); } return $response; } catch(OAuth2BaseException $ex1) { return Response::view ( 'errors.400', array ( 'error_code' => $ex1->getError(), 'error_description' => $ex1->getMessage() ), 400 ); } catch(Exception $ex) { Log::error($ex); return Response::view ( 'errors.400', array ( 'error_code' => "Bad Request", 'error_description' => "Generic Error" ), 400 ); } } /** * Token HTTP Endpoint * @return mixed */ public function token() { $response = $this->oauth2_protocol->token ( new OAuth2TokenRequest ( new OAuth2Message ( Input::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 ( Input::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 ( Input::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 = array(); return View::make("oauth2.session.check-session", $data); } /** * @see http://openid.net/specs/openid-connect-session-1_0.html#RPLogout */ public function endSession() { if(!$this->auth_service->isUserLogged()) { Log::debug("OAuth2ProviderController::endSession user is not logged!"); return Response::view('errors.404', array(), 404); } $request = new OAuth2LogoutRequest ( new OAuth2Message ( Input::all() ) ); if(!$request->isValid()) { Log::error('invalid OAuth2LogoutRequest!'); return Response::view('errors.404', array(), 404); } if(Request::isMethod('get') ) { $clients = []; foreach($this->auth_service->getLoggedRPs() as $client_id) { $client = $this->client_repository->getClientById($client_id); if(!is_null($client)){ $clients[] = $client; Log::info(sprintf("added RP %s", $client->getApplicationName())); } } // At the logout endpoint, the OP SHOULD ask the End-User whether he wants to log out of the OP as well. // If the End-User says "yes", then the OP MUST log out the End-User. return View::make('oauth2.session.session-logout', [ 'clients' => $clients, 'id_token_hint' => $request->getIdTokenHint(), 'post_logout_redirect_uri' => $request->getPostLogoutRedirectUri(), 'state' => $request->getState(), ]); } $consent = Input::get('oidc_endsession_consent'); if($consent === '1') { $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'); } Log::error('invalid consent response!'); return Response::view('errors.404', [], 404); } public function cancelLogout() { return Redirect::action('HomeController@index'); } }