Пример #1
0
 /**
  * @Route("/user/apps/revoke/{clientId}", name="user_profile_revoke_app")
  */
 public function appRevokeAction(OauthClient $client)
 {
     if (!$this->getUserLayer()->isUser()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     // Remove authorization
     $em->createQueryBuilder()->delete()->from('EtuCoreApiBundle:OauthAuthorization', 'a')->where('a.client = :client')->andWhere('a.user = :user')->setParameter('client', $client->getId())->setParameter('user', $this->getUser()->getId())->getQuery()->execute();
     // Remove access_tokens
     $em->createQueryBuilder()->delete()->from('EtuCoreApiBundle:OauthAccessToken', 't')->where('t.client = :client')->andWhere('t.user = :user')->setParameter('client', $client->getId())->setParameter('user', $this->getUser()->getId())->getQuery()->execute();
     // Remove refresh_tokens
     $em->createQueryBuilder()->delete()->from('EtuCoreApiBundle:OauthRefreshToken', 't')->where('t.client = :client')->andWhere('t.user = :user')->setParameter('client', $client->getId())->setParameter('user', $this->getUser()->getId())->getQuery()->execute();
     // Remove authrization_code
     $em->createQueryBuilder()->delete()->from('EtuCoreApiBundle:OauthAuthorizationCode', 't')->where('t.client = :client')->andWhere('t.user = :user')->setParameter('client', $client->getId())->setParameter('user', $this->getUser()->getId())->getQuery()->execute();
     return $this->redirect($this->generateUrl('user_profile'));
 }
Пример #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var EntityManager $em */
     $em = $this->getContainer()->get('doctrine')->getManager();
     $dialog = $this->getHelperSet()->get('dialog');
     $client = new OauthClient();
     $client->setName($dialog->ask($output, 'Name: '));
     $client->setUserId($dialog->ask($output, 'Owner ID: '));
     $client->setRedirectUri($dialog->ask($output, 'Redirect URL: '));
     $client->generateClientId();
     $client->generateClientSecret();
     $em->persist($client);
     $em->flush();
     $output->writeln('<fg=green>Client ' . $client->getClientId() . ' created with secret ' . $client->getClientSecret() . '</fg=green>');
 }
Пример #3
0
 /**
  * @Route("/app/manage/{clientId}/remove", name="devs_panel_remove_app")
  * @Template()
  */
 public function removeAppAction(Request $request, OauthClient $client)
 {
     if (!$this->getUserLayer()->isUser()) {
         return $this->createAccessDeniedResponse();
     }
     if ($client->getUser()->getId() != $this->getUser()->getId()) {
         throw new AccessDeniedHttpException();
     }
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $form = $this->createFormBuilder()->add('client_id', 'text', ['required' => true, 'label' => 'Par sécurité, vous devez entrer le Client ID de cette application pour pouvoir la supprimer :', 'constraints' => new EqualTo(['value' => (string) $client->getClientId(), 'message' => 'Ce Client ID n\'est pas correct'])])->getForm();
     if ($request->getMethod() == 'POST' && $form->submit($request)->isValid()) {
         $em->remove($client);
         $em->flush();
         $this->get('session')->getFlashBag()->set('message', array('type' => 'success', 'message' => 'L\' application ' . $client->getName() . ' a bien été supprimée'));
         return $this->redirect($this->generateUrl('devs_panel_index'));
     }
     /** @var OauthClient[] $clients */
     $clients = $em->getRepository('EtuCoreApiBundle:OauthClient')->findBy(['user' => $this->getUser()]);
     return ['client' => $client, 'clients' => $clients, 'form' => $form->createView()];
 }