/**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  * @throws \Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $baseUrl = $input->getOption(self::OPTION_BASE_URL);
     if (is_null($baseUrl)) {
         throw new \Exception('Invalid base URL');
     }
     $callbackUri = $this->router->generate('weaving_the_web_api_oauth_callback');
     $redirectUrl = $baseUrl . $callbackUri;
     $client = $this->clientRepository->make($redirectUrl);
     $successMessage = $this->translator->trans('oauth.client.authorization_url', ['{{ authorizaton_url }}' => $client->getAuthorizationUrl(), '{{ client_id }}' => $client->getPublicId(), '{{ client_secret }}' => $client->getSecret()], 'authorization');
     $output->writeln($successMessage);
     $successMessage = $this->translator->trans('oauth.client.creation_success', [], 'authorization');
     $output->writeln($successMessage);
     $returnCode = 0;
     return $returnCode;
 }
Esempio n. 2
0
 /**
  * @Extra\Route(
  *      "/client/create",
  *      name="weaving_the_web_dashboard_settings_oauth_create_client"
  * )
  * @Extra\Method({"GET", "POST"})
  * @Extra\Template("WeavingTheWebDashboardBundle:Settings:OAuthClient/Create/_block.html.twig")
  *
  * @param  Request $request
  * @return array
  */
 public function createOAuthClientAction(Request $request)
 {
     $currentRoute = $this->getCurrentRoute();
     $form = $this->formFactory->create('create_oauth_client', ['redirect_uri' => $this->getDefaultRedirectUri()], ['action' => $currentRoute]);
     if ($this->isFormSubmitted($form, $request)) {
         if ($form->isValid()) {
             $data = $form->getData();
             /** @var \WeavingTheWeb\Bundle\ApiBundle\Entity\OAuth\Client $client */
             $redirectUri = $data['redirect_uri'];
             $client = $this->clientRepository->make($redirectUri);
             $infoMessages = [$this->translator->trans('oauth.create_client.success', [], 'oauth')];
             $this->addFlashMessages($infoMessages, 'create_client_info');
             $linkMessages = [$this->translator->trans('oauth.create_client.new_client', ['{{ authorization_url }}' => $client->getAuthorizationUrl(), '{{ client_id }}' => $client->getPublicId(), '{{ client_secret }}' => $client->getSecret()], 'oauth')];
             $this->addFlashMessages($linkMessages, 'create_client_link');
             return new RedirectResponse($currentRoute);
         } else {
             $this->handleFormErrors($form, 'create_client');
         }
     }
     return ['create_oauth_client_form' => $form->createView()];
 }