Generate csfr token.

@return void
@throws EndomondoApiException When generating fail
13111
protected function generateCSRFToken()
    {
        try {
            parent::generateCSRFToken();
        } catch (ClientException $e) {
            // too many request, sleep for a while
            if ($e->getCode() === 429) {
                throw new EndomondoApiException('Too many requests', $e->getCode(), $e);
            }

            throw new EndomondoApiException($e->getMessage(), $e->getCode(), $e);
        }
    }
863030
protected function generateAPI()
    {
        $srcPath = Strata::getSRCPath();
        $vendorPath = Strata::getVendorPath();
        $tmpPath = Strata::getTmpPath();

        $this->output->writeLn("<info>Generating API</info>");
        $this->output->writeLn($this->tree(true) . "Scanning $srcPath");
        $this->nl();

        if (!file_exists($tmpPath . "phploc.xml")) {
            touch($tmpPath . "phploc.xml");
        }

        if (!file_exists($tmpPath . "phpcs.xml")) {
            touch($tmpPath . "phpcs.xml");
        }

        system(sprintf("%sbin/phploc  --log-xml %sphploc.xml test", $vendorPath, $tmpPath));
        system(sprintf("%sbin/phpcs src --standard=PSR2 --report-xml=%sphpcs.xml", $vendorPath, $tmpPath));
        system(sprintf("%sbin/phpdox", $vendorPath));
    }
34382
private function generateActivationToken(): string
    {
        $this->setSize(32);
        $this->generateRandomToken();

        $this->activation_token = hash('sha256', $this->token);

        return $this->activation_token;
    }
3947
public function completeFlow()
    {
        $selfClient = app('selfClient');
        // Get the required params
        if (is_null($selfClient)) {
            throw new Exception\InvalidClientException();
        }

        // Validate client ID and client secret
        $client = $this->server->getClientStorage()->get(
            $selfClient->id,
            $selfClient->secret,
            null,
            $this->getIdentifier()
        );

        if (($client instanceof ClientEntity) === false) {
            $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
            throw new Exception\InvalidClientException();
        }

        // Create a new session
        $session = new SessionEntity($this->server);
        $session->setOwner('client', $client->getId());
        $session->associateClient($client);

        // Generate an access token
        $accessToken = new AccessTokenEntity($this->server);
        $accessToken->setId(SecureKey::generate());
        $accessToken->setExpireTime($this->getAccessTokenTTL() + time());

        foreach ($session->getScopes() as $scope) {
            $accessToken->associateScope($scope);
        }

        // Save everything
        $session->save();
        $accessToken->setSession($session);
        $accessToken->save();

        $oauthClient = new GenericProvider([
            'clientId'                => $selfClient->id,    // The client ID assigned to you by the provider
            'clientSecret'            => $selfClient->secret,   // The client password assigned to you by the provider
            'redirectUri'             => null,
            'urlAuthorize'            => null,
            'urlAccessToken'          => null,
            'urlResourceOwnerDetails' => null
        ]);
        $accessToken = new AccessToken(['access_token' => $accessToken->getId(), 'expires' => $accessToken->getExpireTime()]);
        return function ($method, $url, $options = []) use ($oauthClient, $accessToken) {
            return $oauthClient->getAuthenticatedRequest($method, $url, $accessToken, $options);
        };
    }
892427
private function registerDirectives()
  {
    $this->register(Not::class);
    $this->register(EndEmpty::class);
    $this->register(EndIsset::class);
    $this->register(EndNot::class);
    $this->register(EndNull::class);

    return true;
  }
1202841
public void prepareEndPoint(CFEndPointImpl endpoint) throws ChannelFrameworkException {
        if (null == endpoint.getOutboundChainData()) {
            VirtualConnectionFactory vcf = getOutboundVCFactory(endpoint.getOutboundChannelDefs());
            endpoint.setOutboundVCFactory(vcf);
            endpoint.setOutboundChainData(getChain(vcf.getName()));
        }
    }
697128
private function generateToken()
    {
        return Hash::hash256(self::getHa1()->getHash(), $this->getNonce(), $this->getRounds());
    }
1202295
private function dispenseToken()
    {
        $token = bin2hex(random_bytes($this->config->getTokenLength())); // Generate token.

        $arr = array(
            'token' => $token,
            'expires' => time() + $this->config->getTokenTtl()
        ); // Prepare array containing token and expiry.

        $plain = Spyc::YAMLDump($arr); // Encode as YAML.
        $encrypted =  Encryption::encrypt($plain, $this->config->getSecretKey()); // Apply symmetric encryption.

        file_put_contents($this->config->getSessionFileName(), $encrypted); // Write to disk.

        return $token;
    }
93176
private function genCrfsToken()
    {
        $hashOrig = '';
        if (!empty($this->fields)) {
            foreach (array_keys($this->fields) as $field) {
                if ($field !== self::SEPARATOR) {
                    $hashOrig .= $field;
                }
            }
        }
        if ('' !== $hashOrig) {
            $this->crfs = sha1($hashOrig);
            $this->add($this->getName() . '_token', array(
                'type' => 'hidden',
                'value' => $this->crfs,
            ));
        }
        return $this;
    }
601925
protected function createToken()
    {
        $token = $this->getToken()->createApplicationToken(
            $this->connect->getSaml()->getMetadata()->getServiceProvider()->getEntityID(),
            $this->connect->getSaml()->getPrivateKey()
        );
        return $token['token'];
    }
14654
private function callApiTokens()
    {
        $result = $this->callApi('action=tokens&type=edit');
        if (false == isset($result['tokens']) || false == isset($result['tokens']['edittoken'])) {
            throw new BuildException('Wiki token not found');
        }

        $this->apiEditToken = $result['tokens']['edittoken'];
    }
864183
public function generateToken()
    {
        $token   = md5(__CLASS__.uniqid());

        $sesCont = new SessionContainer(self::SESSION_KEY);
        $sesCont->$token = time();
        $sesCont->setExpirationSeconds(30, $token);

        return $token;
    }
1254875
private function getProvidedCsrfToken(): ?string
    {
        $token = $this->request->getParameter(self::REQUEST_TOKEN_VALUE);
        if (is_null($token)) {
            $token = isset($_SERVER[self::HEADER_TOKEN]) ? $_SERVER[self::HEADER_TOKEN] : null;
        }
        return $token;
    }
1031971
private function cspGenerateNonce()
    {
        $nonce = base64_encode(
            openssl_random_pseudo_bytes(30, $isCryptoStrong)
        );

        if ( ! $isCryptoStrong)
        {
            $this->addError(
                'OpenSSL (openssl_random_pseudo_bytes) reported that it did
                <strong>not</strong> use a cryptographically strong algorithm
                to generate the nonce for CSP.',

                E_USER_WARNING
            );
        }

        return $nonce;
    }
508186
public function generateAccessToken()
    {

        // $this->access_token = Yii::$app->security->generateRandomString() . '_' . time();
        $signer = new Sha256();
        $token = Yii::$app->jwt->getBuilder()->setIssuer(Yii::getAlias("@restIssuer"))// Configures the issuer (iss claim)
        ->setAudience(Yii::getAlias("@restAudience"))// Configures the audience (aud claim)
        ->setId(Yii::getAlias("@restId")+ strtotime(date('Y-m-d',time())), true)
            ->setExpiration(time() + Yii::$app->params['accessTokenExpire'])// Configures exp time
            ->setIssuedAt(time())// Configures the time that the token was issue (iat claim)

            ->sign($signer, Yii::$app->jwt->key)
            ->getToken(); // Retrieves the generated token
        //$this->auth_key=$this->id;
        $this->access_token = (string)$token;
    }
1177599
public function generateAccessToken()
    {
        try {
            $this->access_token = Yii::$app->security->generateRandomString(32);
        } catch (Exception $e) {
            throw $e;
        }
    }
1083563
protected function _generateCFS()
    {
        $cfsFile = $this->_directory->createFile($this->_name . '.cfs');
        $cfsFile->writeVInt(count($this->_files));

        $dataOffsetPointers = array();
        foreach ($this->_files as $fileName) {
            $dataOffsetPointers[$fileName] = $cfsFile->tell();
            $cfsFile->writeLong(0); // write dummy data
            $cfsFile->writeString($fileName);
        }

        foreach ($this->_files as $fileName) {
            // Get actual data offset
            $dataOffset = $cfsFile->tell();
            // Seek to the data offset pointer
            $cfsFile->seek($dataOffsetPointers[$fileName]);
            // Write actual data offset value
            $cfsFile->writeLong($dataOffset);
            // Seek back to the end of file
            $cfsFile->seek($dataOffset);

            $dataFile = $this->_directory->getFileObject($fileName);

            $byteCount = $this->_directory->fileLength($fileName);
            while ($byteCount > 0) {
                $data = $dataFile->readBytes(min($byteCount, 131072 /*128Kb*/));
                $byteCount -= strlen($data);
                $cfsFile->writeBytes($data);
            }

            $this->_directory->deleteFile($fileName);
        }
    }