protected function generate(Credentials $credentials, $scope) { $userId = $this->userService->authenticateUser($credentials->getClientId(), $credentials->getClientSecret(), [User::STATUS_ADMINISTRATOR]); if (!empty($userId)) { $scopes = ['backend', 'authorization']; // scopes $scopes = $this->userService->getValidScopes($userId, $scopes); if (empty($scopes)) { throw new ServerErrorException('No valid scope given'); } // generate access token return $this->appService->generateAccessToken(App::BACKEND, $userId, $scopes, isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1', new \DateInterval($this->expireBackend)); } else { throw new ServerErrorException('Unknown user'); } }
protected function generate(Credentials $credentials, $code, $redirectUri, $clientId) { $code = $this->appCodeService->getCode($credentials->getClientId(), $credentials->getClientSecret(), $code, $redirectUri ?: ''); if (!empty($code)) { // check whether the code is older then 30 minutes. After that we // can not exchange it for an access token if (time() - strtotime($code['date']) > 60 * 30) { throw new ServerErrorException('Code is expired'); } // scopes $scopes = $this->scopeService->getValidScopes($code['appId'], $code['userId'], $code['scope'], ['backend']); if (empty($scopes)) { throw new ServerErrorException('No valid scope given'); } // generate access token return $this->appService->generateAccessToken($code['appId'], $code['userId'], $scopes, isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1', new \DateInterval($this->expireApp)); } else { throw new ServerErrorException('Unknown credentials'); } }
protected function generate(Credentials $credentials, $username, $password, $scope) { $app = $this->appService->getByAppKeyAndSecret($credentials->getClientId(), $credentials->getClientSecret()); if (!empty($app)) { // check user $userId = $this->userService->authenticateUser($username, $password, [User::STATUS_ADMINISTRATOR, User::STATUS_CONSUMER]); if (!empty($userId)) { // validate scopes $scopes = $this->scopeService->getValidScopes($app['id'], $userId, $scope, ['backend']); if (empty($scopes)) { throw new ServerErrorException('No valid scope given'); } // generate access token return $this->appService->generateAccessToken($app['id'], $userId, $scopes, isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1', new \DateInterval($this->expireApp)); } else { throw new ServerErrorException('Unknown user'); } } else { throw new ServerErrorException('Unknown credentials'); } }