Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $accessTokenService = new AccessTokenService($this->getSlim());
     $accessTokenService->fetchTokens();
     $textArray = [];
     foreach ($accessTokenService->getCursor() as $document) {
         $textArray[] = $document->jsonSerialize();
     }
     $text = json_encode($textArray, JSON_PRETTY_PRINT);
     $output->writeln('<info>Tokens successfully fetched!</info>');
     $output->writeln('<info>Info:</info>');
     $output->writeln($text);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $basicAuthService = new BasicAuthService($this->getSlim());
     if (null === $input->getOption('name')) {
         $helper = $this->getHelper('question');
         $question = new Question('Please enter a name: ', 'untitled');
         $name = $helper->ask($input, $output, $question);
     } else {
         $name = $input->getOption('name');
     }
     if (null === $input->getOption('description')) {
         $question = new Question('Please enter a description: ', '');
         $description = $helper->ask($input, $output, $question);
     } else {
         $description = $input->getOption('description');
     }
     if (null === $input->getOption('expiration')) {
         $question = new Question('Please enter the expiration timestamp for the token (blank == indefinite): ');
         $expiresAt = $helper->ask($input, $output, $question);
     } else {
         $expiresAt = $input->getOption('expiration');
     }
     $userService = new UserService($this->getSlim());
     $userService->fetchAll();
     $users = [];
     foreach ($userService->getCursor() as $user) {
         $users[$user->getEmail()] = $user;
     }
     if (null === $input->getOption('email')) {
         $question = new Question('Please enter enter the e-mail of the associated user: '******'');
         $question->setAutocompleterValues(array_keys($users));
         $email = $helper->ask($input, $output, $question);
         $user = $users[$email];
     } else {
         $email = $input->getOption('email');
         if (!isset($users[$email])) {
             throw new Exception('Invalid e-mail provided! User does not exist!');
         }
         $user = $users[$email];
     }
     $userService->fetchAvailablePermissions();
     $scopesDictionary = [];
     foreach ($userService->getCursor() as $scope) {
         $scopesDictionary[$scope->getName()] = $scope;
     }
     if (null === $input->getOption('scopes')) {
         $question = new ChoiceQuestion('Please select which scopes you would like to enable (defaults to super). Separate multiple values with commas (without spaces). If you select super, all other permissions are also inherited: ', array_keys($scopesDictionary), '0');
         $question->setMultiselect(true);
         $selectedScopeNames = $helper->ask($input, $output, $question);
         $selectedScopes = [];
         foreach ($selectedScopeNames as $selectedScopeName) {
             $selectedScopes[] = $scopesDictionary[$selectedScopeName];
         }
     } else {
         $selectedScopeNames = explode(',', $input->getOption('scopes'));
     }
     $selectedScopes = [];
     foreach ($selectedScopeNames as $selectedScopeName) {
         $selectedScopes[] = $scopesDictionary[$selectedScopeName];
     }
     $token = $basicAuthService->addToken($name, $description, $expiresAt, $user, $selectedScopes);
     if (null !== $input->getOption('key')) {
         $token->setKey($input->getOption('key'));
         $token->save();
     }
     if (null !== $input->getOption('secret')) {
         $token->setSecret($input->getOption('secret'));
         $token->save();
     }
     $text = json_encode($token, JSON_PRETTY_PRINT);
     $output->writeln('<info>Basic token successfully created!</info>');
     $output->writeln('<info>Info:</info>');
     $output->writeln($text);
 }
Ejemplo n.º 3
0
             return $version;
         } catch (\InvalidArgumentException $e) {
             throw new \Exception('X-Experience-API-Version header invalid.', Resource::STATUS_BAD_REQUEST);
         }
     }
 });
 // Request logging
 $app->container->singleton('requestLog', function () use($app) {
     $logService = new LogService($app);
     $logDocument = $logService->logRequest($app->request);
     return $logDocument;
 });
 // Auth - token
 $app->container->singleton('auth', function () use($app) {
     if (!$app->request->isOptions() && !($app->request->getPathInfo() === '/about')) {
         $basicAuthService = new BasicAuthService($app);
         $oAuthService = new OAuthService($app);
         $token = null;
         try {
             $token = $oAuthService->extractToken($app->request);
             $app->requestLog->addRelation('oAuthToken', $token)->save();
         } catch (AuthFailureException $e) {
             // Ignore
         }
         try {
             $token = $basicAuthService->extractToken($app->request);
             $app->requestLog->addRelation('basicToken', $token)->save();
         } catch (AuthFailureException $e) {
             // Ignore
         }
         if (null === $token) {