protected function execute(InputInterface $input, OutputInterface $output) { $appId = $input->getArgument('appId'); $userId = $input->getArgument('userId'); $scopes = $input->getArgument('scopes'); $expire = $input->getArgument('expire'); if (!is_numeric($appId)) { $app = $this->appTable->getOneByName($appId); } else { $app = $this->appTable->get($appId); } if (empty($app)) { throw new RuntimeException('Invalid app'); } if (!is_numeric($userId)) { $user = $this->userTable->getOneByName($userId); } else { $user = $this->userTable->get($userId); } if (empty($user)) { throw new RuntimeException('Invalid user'); } $scopes = $this->scopeService->getValidScopes($app['id'], $user['id'], $scopes); $ip = '127.0.0.1'; $expire = new DateInterval($expire); $accessToken = $this->appService->generateAccessToken($app['id'], $user['id'], $scopes, $ip, $expire); $response = ['App' => $app['name'], 'User' => $user['name'], 'Token' => $accessToken->getAccessToken(), 'Expires' => date('Y-m-d', $accessToken->getExpiresIn()), 'Scope' => $accessToken->getScope()]; $output->writeln(""); $output->writeln(Yaml::dump($response, 2)); $output->writeln(""); }
public function removeToken($appId, $tokenId) { $app = $this->appTable->get($appId); if (!empty($app)) { $this->appTokenTable->removeTokenFromApp($appId, $tokenId); } else { throw new StatusCode\NotFoundException('Invalid app'); } }
public function delete($userId, $appId) { $app = $this->appTable->get($appId); if (!empty($app)) { if ($app['userId'] != $userId) { throw new StatusCode\BadRequestException('App does not belong to the user'); } $this->appService->delete($appId); } else { throw new StatusCode\NotFoundException('Could not find app'); } }