/** * @Rest\Post("/app/client", name="create-client") * @Rest\View() */ public function createAction() { $client = $this->clientManager->createClient(); $client->setRedirectUris(['http://www.example.com']); $client->setAllowedGrantTypes(['token', 'password', 'authorization_code', 'client_credentials']); $this->clientManager->updateClient($client); return $client; }
/** * If the user is logged generates the access token and sets into response creating a cookie. * * @param \Kreta\Bundle\UserBundle\Event\AuthorizationEvent $event The authorization event */ public function onAuthorizationEvent(AuthorizationEvent $event) { $client = $this->clientManager->findClientBy(['secret' => $this->clientSecret]); $session = $event->getRequest()->getSession(); $request = new Request(); $request->query->add(['grant_type' => 'password', 'client_secret' => $this->clientSecret, 'client_id' => sprintf('%s_%s', $client->getId(), $client->getRandomId()), 'username' => $session->get('_email'), 'password' => $session->get('_password')]); $response = $this->oauthServer->grantAccessToken($request); $token = json_decode($response->getContent(), true); $event->getRequest()->getSession()->remove('_email'); $event->getRequest()->getSession()->remove('_password'); $event->getRequest()->getSession()->replace(['access_token' => $token['access_token'], 'refresh_token' => $token['refresh_token']]); }
function it_listens_interactive_login(InteractiveLoginEvent $interactiveLoginEvent, TokenInterface $token, UserInterface $user, Request $request, SessionInterface $session, ParameterBagInterface $parameterBag, ClientManagerInterface $clientManager, ClientInterface $client, OAuth2 $oauthServer, Response $response) { $interactiveLoginEvent->getAuthenticationToken()->shouldBeCalled()->willReturn($token); $token->getUser()->shouldBeCalled()->willReturn($user); $interactiveLoginEvent->getRequest()->shouldBeCalled()->willReturn($request); $parameterBag->get('_username')->shouldBeCalled()->willReturn('*****@*****.**'); $parameterBag->get('_password')->shouldBeCalled()->willReturn('123456'); $request->request = $parameterBag; $request->getSession()->shouldBeCalled()->willReturn($session); $session->set('_email', '*****@*****.**')->shouldBeCalled(); $session->set('_password', '123456')->shouldBeCalled(); $clientManager->findClientBy(['secret' => 'client-secret'])->shouldBeCalled()->willReturn($client); $client->getId()->shouldBeCalled()->willReturn('the-id'); $client->getRandomId()->shouldBeCalled()->willReturn('random-id'); $session->get('_email')->shouldBeCalled()->willReturn('*****@*****.**'); $session->get('_password')->shouldBeCalled()->willReturn('123456'); $oauthServer->grantAccessToken(Argument::type('Symfony\\Component\\HttpFoundation\\Request'))->shouldBeCalled()->willReturn($response); $response->getContent()->shouldBeCalled()->willReturn('the response content'); $session->remove('_email')->shouldBeCalled()->willReturn('*****@*****.**'); $session->remove('_password')->shouldBeCalled()->willReturn('123456'); $session->replace(['access_token' => null, 'refresh_token' => null])->shouldBeCalled(); $this->onInteractiveLogin($interactiveLoginEvent); }
public function getClient($clientId) { return $this->clientManager->findClientByPublicId($clientId); }