Generate the token or get it from the session
329200
protected function generateToken()
    {
        if ($this->token === null) {
            $secret = array(
                'install' => __DIR__,
                'name' => $this->name,
            );

            if (isset($_SESSION)) {
                $key = sha1(__DIR__ . '/' . 'formidable_secret');

                if (isset($_SESSION[$key])) {
                    $secret['csrf'] = $_SESSION[$key];
                } else {
                    $csrf = sha1(uniqid(mt_rand(), true).'|'.gettimeofday(true));
                    $_SESSION[$key] = $csrf;
                    $secret['csrf'] = $csrf;
                }
            }

            $this->token = sha1(serialize($secret));
        }
    }
300137
async def fetch_token(self):
        """"""
        url = '{}/login'.format(API_URL)
        payload = 'email={}&password={}'.format(self._email, self._password)

        reg = await self.api_post(url, None, payload)
        if reg is None:
            _LOGGER.error('Unable to authenticate and fetch eight token.')
        else:
            self._userid = reg['session']['userId']
            self._token = reg['session']['token']
            self._expdate = reg['session']['expirationDate']
            _LOGGER.debug('UserID: %s, Token: %s', self._userid, self.token)
848551
private String getToken() {

        SessionData session = dataMgr.getSessionDAO().session();
        if (session != null && session.getExpiresOn() > System.currentTimeMillis()) {
            return session.getAccessToken();
        }

        return null;
    }
1170888
def make_bench_generate_token(alg):
    
    def f(_):
        """ Generate token """
        privk = priv_keys[alg].get('default', priv_key)
        jwt.generate_jwt(payload, privk, alg, timedelta(seconds=5))
    return f
237106
public function generateToken() {
		if( !isset($_SESSION[self::SESSION_KEY][$this->name]) ) {
			$_SESSION[self::SESSION_KEY][$this->name]	= array();
		}
		$TOKEN_SESSION = &$_SESSION[self::SESSION_KEY][$this->name];
		do {
			$token = generatePassword(static::$TOKEN_LENGTH);
		} while( isset($TOKEN_SESSION[$token]) );
		if( count($TOKEN_SESSION) >= $this->maxToken ) {
			array_shift($TOKEN_SESSION);
		}
		$TOKEN_SESSION[$token]	= 0;
		return $token;
	}
1342001
def gen_token():
    """"""
    return ''.join(
        random.choice(
            string.ascii_uppercase + string.ascii_lowercase + string.digits)
        for _ in range(32))
832041
public static function generateToken() {
        if (self::$token == NULL) {
            if (session()->has('token')) {
                session()->delete('token');
            }
            self::$token = base64_encode(openssl_random_pseudo_bytes(32));
            session()->set('token', self::$token);
        }

        return self::$token;
    }
1144638
public function generate(): string
    {
        $this->token = hash('sha256', $this->generateRandomToken());
        $this->session[$this->name] = $this->token;

        return $this->token;
    }
347132
function() {
      if (this.options.applevel === true || this.options.applevel === false) return this.options.applevel;
      return this.options.session_token == null;
    }
510358
public static function getSessionToken()
    {
        $token = null;

        if (isset($_SESSION[__SYM_COOKIE_PREFIX__]['xsrf-token'])) {
            $token = $_SESSION[__SYM_COOKIE_PREFIX__]['xsrf-token'];
        }

        if (is_array($token)) {
            $token = key($token);
        }

        return is_null($token) ? null : $token;
    }
506240
function generateSetupToken (tokenPath) {
  mkdirp.sync(path.dirname(tokenPath))

  var token = crypto.randomBytes(256).toString('hex')
  try {
    fs.writeFileSync(tokenPath, token, 'utf8')
  } catch (e) {
    throw new Error('Unable to save setup token to ' + tokenPath)
  }
  return token
}
540019
def token(self):
        
        if not self._token:
            self._token = self.fetch_token()
            logger.payment(self)
        return self._token
608936
public function generateOneTimeToken(): string
	{
		if(!empty($this->sessionData['mako.tokens']))
		{
			$this->sessionData['mako.tokens'] = array_slice($this->sessionData['mako.tokens'], 0, (static::MAX_TOKENS - 1));
		}
		else
		{
			$this->sessionData['mako.tokens'] = [];
		}

		$token = $this->generateId();

		array_unshift($this->sessionData['mako.tokens'], $token);

		return $token;
	}
1213035
def generate_token():
    
    length = 50
    stringset = string.ascii_letters + string.digits
    token = ''.join([stringset[i % len(stringset)] for i in [ord(x) for x in os.urandom(length)]])
    return token
579537
def token_gen_call(username, password):
    """"""
    secret_key = 'super-secret-key-please-change'
    mockusername = 'User2'
    mockpassword = 'Mypassword'
    if mockpassword == password and mockusername == username: # This is an example. Don't do that.
        return {"token" : jwt.encode({'user': username, 'data': 'mydata'}, secret_key, algorithm='HS256')}
    return 'Invalid username and/or password for user: {0}'.format(username)
794641
def _generateForTokenSecurity(self):
        
        agolToken = self._agolSecurityHandler.token
        url = self._url + "/getProxyUserToken"
        params = {"token" : self._agolSecurityHandler.token,
                  "contributorUid" : self._contributionUID}
        res = self._post(url=url, param_dict=params,
                         additional_headers={ "Referer": self._agolSecurityHandler._referer_url},
                         proxy_port=self._proxy_port,
                         proxy_url=self._proxy_url)
        return res['token']
1007401
def generate_token(user_id, expire_in=None, data={}, issuer=None, iat=None):
    """"""
    assert user_id, "No user_id passed to generate_token()"
    assert isinstance(data, dict), "generate_token(data=) should be a dictionary"
    assert get_config().jwt_secret, "No JWT secret configured in pymacaron"

    if not issuer:
        issuer = get_config().jwt_issuer

    assert issuer, "No JWT issuer configured for pymacaron"

    if expire_in is None:
        expire_in = get_config().jwt_token_timeout

    if iat:
        epoch_now = iat
    else:
        epoch_now = to_epoch(timenow())
    epoch_end = epoch_now + expire_in

    data['iss'] = issuer
    data['sub'] = user_id
    data['aud'] = get_config().jwt_audience
    data['exp'] = epoch_end
    data['iat'] = epoch_now

    headers = {
        "typ": "JWT",
        "alg": "HS256",
        "iss": issuer,
    }

    log.debug("Encoding token with data %s and headers %s (secret:%s****)" % (data, headers, get_config().jwt_secret[0:8]))

    t = jwt.encode(
        data,
        get_config().jwt_secret,
        headers=headers,
    )

    if type(t) is bytes:
        t = t.decode("utf-8")

    return t