read access token from file

@return string
@throws \Simple\Filesystem\FileNotFoundException
510784
protected function readAccessToken()
    {
        if (!$this->getFileSystem()->isFile($this->getTokenFilePath())) {
            return '';
        }

        $content = trim($this->getFileSystem()->get($this->getTokenFilePath()));
        $result = json_decode($content, true);

        if (isset($result['token']) && isset($result['expire']) && isset($result['time'])) {
            $expireTime = $result['time'] + $result['expire'] - self::TOKEN_EXPIRE_SUB_TIME;
            if ($expireTime > time()) {
                return $result['token'];
            }
        }

        return '';
    }
74669
public function readToken()
    {
        if ($this->file === null) {
            throw new BuildException("No File set for IniFileTokenReader");
        }

        if ($this->tokens === null) {
            $this->processFile();
        }

        if (count($this->tokens) > 0) {
            return array_pop($this->tokens);
        } else {
            return null;
        }
    }
1216420
public function getAsString()
	{
		$permissions	= @fileperms( $this->pathName );
		if( FALSE === $permissions )
			throw new InvalidArgumentException( 'Could not get permissions of file "'.$this->pathName.'"' );
		return self::getStringFromOctal( $permissions );
	}
154734
public function getAccessToken()
    {
        if ($this->accessToken === null) {
            $headers = array('Content-Type' => 'application/x-www-form-urlencoded');
            $content = array(
                'grant_type'     => 'assertion',
                'assertion_type' => 'http://oauth.net/grant_type/jwt/1.0/bearer',
                'assertion'      => $this->generateJsonWebToken(),
            );

            $response = json_decode($this->httpAdapter->postContent($this->url, $headers, $content));

            if (isset($response->error)) {
                throw GoogleAnalyticsException::invalidAccessToken($response->error);
            }

            $this->accessToken = $response->access_token;
        }

        return $this->accessToken;
    }
693255
public function getAccessToken()
    {
        $session = $this->getClient()->getConnector()->getSession();
        $token = $session->get('accessToken');
        $expires = $session->get('expires');
        if (!$token || $expires < time()) {
            // Force a connection to the API to ensure there is an access token.
            $this->getMyAccount(true);
            if (!$token = $session->get('accessToken')) {
                throw new \RuntimeException('No access token found');
            }
        }

        return $token;
    }
104890
public function getToken(): string
    {
        return $this->cache->remember($this->tokenKey, $this->tokenTTL, function () {
            return $this->fetchToken();
        });
    }
1069322
public function readToken(): Token
    {
        if ($this->getBuffer()->isEnd()) {
            try {
                $token = $this
                    ->getScanner()
                    ->readToken();
            } catch (UnknownSyntaxException $e) {
                throw new UnknownSyntaxException(
                    "Unknown syntax error near position #{$this->getNextPosition()}",
                    $this->getNextPosition(),
                    $e
                );
            }
            $this->assertErrorToken($token);
            $this
                ->getBuffer()
                ->addToken($token);
        }
        return $this
            ->getBuffer()
            ->readToken();
    }
22214
private function getTokenFilePath()
    {
        if ($this->tokenDirectory === null) {
            throw new \Dropbox\Exception('OAuth token directory not set. See Filesystem::setDirectory()');
        } else {
            return $this->tokenDirectory . '/' . md5($this->userID) . '.token';
        }
    }
744139
protected function readFile()
	{
		// construct the session file name
		$file = $this->config['file']['path'].$this->config['file']['cookie_name'].'_'.$this->sessionId;

		if (is_file($file) and $handle = fopen($file,'r'))
		{
			// wait for a lock
			while ( ! flock($handle, LOCK_SH));

			if ($size = filesize($file))
			{
				// read the session data
				$payload = fread($handle, $size);
			}
			else
			{
				// file exists, but empty?
				$payload = false;
			}

			//release the lock
			flock($handle, LOCK_UN);

			// close the file
			fclose($handle);

			// return the loaded payload
			return $payload;
		}

		// session file did not exist or could not be opened
		return false;
	}
50279
public function nextToken()
    {
        if ($this->lookahead !== null) {
            $token = $this->lookahead;

            $this->lookahead = null;
        } else {
            $token = trim(array_shift($this->tokens));
        }


        if (strlen($token) === 1 && Character::isLetter($token{0})
            && $this->dosStyleFilesystem
            && !empty($this->tokens)
        ) {
            // we are on a dos style system so this path could be a drive

            // spec. We look at the next token

            $nextToken = trim(array_shift($this->tokens));

            if (StringHelper::startsWith('\\', $nextToken) || StringHelper::startsWith('/', $nextToken)) {
                // we know we are on a DOS style platform and the next path

                // starts with a slash or backslash, so we know this is a

                // drive spec

                $token .= ':' . $nextToken;
            } else {
                // store the token just read for next time

                $this->lookahead = $nextToken;
            }
        }

        return $token;
    }
1322161
public function getAccessToken()
    {
        if (! $this->accessTokenEntity instanceof AccessTokenEntity) {
            $this->accessTokenEntity = $this->server->getAccessTokenStorage()->get($this->accessTokenId);
        }

        return $this->accessTokenEntity;
    }
150775
public function getToken()
    {
        if (Cache::has(self::CACHE_NAME)) {
            return Cache::get(self::CACHE_NAME);
        } else {
            $url    = $this->url."token";
            $option = [
                'grant_type'    => 'client_credentials',
                'client_id'     => $this->client_id,
                'client_secret' => $this->client_secret,
            ];
            $return = Http::postCurl($url, $option);
            Cache::put(self::CACHE_NAME, $return['access_token'], (int) ($return['expires_in'] / 60));

            return $return['access_token'];

        }
    }
618866
private function getAccessToken($email, $password, $clientConfig)
    {
        $oauth2Config = $clientConfig['oauth2'];
        $accessToken = null;

        // If there is a token file, try to read it and test the found token
        try {
            $filePath = array_key_exists('token_file_path', $oauth2Config) && !empty($oauth2Config['token_file_path'])
                ? $oauth2Config['token_file_path'] : '';

            if (file_exists($filePath)) {
                $data = file_get_contents($filePath);

                if (!empty($data)) {
                    $decodedData = json_decode($data);
                    $accessToken = $decodedData->access_token;

                    return $accessToken;
                }
            }
        } catch (\Exception $e) {
        }

        return $this->createAccessToken($email, $password, $clientConfig);
    }
162917
public function read()
    {

        // if file is readable
        if ($this->readable !== true) return false;

        if (!empty($this->fp) && is_resource($this->fp)) fclose($this->fp);

        $this->open_fp('r');

        if (filesize($this->file) == 0) return false;
        $this->lock(LOCK_SH);

        $content = (string)fread($this->fp, ($this->size >= 0) ? $this->size : 1);

        $this->lock(LOCK_UN);

        return $content;
    }
1250647
protected function getAccessToken()
    {
        switch ($this->grant) {
            case 'provided_token':
                return $this->token;

            case 'client_credentials':
                return $this->getFrameworkBridge()->getClientToken();

            case 'authorization_code':
                $user = $this->getFrameworkBridge()->getCurrentUser();

                if (! $user) {
                    return null;
                }

                return $user->getOAuthToken();

            default:
                throw new \Exception('Unsupported grant type. Check $this->grant.');
        }
    }
915070
public function getAccessToken()
    {
        if (is_string($this->access_token) && $this->isValidToken() ) {
            $this->accessToken = $this->token_type . ' ' . $this->access_token;

            return $this->accessToken;
        }

        return false;
    }
1298109
public function getAsString(): string
    {
        if ('php://stdin' !== $this->filename) {
            if (!file_exists($this->filename)) {
                throw new SourceException(sprintf('File "%s" not exists', $this->filename));
            }

            if (!is_readable($this->filename)) {
                throw new SourceException(sprintf('File "%s" is not readable', $this->filename));
            }
        }

        return file_get_contents($this->filename);
    }