Get an auth token for these client credentials

@param bool $refresh whether to force fetching a new token
@return \StdClass the auth token object
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;
    }
13557
public function getRefreshToken($refresh_token)
	{
		// create refresh token
		$token = \Components\Developer\Models\Refreshtoken::oneByToken($refresh_token);

		// make sure we have a token
		if (!$token->get('id'))
		{
			return false;
		}

		// make sure its a published token
		if (!$token->isPublished())
		{
			return false;
		}

		// get the application's client id
		$application = \Components\Developer\Models\Application::oneOrFail($token->get('application_id'));
		$token->set('client_id', $application->get('client_id'));

		// format expires to unix timestamp
		$token->set('expires', with(new Date($token->get('expires')))->toUnix());

		// return token
		return $token->toArray();
	}
681205
protected function refreshToken()
    {
        $token = $this->authorization->getApi()
                                     ->getAuthorizerToken(
                                         $this->authorization->getAuthorizerCorpId(),
                                         $this->authorization->getAuthorizerPermanentCode()
                                     );

        $this->authorization->setAuthorizerAccessToken($token['access_token'], $token['expires_in'] - 1500);

        return $token['access_token'];
    }
783281
public function getConfig($refresh = false)
    {
        return $this->getCache('plugins-config', $refresh, function () {
            return [
                'wei' => [
                    'aliases' => $this->getWeiAliases(),
                ],
                'app' => [
                    'controllerMap' => $this->getAppControllerMap(),
                ],
                'plugin' => [
                    'pluginClasses' => $this->getPluginClasses(true),
                ],
            ];
        });
    }
1354463
public function getFileCollection($refresh = false)
    {
        if ($refresh || !is_object($this->_fileCollection)) {
            $this->_fileCollection = Yii::createObject([
                'class' => 'yii\mongodb\Collection',
                'database' => $this->database,
                'name' => $this->name
            ]);
        }

        return $this->_fileCollection;
    }
780466
public function refresh($refresh = true)
    {
        $this->unitOfWorkHints[Query::HINT_REFRESH] = (boolean) $refresh;
        return $this;
    }
655806
public function refreshToken($forceRefresh = false)
    {
        if (property_exists($this, "sdl") && $this->sdl == 0) {
            parent::__construct($this->xmlLoc, array('trace'=>1, 'exceptions'=>0));
        }
        try {
            $currentTime = new DateTime();
            if (is_null($this->getAuthTokenExpiration($this->tenantKey))) {
                $timeDiff = 0;
            } else {
                $timeDiff = $currentTime->diff($this->getAuthTokenExpiration($this->tenantKey))->format('%i');
                $timeDiff = $timeDiff  + (60 * $currentTime->diff($this->getAuthTokenExpiration($this->tenantKey))->format('%H'));
            }
            if (is_null($this->getAuthToken($this->tenantKey)) || ($timeDiff < 5) || $forceRefresh) {
                $url = $this->tenantKey == null
                        ? $this->baseAuthUrl."/v1/requestToken?legacy=1"
                        : $this->baseUrl."/provisioning/v1/tenants/{$this->tenantKey}/requestToken?legacy=1";

                $jsonRequest = new stdClass();
                $jsonRequest->clientId = $this->clientId;
                $jsonRequest->clientSecret = $this->clientSecret;
                $jsonRequest->accessType = "offline";
                if (!is_null($this->getRefreshToken($this->tenantKey))) {
                    $jsonRequest->refreshToken = $this->getRefreshToken($this->tenantKey);
                }
                $authResponse = ET_Util::restPost($url, json_encode($jsonRequest), $this);
                $authObject = json_decode($authResponse->body);
                //echo "auth:  \n";
                //print_r($authResponse);

                if ($authResponse && property_exists($authObject, "accessToken")) {
                    $dv = new DateInterval('PT'.$authObject->expiresIn.'S');
                    $newexpTime = new DateTime();
                    $this->setAuthToken($this->tenantKey, $authObject->accessToken, $newexpTime->add($dv));
                    $this->setInternalAuthToken($this->tenantKey, $authObject->legacyToken);
                    if (property_exists($authObject, 'refreshToken')) {
                        $this->setRefreshToken($this->tenantKey, $authObject->refreshToken);
                    }
                } else {
                    throw new Exception('Unable to validate App Keys(ClientID/ClientSecret) provided, requestToken response:'.$authResponse->body);
                }
            }
        } catch (Exception $e) {
            throw new Exception('Unable to validate App Keys(ClientID/ClientSecret) provided.: '.$e->getMessage());
        }
    }
84476
public function get($token)
    {
        $result = $this->getConnection()->table('oauth_refresh_tokens')
                ->where('oauth_refresh_tokens.id', $token)
                ->where('oauth_refresh_tokens.expire_time', '>=', time())
                ->first();

        if (is_null($result)) {
            return;
        }

        return (new RefreshTokenEntity($this->getServer()))
               ->setId($result->id)
               ->setAccessTokenId($result->access_token_id)
               ->setExpireTime((int) $result->expire_time);
    }
344242
public function getChunkCollection($refresh = false)
    {
        if ($refresh || !is_object($this->_chunkCollection)) {
            $this->_chunkCollection = Yii::createObject([
                'class' => 'yii\mongodb\Collection',
                'database' => $this->database,
                'name' => $this->getPrefix() . '.chunks'
            ]);
        }

        return $this->_chunkCollection;
    }
507383
public function setRefreshToken($refreshToken = null)
    {
        $this->refreshToken = null === $refreshToken
            ? bin2hex(openssl_random_pseudo_bytes(64))
            : $refreshToken;

        return $this;
    }
1303390
public function getAccess($code, $refreshToken = false)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');

        //populate fields
        $query = array(
            'client_id'         => $this->client,
            'client_secret'     => $this->secret,
            'redirect_uri'  => $this->redirect,
            'grant_type'    => $this->grantType);

        return $this->generateAccess($query, $code, $refreshToken);
    }
327541
public function exchangeRefreshToken($refreshToken)
    {
        return $this->client->exchangeRefreshToken(
            $refreshToken,
            $this->clientId,
            $this->clientSecret
        );
    }
375917
public function getBrowser($refresh = false)
    {
        if (empty($this->detection['browser']) || $refresh) {
            $this->detectBrowser($this->userAgent);
        }

        return $this->browser;
    }
661534
public function getChunkCursor($refresh = false)
    {
        if ($refresh || $this->_chunkCursor === null) {
            $file = $this->getDocument();
            $this->_chunkCursor = $this->collection->getChunkCollection()->find(
                ['files_id' => $file['_id']],
                [],
                ['sort' => ['n' => 1]]
            );
        }
        return $this->_chunkCursor;
    }
1372041
public function getIndexNames($refresh = false)
    {
        if (!isset($this->_indexNames) || $refresh) {
            $this->initIndexesInfo();
        }

        return $this->_indexNames;
    }
782496
public function refreshToken($refreshToken)
	{
		$this->result = $this->http->get($this->getUrl('sns/oauth2/refresh_token', array(
			'appid'			=>	$this->appid,
			'grant_type'	=>	'refresh_token',
			'refresh_token'	=>	$refreshToken,
		)))->json(true);
		return isset($this->result['errcode']) && 0 == $this->result['errcode'];
	}
750294
public function refreshToken()
    {
        if (is_null($this->token) || is_null($this->token->getRefreshToken())) {
            return null;
        }

        $grant = new RefreshToken();
        $refreshToken = $this->provider->getAccessToken($grant, [
            'refresh_token' => $this->token->getRefreshToken()
        ]);

        $this->token = $refreshToken;


        return $this->token;
    }