Returns a token to use for the keystone service. Uses cached instance
whenever possible.

@param  Client  $client   The client
@param  boolean $forceNew Whether to force creating a new token
@return Token
761955
private function getToken(Client $client, $forceNew = false)
    {
        $tokenName = sprintf('keystone_token_%s', rawurlencode($client->getTokenUrl()));

        // see if token is in cache
        if (!$forceNew && $cachedToken = $this->cache->get($tokenName)) {
            $token = unserialize($cachedToken);
        }

        if (!isset($token) || !($token instanceof Token) || $this->tokenIsExpired($token)) {
            $token = $this->createToken($client);
            $this->cache->set($tokenName, serialize($token), $token->getExpirationDate()->getTimestamp() - time());
        }

        return $token;
    }
730480
public function client($client = null)
	{
		$client = $client ?: $this->getDefaultClient();

		// If the given driver has not been created before, we will create the instances
		// here and cache it so we can return it next time very quickly. If there is
		// already a driver created by this name, we'll just return that instance.
		if (!isset($this->routers[$client]))
		{
			$this->routers[$client] = $this->createRouter($client);
		}

		return $this->routers[$client];
	}
438430
protected function createLaravelDriver(): Sdk\Client
    {
        return \tap($this->createHttpClient(), function ($client) {
            if (isset($this->config['client_id']) || isset($this->config['client_secret'])) {
                $client->setClientId($this->config['client_id'])
                        ->setClientSecret($this->config['client_secret']);
            }

            if (isset($this->config['access_token'])) {
                $client->setAccessToken($this->config['access_token']);
            }
        });
    }
315605
public function getOpenedClient(ServiceAbstractClient $client = null)
    {
        if (!$client) {
            $client = new ServiceClient();
        }

        $client->open(
            $this->isProductionEnvironment() ? ServiceClient::PRODUCTION_URI : ServiceClient::SANDBOX_URI,
            $this->getParameter('certificate'),
            $this->getParameter('passPhrase')
        );

        return $client;
    }
461670
public function createCredentials(ClientCredentials $client)
    {
        return $this->createCommand()
            ->setRequest($this->client->post('credentials'))
            ->setBodyEntity($client, 'json')
            ->setResponseClass('Maba\OAuthCommerceInternalClient\Entity\ClientCredentials')
        ;
    }
247885
public static function push($config = null, $clientId, $accessToken, $tokenCreateTime, $tokenExpiresIn)
    {
        // Return if not enabled
        if (!self::isEnabled($config)) {
            return;
        }

        $cachePath = self::cachePath($config);
        if (!is_dir(dirname($cachePath))) {
            if (mkdir(dirname($cachePath), 0755, true) == false) {
                throw new \Exception("Failed to create directory at $cachePath");
            }
        }

        // Reads all the existing persisted data
        $tokens = self::pull();
        $tokens = $tokens ? $tokens : array();
        if (is_array($tokens)) {
            $tokens[$clientId] = array(
                'clientId' => $clientId,
                'accessTokenEncrypted' => $accessToken,
                'tokenCreateTime' => $tokenCreateTime,
                'tokenExpiresIn' => $tokenExpiresIn
            );
        }
        if (!file_put_contents($cachePath, json_encode($tokens))) {
            throw new \Exception("Failed to write cache");
        };
    }
376574
protected function setToken(Client $client)
    {
        $token = getenv('BOWERPHP_TOKEN');
        if (!empty($token)) {
            $client->authenticate($token, null, Client::AUTH_HTTP_TOKEN);
        }
    }
552924
public static function createNewRefreshToken(
        int $ttl,
        TokenOwnerInterface $owner = null,
        Client $client = null,
        $scopes = null
    ): RefreshToken {
        return static::createNew($ttl, $owner, $client, $scopes);
    }
454164
public function getToken($forceRefresh = false)
    {
        $cached = $this->getCache()->fetch($this->getCacheKey()) ?: $this->token;

        if ($forceRefresh || empty($cached)) {

            $result = $this->getTokenFromServer();

            $this->checkTokenResponse($result);

            $this->setToken(
                $token = $result[$this->tokenJsonKey],
                $this->expiresJsonKey ? $result[$this->expiresJsonKey] : null
            );

            return $token;
        }

        return $cached;
    }
794907
public function client($client = null)
    {
        if ($client === null) {
            return $this->getClient();
        }

        return $this->setClient($client);
    }
1178142
public function getFormToken($forceNew = false) {
	   
        return md5($this->get('secret') . $this->getSession()->getToken($forceNew));    
    }
599474
public static function pull($config = null, $clientId = null)
    {
        // Return if not enabled
        if (!self::isEnabled($config)) {
            return null;
        }

        $tokens = null;
        $cachePath = self::cachePath($config);
        if (file_exists($cachePath)) {
            // Read from the file
            $cachedToken = file_get_contents($cachePath);
            if ($cachedToken && JsonValidator::validate($cachedToken, true)) {
                $tokens = json_decode($cachedToken, true);
                if ($clientId && is_array($tokens) && array_key_exists($clientId, $tokens)) {
                    // If client Id is found, just send in that data only
                    return $tokens[$clientId];
                } else if ($clientId) {
                    // If client Id is provided, but no key in persisted data found matching it.
                    return null;
                }
            }
        }
        return $tokens;
    }
346354
public static function GetService($wsdl, $forceNuSoap = false)
	{
		if (extension_loaded("soap") && !$forceNuSoap)
		{
			Debug::PrintValue("Local");
			$client = new SoapClient($wsdl);
			return $client;
		}
		else 
		{
			Debug::PrintValue("NuSoap");
			if (!SoapClientWrapper::$_readed)
			{
				//Debug::PrintValue("Read NuSoap");
		    	require_once("nusoap.php");
		    	SoapClientWrapper::$_readed = true;
			}
			$client = new nusoap_client($wsdl, 'wsdl');
			$proxy = $client->getProxy();
			return $proxy;
		}
	}
1318365
private function getToken($token, &$hasSeenBy)
    {
        switch ($token) {
            case 'And':
                return new AndToken();
            case 'Or':
                return new OrToken();
            case 'By':
            case 'Where':
                $hasSeenBy = true;
                return new ByToken();
            case 'All':
                return new AllToken();
            case 'Distinct':
                if ($hasSeenBy) {
                    return new ValueToken($token);
                } else {
                    return new DistinctToken();
                }
            case 'Like':
                if ($hasSeenBy) {
                    return new LikeToken();
                } else {
                    return new ValueToken($token);
                }
            default:
                return new ValueToken($token);
        }
    }
558966
public function getToken($refresh = false)
    {
        if ($refresh || empty($this->_token)) {
            $data = ['grant_type' => 'client_credentials'];
            $this->_token = $this->_request(self::URN_ISSUE, $data);

            // check for valid response
            if (empty($this->_token->access_token)) {
                throw new AuthException('Unexpected empty token from the authentication server');
            }
        }
        return $this->_token;
    }
714896
public function refresh(Token $token, $forceForever = false, $resetClaims = false)
    {
        $this->setRefreshFlow();

        $claims = $this->buildRefreshClaims($this->decode($token));

        if ($this->blacklistEnabled) {
            // Invalidate old token
            $this->invalidate($token, $forceForever);
        }

        // Return the new token
        return $this->encode(
            $this->payloadFactory->customClaims($claims)->make($resetClaims)
        );
    }
384485
public function createClientUrl($client)
    {
        $this->autoRender = false;
        $url = $this->getBaseAuthUrl();
        $url[$this->clientIdGetParamName] = $client->getId();

        return Url::to($url);
    }