returns a CSRF token for the given token id

if previously no token existed for the given id, a new token is
generated, stored and returned; otherwise the existing token is returned

@param string $tokenId
@return CsrfToken
420455
public function getToken($tokenId) {

		if($this->storage->hasToken($tokenId)) {
			return $this->storage->getToken($tokenId);
		}

		$token = new CsrfToken(
			$tokenId,
			$this->generateValue((int) $this->tokenLength)
		);

		$this->storage->setToken($tokenId, $token);

		return $token;
	}
298426
public function forPreviousTokenId($tokenId) {
        $this->sql_select->join('gems__tokens as ct',
                'gems__tokens.gto_id_respondent_track = ct.gto_id_respondent_track AND
                    gems__tokens.gto_id_token != ct.gto_id_token AND
                        ((gems__tokens.gto_round_order > ct.gto_round_order) OR
                            (gems__tokens.gto_round_order = ct.gto_round_order AND gems__tokens.gto_created > ct.gto_created))',
                array());

        $this->sql_select
                ->where('ct.gto_id_token = ?', $tokenId)
                ->order('gems__tokens.gto_round_order')
                ->order('gems__tokens.gto_created');

        return $this;
    }
435647
public function generateCsrfToken(int $length = 32): string
    {
        $token = bin2hex(random_bytes($length));

        (new Session())->set('csrf_token', $token);

        return $token;
    }
319418
public function createFromToken($token, $data, $cardId = null)
    {
        if ($data instanceof JsonSerializable) {
            $data = $data->jsonSerialize();
        }

        if (is_string($token)) {
            $data['token'] = $token;
        } else {
            $data['token'] = $token['token'];
        }

        return $this->create($data, $cardId);
    }
395193
public function refreshToken($clientId, $clientSecret, $refreshToken): Token
    {
        $request = new Request('POST', $this->tokenUrl, [
            'Content-Type' => 'application/json',
        ], json_encode([
            'client_id' => $clientId,
            'client_secret' => $clientSecret,
            'refresh_token' => $refreshToken,
            'grant_type' => 'refresh_token',
        ]));

        $response = $this->getClient()->sendRequest($request);
        $responseBody = $response->getBody()->getContents();

        $this->token = $this->denormalizeObject(Token::class, [json_decode($responseBody)], false);

        return $this->token;
    }
1241983
public function tokenById($id)
    {
        if ($user = $this->provider->retrieveById($id)) {
            return $this->jwt->fromUser($user);
        }
    }
241845
protected function _token($token = null)
    {
        if ($token) {
            return $token;
        }

        $token = $this->_request()->data('token');
        if ($token) {
            return $token;
        }

        $token = $this->_request()->param('token');
        if ($token) {
            return $token;
        }

        return $this->_request()->query('token');
    }
1110427
private function registerUse(int $tokenID)
    {
        $namespace = rtrim($this->activeNamespace($tokenID), '\\');

        $class = '';
        $localAlias = null;
        for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] != ';'; ++$localID) {
            if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) {
                $localAlias = '';
                continue;
            }

            if ($localAlias === null) {
                $class .= $this->tokens[$localID][self::TOKEN_CODE];
            } else {
                $localAlias .= $this->tokens[$localID][self::TOKEN_CODE];
            }
        }

        if (empty($localAlias)) {
            $names = explode('\\', $class);
            $localAlias = end($names);
        }

        $this->namespaces[$namespace][self::N_USES][trim($localAlias)] = trim($class);
    }
1077341
private function activeDeclaration(int $tokenID): string
    {
        foreach ($this->declarations as $declarations) {
            foreach ($declarations as $name => $position) {
                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
                    return $name;
                }
            }
        }

        //Can not be detected
        return '';
    }
216201
public function getTokenAskButton($tokenId, $tokenStatus, $staffToken, $keepCaps)
    {
        if ('O' == $tokenStatus || 'P' == $tokenStatus) {
            if ($staffToken) {
                $menuItem = $this->_getAskMenuItem();
                $label    = $menuItem->get('label');

                if ('P' == $tokenStatus) {
                    $label = $this->_('Continue');
                }

                $link = $menuItem->toActionLink(
                    ($keepCaps ? $label : strtolower($label)),
                    [
                        'gto_id_token' => $tokenId,
                        'can_be_taken' => 1,
                        \Gems_Model::ID_TYPE => 'token',
                    ]);

                if ($link) {
                    $link->title = sprintf($this->_('Answer token %s'), strtoupper($tokenId));

                    return $link;
                }
            }

            return $this->getTokenCopyLink($tokenId, $tokenStatus);
        }
    }
813767
protected function createToken($userId, $csrfToken, Carbon $expiration)
    {
        return JWT::encode([
            'sub' => $userId,
            'csrf' => $csrfToken,
            'expiry' => $expiration->getTimestamp(),
        ], $this->encrypter->getKey());
    }
1164635
protected function _extractContent($tokenId, $tokens) {
		$token = $tokens[$tokenId];
		$body = $this->_controlContent($tokenId, $tokens);
		$line = $token['line'];
		while (--$tokenId >= 0 && $tokens[$tokenId]['line'] === $line) {
			$body = $tokens[$tokenId]['content'] . $body;
		}
		return $body;
	}
74964
public function getToken()
    {
        if (!$this->token) {
            $session = new Session('Auth');
            if (!$session->token) {
                $session->token = uniqid();
            }
            $this->token = $session->token;
        }
        return $this->token;
    }
176382
public function certificate($serverId, $siteId, $certificateId)
    {
        return new Certificate(
            $this->get("servers/$serverId/sites/$siteId/certificates/$certificateId")['certificate']
            + ['server_id' => $serverId, 'site_id' => $siteId], $this
        );
    }
1272238
protected function generateToken() {
		$session = $this->getSession();
		if($session->has('_csrf_token'))
			return $session['_csrf_token'];
		else {
			$token = \Asgard\Common\Tools::randstr();
			return $session['_csrf_token'] = $token;
		}
	}
72692
public function make($userId, $csrfToken)
    {
        $config = $this->config->get('session');

        $expiration = Carbon::now()->addMinutes($config['lifetime']);

        return new Cookie(
            Passport::cookie(),
            $this->createToken($userId, $csrfToken, $expiration),
            $expiration,
            $config['path'],
            $config['domain'],
            $config['secure'],
            true,
            false,
            $config['same_site'] ?? null
        );
    }
646343
public function generateToken($userId)
    {
        $user = $this->users->find($userId);

        if (! is_null($user)) {
            $user->generateActivationToken();
            $user->setStatus(Status::INACTIVE);
        }
    }