Request an access token using the Client Credentials Flow.

@return bool True when an access token was successfully granted, false otherwise.
483317
public function requestCredentialsToken()
    {
        $payload = base64_encode($this->getClientId() . ':' . $this->getClientSecret());

        $parameters = [
            'grant_type' => 'client_credentials',
        ];

        $headers = [
            'Authorization' => 'Basic ' . $payload,
        ];

        $response = $this->request->account('POST', '/api/token', $parameters, $headers);
        $response = $response['body'];

        if (isset($response->access_token)) {
            $this->accessToken = $response->access_token;
            $this->expirationTime = time() + $response->expires_in;
            $this->scope = isset($response->scope) ? $response->scope : $this->scope;

            return true;
        }

        return false;
    }
220111
public function authorize()
    {
        $path = $this->endpoint.self::OAUTH_TOKEN;
        $headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
        $body = [
            'client_id'     => $this->client_id,
            'client_secret' => $this->client_secret,
            'grant_type'    => self::GRANT_TYPE,
            'code'          => $this->code,
            'redirect_uri'  => $this->redirect_uri,
        ];

        try {
            $http_response = $this->createNewSession()->request($path, $headers, $body, 'POST');
        } catch (Requests_Exception $e) {
            throw new UnexpectedException($e);
        }

        if ($http_response->status_code >= 200 && $http_response->status_code < 300) {
            return json_decode($http_response->body);
        } elseif ($http_response->status_code >= 400 && $http_response->status_code <= 499) {
            throw new ValidationException($http_response->status_code, $http_response->body);
        }

        throw new UnexpectedException();
    }
375736
public function getAccessTokenByClientCredentials(array $params = array())
    {
        $params = array(
            'grant_type' => 'client_credentials',
            'client_id' => $this->getClientId(),
            'client_secret'	=> $this->getClientSecret(),
        ) + $params;
        $request = $this->request('GET', 'oauth/2.0/token', $params);
        return $request->response()->getJson(true);
    }
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;
    }
1143792
public function acquireAccessToken() {
    $grant = new PasswordGrant($this->clientId, $this->clientSecret, $this->username, $this->password, $this->scopes);
    $tokens = $grant->getTokens();

    $accessToken = $tokens->{"access_token"};
    $refreshToken = $tokens->{"refresh_token"};
    $expiresAt = Util::calculateExpiryTime($tokens->{"expires_in"});

    return new RefreshableAccessToken($this->clientId, $this->clientSecret, $accessToken, $expiresAt, $refreshToken);
  }
662237
public function getAccessToken()
    {
        // Get the signed request URL
        $response = $this->fetch('POST', API::API_URL, self::ACCESS_TOKEN_METHOD);
        $token = $this->parseTokenString($response['body']);
        $this->storage->set($token, 'access_token');
    }
44670
public function getOauthAccessToken(){
        $code = isset($_GET['code'])?$_GET['code']:'';
        if (!$code) return false;
        $result = $this->http_get(self::API_BASE_URL_PREFIX.self::OAUTH_TOKEN_URL.'appid='.$this->appid.'&secret='.$this->appsecret.'&code='.$code.'&grant_type=authorization_code');
        if ($result)
        {
            $json = json_decode($result,true);
            if (!$json || !empty($json['errcode'])) {
                $this->errCode = $json['errcode'];
                $this->errMsg = $json['errmsg'];
                return false;
            }
            $this->user_token = $json['access_token'];
            return $json;
        }
        return false;
    }
995467
public function getAccessToken()
    {
        // check in the session
        $existing = $this->storage->getKey('authentication');

        // is it still valid
        if ($existing && $existing->expires > time()) {
            return $existing->access_token;
        }

        // make the call to the API
        $authResponse = $this->makeAuthenticationCall();

        // save the access token result
        $this->storage->setKey('authentication', $authResponse->getRaw());

        // return the token
        return $authResponse->getRaw()->access_token;
    }
41284
private function getAccessToken()
    {
        if ($this->provider === null)
            throw new EmptyProviderException();
        $this->getLogger()->debug('Checking Access token and requesting a new one if necessary');
        if ($this->token == null || $this->token->hasExpired() || $this->token->getExpires() <= time() + 10) {
            // Get and store a new token
        $this->getLogger()->info('Getting a new Access Token');
            $this->token = $this->provider->getAccessToken('client_credentials');
        }
        else {
            $this->token = $this->token;
        }
        return $this->token;
    }
608893
protected function authenticate()
    {
        if ((!$this->storage->get('access_token'))) {
            try {
                $this->getAccessToken();
            } catch(\Dropbox\Exception $e) {
                $this->getRequestToken();
                $this->authorise();
            }
        }
    }
1049488
public function getAccessToken() {
		$time = time();
		if(empty($this->app->access_token) || $this->app->access_token_expired_at < $time) {
			$data = $this->getData('/cgi-bin/token', [
				'grant_type' => 'client_credential',
				'appid' => $this->app->appid,
				'secret' => $this->app->secret,
			]);
			if(isset($data['access_token']) && isset($data['expires_in'])) {
				$this->app->access_token = $data['access_token'];
				$this->app->access_token_expired_at = $time + $data['expires_in'];
				$this->app->save();
			}
		}

		return $this->app->access_token;
	}
32747
protected function getOAuthToken() {
        # TODO: use session to store the token
        if ($this->client_id and $this->client_secret) {
            $response = $this->httpQuery(
                'POST', 'https://orcid.org/oauth/token',
                [
                    'Accept' => 'application/json',
                    'Content-Type' => 'application/x-www-form-urlencoded'
                ],
                http_build_query([
                  'client_id' => $this->client_id,
                  'client_secret' => $this->client_secret,
                  'scope' => '/read-public',
                  'grant_type' => 'client_credentials',
                ])
            );

            if ($response) {
                return $response->{'access_token'};
            }
        }
    }
725993
public function exchange() {
        if ($this->isExpire()) {
            return false;
        }
        return OAuthAccessTokenModel::createToken($this->client_id, $this->user_id);
    }
722458
public function requestAccessToken()
    {
        $config = $this->getConfig();

        $token_url = $config['urls']['token'];
        $params = array();
        $params['client_id'] = $config['api_key'];
        $params['redirect_uri'] = $this->getRedirect();
        $params['code'] = $this->getCode();
        $params['grant_type'] = 'authorization_code';
        $params['client_secret'] = $config['secret_key'];

        //get access token
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $token_url);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  // don't worry about bad ssl certs
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));  // @todo why post a get query?

        $response = curl_exec($ch);

        if (!$response) {
            throw new \Exception('no response from linkedin');
        }

        $response = json_decode($response);
        if (!isset($response->access_token) || !$response->access_token) {
            throw new \Exception('no access token received from linkedin');
        }

        $this->setAccessToken($response->access_token);

        return (string) $response->access_token;
    }
54818
protected function passesAuthorization(): bool
    {
        $passes = false;

        if (\method_exists($this, 'authorize')) {
            $passes = $this->container->call([$this, 'authorize']);
        }

        return (bool) $passes;
    }
230784
public function getAccessToken($access_token)
	{
		// create access token
		$token = \Components\Developer\Models\Accesstoken::oneByToken($access_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(true);
	}
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()
      );
    }
  }