Performs discovery request and gets the token
@return $this|bool
969847
public function clientCredentials()
    {
        if (! $this->credentials) {
            // $this->credentials = new ClientCredentials;
            $this->credentials = new Credentials('client_credentials');

            // Get API endpoints
            $this->endpointDiscovery();

            // Acquire the tokens and expiration and save
            $body = $this->acquireToken();
            $this->credentials->set($body);

            // Add credentials to the cache
            $creds = serialize($this->credentials);
            $expiration = $this->credentials->getExpiration();
            $this->cache->put($this->cacheKey, $creds, $expiration );
        }

        return $this;
    }
101110
private function getRequest() {

        $token = $this->getParam('token');

        if (empty($token)) {
            throw new ConfigurationException(__CLASS__ . ' is not configured properly. Please set "token" parameter properly.');
        }

        $request = new Request();
        $request->setUri($this->url);
        $request->setMethod(Request::METHOD_POST);

        $request->getHeaders()->addHeaders(array(
          'accept' => 'application/json',
          'content-type' => 'application/json',
          'authorization' => 'Basic ' . $token
        ));

        return $request;
    }
590213
public function getMeAction()
    {
        $tokenManager = $this->get('fos_oauth_server.access_token_manager');


        $accessToken = $tokenManager->findTokenByToken(
            $this->get('security.context')->getToken()->getToken()
        );
        /* @var $me UserInterface */
        $me = $accessToken->getUser();

        if (null === $me) {
            throw new NotFoundHttpException('User is null.');
        }
        if (false === $me instanceof UserInterface) {
            throw new NotFoundHttpException('User not found.');
        }

        return new JsonResponse([
            'objectId' => $me->getId()
            , 'userName' => $me->getUsername()]);
    }
492966
public function getToken()
    {
        if (!isset($this->token)) {
            $this->token = $this->csrf->getToken();
        }

        return $this->token;
    }
876962
public function tokenAction()
    {
        $request = $this->getRequest();
        if (! $request instanceof HttpRequest) {
            // not an HTTP request; nothing left to do
            return;
        }

        if ($request->isOptions()) {
            // OPTIONS request.
            // This is most likely a CORS attempt; as such, pass the response on.
            return $this->getResponse();
        }

        $oauth2request = $this->getOAuth2Request();
        
        $response = $this->server->handleTokenRequest($oauth2request);
        if ($response->isClientError()) {
            $parameters = $response->getParameters();
            $errorUri   = isset($parameters['error_uri']) ? $parameters['error_uri'] : null;
            return new ApiProblemResponse(
                new ApiProblem(
                    $response->getStatusCode(),
                    $parameters['error_description'],
                    $errorUri,
                    $parameters['error']
                )
            );
        }
        return $this->setHttpResponse($response);
    }
463014
public function getRequest()
    {
        if (is_null($this->request)) {
            $this->setRequest(app()->refresh('request', $this, 'setRequest'));
        }

        return $this->request;
    }
1318178
public function getUrlGenerator()
    {
        if (!$this->urlGenerator) {
            $this->urlGenerator = new DiscoveryUrlGenerator(
                $this->getPuli()->getDiscovery(),
                $this->getInstallTargetManager()->getTargets()
            );
        }

        return $this->urlGenerator;
    }
779781
public function token()
    {
        if (empty($this->csrfToken) && !is_null($this->session)) {
            $this->csrfToken = $this->session->token();
        }

        return $this->hidden('_token', $this->csrfToken);
    }
532094
public function getTokenForRequest()
    {
        if (!$this->jwt->isHealthy() && $this->request->headers->has('Authorization')) {
          list($jwt_token) = sscanf( $this->request->headers->get('Authorization'), 'Bearer %s');
          $this->jwt->setToken($jwt_token);
        }

        return $this->jwt->getToken();
    }
292473
protected function fetchRequestToken()
    {
        // Fetching a new request token. Remove any old access tokens.
        $this->storage->delete(static::BIB_ACCESS_TOKEN);
        // Fetch a request token.
        $token = $this->consumer->getRequestToken();
        // Persist the token to storage.
        $this->storage->set(static::BIB_REQUEST_TOKEN, $token);

        return $this;
    }
1037998
public function getRequest()
    {
        if ($this->request === null) {
            $this->request = Request::createFromGlobals();
        }

        return $this->request;
    }
840394
public function getToken()
    {
        if(isset($this->_tokens[$this->_position])) {
            return $this->_tokens[$this->_position];
        } else {
            return null;
        }
    }
1284477
public function authenticate() {
    $this->getClient()->authenticate($this->getApiToken(), \Github\Client::AUTH_HTTP_TOKEN);
    return $this;
  }
109899
protected function getTokenData() {
    $result = null;

    $request = ObjectFactory::getInstance('request');
    $token = $request->hasHeader(self::TOKEN_HEADER) ?
        trim(str_replace(self::AUTH_TYPE, '', $request->getHeader(self::TOKEN_HEADER))) : $this->token;
    if ($token !== null) {
      $jwt = (new Parser())->parse((string)$token);

      // validate
      $data = new ValidationData();
      $data->setIssuer($this->getTokenIssuer());
      if ($jwt->validate($data) && $jwt->verify($this->getTokenSigner(), $this->key)) {
        $result = $jwt->getClaims();
      }
    }
    return $result;
  }
89734
protected function acquireAccessToken()
    {
        $accessToken = null;

        if ($this->refreshTokenGrantType) {
            // Get an access token using the stored refresh token.
            if ($this->refreshToken) {
                $this->refreshTokenGrantType->setRefreshToken($this->refreshToken->getToken());
            }
            if ($this->refreshTokenGrantType->hasRefreshToken()) {
                $accessToken = $this->refreshTokenGrantType->getToken();
            }
        }

        if (!$accessToken && $this->grantType) {
            // Get a new access token.
            $accessToken = $this->grantType->getToken();
        }

        return $accessToken ?: null;
    }
990171
public function acquireAccessToken()
  {
    $request = new Request(
        self::METADATA_AUTH_URL,
        'GET',
        array(
          'Metadata-Flavor' => 'Google'
        )
    );
    $request->disableGzip();
    $response = $this->client->getIo()->makeRequest($request);

    if ($response->getResponseHttpCode() == 200) {
      $this->setAccessToken($response->getResponseBody());
      $this->token['created'] = time();
      return $this->getAccessToken();
    } else {
      throw new Exception(
          sprintf(
              "Error fetching service account access token, message: '%s'",
              $response->getResponseBody()
          ),
          $response->getResponseHttpCode()
      );
    }
  }
1343486
protected function getToken()
    {
        if (!$this->isStateless()) {
            $temp = $this->request->getSession()->get('oauth.temp');

            return $this->server->getTokenCredentials(
                $temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier')
            );
        }
        $temp = unserialize($this->request->session()->get('oauth_temp'));

        return $this->server->getTokenCredentials(
                $temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier')
            );
    }