Exemplo n.º 1
0
 /**
  * @Route("/", methods={"POST"})
  */
 public function loginAction(Request $request)
 {
     $request->request->set('grant_type', 'password');
     $request->request->set('client_id', $this->clientId);
     $request->request->set('client_secret', $this->clientSecret);
     $this->server->setRequest($request);
     try {
         $response = $this->server->issueAccessToken();
         $request->getSession()->set('oauth_data', $response);
         return new Response();
     } catch (OAuthException $e) {
         return new Response('', Response::HTTP_BAD_REQUEST);
     }
 }
Exemplo n.º 2
0
 /**
  * Resource owner password credentials grant.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function grantPasswordCredentials(Request $request)
 {
     $this->authorisationServer->setRequest($request);
     try {
         $response = $this->authorisationServer->issueAccessToken();
         return new Response(json_encode($response), 200, ['Content-type' => 'application/json', 'Cache-Control' => 'no-store', 'Pragma' => 'no-store']);
     } catch (OAuthException $e) {
         return $this->getExceptionResponse($e);
     }
 }
 /**
  * Register the Authorisation Server
  *
  * @return void
  */
 private function authorisation()
 {
     $this->app->singleton('League\\OAuth2\\Server\\AuthorizationServer', function ($app) {
         $server = new AuthorizationServer();
         $server->setSessionStorage(new SessionStorage($app->make('db')));
         $server->setAccessTokenStorage(new AccessTokenStorage($app->make('db')));
         $server->setRefreshTokenStorage(new RefreshTokenStorage($app->make('db')));
         $server->setClientStorage(new ClientStorage($app->make('db')));
         $server->setScopeStorage(new ScopeStorage($app->make('db')));
         $server->setAuthCodeStorage(new AuthCodeStorage($app->make('db')));
         $passwordGrant = new PasswordGrant();
         $passwordGrant->setVerifyCredentialsCallback(function ($user, $pass) {
             return true;
         });
         $server->addGrantType($passwordGrant);
         $refreshTokenGrant = new RefreshTokenGrant();
         $server->addGrantType($refreshTokenGrant);
         $server->setRequest($app['request']);
         return $server;
     });
 }
Exemplo n.º 4
0
 /**
  * Set the request to use on the issuer and checker.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  */
 public function setRequest(Request $request)
 {
     $this->issuer->setRequest($request);
     $this->checker->setRequest($request);
 }
 function it_sets_the_request_to_the_issuer_and_checker(AuthorizationServer $issuer, ResourceServer $checker, Request $request)
 {
     $issuer->setRequest($request)->shouldBeCalled();
     $checker->setRequest($request)->shouldBeCalled();
     $this->setRequest($request);
 }