Exchange an authorized request token for new access token.

@param string token
@param array options		options for the token, token_ttl
@exception OAuthException2 when token could not be exchanged
@return array (token, token_secret)
328675
public function exchangeConsumerRequestForAccessToken ( $token, $options = array() )
	{
		$new_token  = $this->generateKey(true);
		$new_secret = $this->generateKey();
		
		$sql = "BEGIN SP_EXCH_CONS_REQ_FOR_ACC_TOKEN(:P_TOKEN_TTL, :P_NEW_TOKEN, :P_TOKEN, :P_TOKEN_SECRET, :P_VERIFIER, :P_OUT_TOKEN_TTL, :P_RESULT); END;";

			// parse sql
		$stmt = oci_parse($this->conn, $sql) or die ('Can not parse query');

		// Bind In and Out Variables
		oci_bind_by_name($stmt, ':P_TOKEN_TTL', $options['token_ttl'], 255);
		oci_bind_by_name($stmt, ':P_NEW_TOKEN', $new_token, 255);
		oci_bind_by_name($stmt, ':P_TOKEN', $token, 255);
		oci_bind_by_name($stmt, ':P_TOKEN_SECRET', $new_secret, 255);
		oci_bind_by_name($stmt, ':P_VERIFIER', $options['verifier'], 255);
		oci_bind_by_name($stmt, ':P_OUT_TOKEN_TTL', $ttl, 255);
		oci_bind_by_name($stmt, ':P_RESULT', $result, 20);


		//Execute the statement
		oci_execute($stmt);

		$ret = array('token' => $new_token, 'token_secret' => $new_secret);
		if (is_numeric($ttl))
		{
			$ret['token_ttl'] = intval($ttl);
		}
		return $ret;
	}
397139
function assertToken($tokenStr)
    {
        if (false === $token = $this->_accessTokens->findByIdentifier((string) $tokenStr))
            throw new exOAuthAccessDenied;


        $accessToken = new AccessTokenEntity(
            new HydrateGetters($token) );

        return $accessToken;
    }
571663
protected function refreshAccessToken($token)
    {
        switch ($this->grant) {
            case 'provided_token':
                throw new UnauthorizedException('[internal]', 'The provided token expired.');

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

            case 'authorization_code':
                return $this->getTokenByRefreshTokenGrant($token);

            default:
                throw new \Exception('Unsupported grant type. Check $this->grant.');
        }
    }
574357
public static function authenticateWithToken($token) {
    $pkeyResource = openssl_pkey_new(array(
      "digest_alg" => "sha256",
      "private_key_bits" => 2048
    ));

    openssl_pkey_export($pkeyResource, $generatedPrivateKey);

    $pkeyResourceDetails = openssl_pkey_get_details($pkeyResource);
    $generatedPublicKey = $pkeyResourceDetails["key"];

    $requestResult = Request::post("/g_business/v1/authentication_keys", array(
      "body" => array(
        "public_key" => $generatedPublicKey,
        "token" => $token
      )
    ));

    self::$privateKey = $generatedPrivateKey;
    self::$publicKey = $generatedPublicKey;
    self::$keyId = $requestResult->key_id;

    $returnClass = new ApiAuthentication();
    $returnClass->privateKey = $generatedPrivateKey;
    $returnClass->publicKey = $generatedPublicKey;
    $returnClass->keyId = $requestResult->key_id;
    return $returnClass;
  }
261506
public function generateUrl($url, $token, $options, $availableOptions)
    {

        // Append client id
        $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').'client_id='.$this->getClientId();

        // Append token if provided
        if ($token) {
            $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').'oauth_token='.$this->getToken($token);
        }

        // Add options to the URL
        foreach ($options as $key => $value) {
            $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').$key.'='.$value;
        }

        return $url;
    }
733169
public static function getValidToken(
        ContextInterface $context,
        AccessToken $token = null,
        array $scopes = null,
        array $options = []
    ): AccessToken
	{
		if ($token === null || !$token->isValid()) {
            $token = AuthenticationHelper::getAccessToken($context, $scopes, $options);
		}

		return $token;
	}
810286
public function request($method = 'GET', $uri = '', $options = [])
    {
        try {
            // Make the request.
            return $this->getClient()->request($method, $uri, $this->getRequestOptions($options));
        } catch (ClientException $e) {
            // We are using token auth and probably token expired.
            if ($this->authMethod == 'token' && $e->getCode() == 401 && ! $this->isThrottledReached()) {
                // Try refresh token.
                $this->fetchToken(true);

                // Try requesting again.
                return $this->request($method, $uri, $options);
            }
            // Clear throttle for this request.
            $this->clearThrottle();
            // Call Failed Request.
            $this->failedRequest($e->getResponse());
        }
    }
596339
def oauth_token_exchange_cli(client_id, client_secret, redirect_uri,
                             base_url=OH_BASE_URL, code=None,
                             refresh_token=None):
    
    print(oauth2_token_exchange(client_id, client_secret, redirect_uri,
                                base_url, code, refresh_token))
931408
public static function getPayload(string $token, string $secret): array
    {
        $parser = self::parser($token, $secret);

        return $parser->validate()->parse()->getPayload();
    }
597745
public function AccessToken($Token = NULL, $Secret = NULL) {
      if (!$this->IsConfigured()) 
         return FALSE;
      
      if (is_object($Token)) {
         $this->_AccessToken = $Token;
      } if ($Token !== NULL && $Secret !== NULL) {
         $this->_AccessToken = new OAuthToken($Token, $Secret);
//         setcookie('tw_access_token', $Token, 0, C('Garden.Cookie.Path', '/'), C('Garden.Cookie.Domain', ''));
      } elseif ($this->_AccessToken == NULL) {
//         $Token = GetValue('tw_access_token', $_COOKIE, NULL);
         if ($Token)
            $this->_AccessToken = $this->GetOAuthToken($Token);
         elseif (Gdn::Session()->User) {
            $AccessToken = GetValueR(self::ProviderKey.'.AccessToken', Gdn::Session()->User->Attributes);
            
            if (is_array($AccessToken)) {
               $this->_AccessToken = new OAuthToken($AccessToken[0], $AccessToken[1]);
            }
         }
      }
      return $this->_AccessToken;
   }
1197389
public function getToken($token = null)
    {
        if ($token != null) {

            return $token;
        }

        if ($this->token == null) {

            throw new RequestRequiresAuthenticationException();
        }

        return $this->token;
    }
591590
public function executeRequest($method, $url, $token, $body = null)
    {
        $options = [];
        if ($body) {
            $options['body'] = json_encode($body);
            $options['headers']['Content-Type'] = 'application/json';
        }

        $request = $this->getAuthenticatedRequest($method, $this->apiDomain.'/'.$this->version.$url, $token, $options);

        return $this->getParsedResponse($request);
    }
556141
public function requestClientCredentials($options = array()) {
        $options = array_merge(array(
            'scope' => '',
        ), $options);

        $res = $this->sendRequest('POST', $this->getUrl('oauth', 'token'), array(
            'client_id' => $this->getClientId(),
            'client_secret' => $this->getClientSecret(),
            'grant_type' => 'client_credentials',
            'scope' => $options['scope'],
        ));
        $result = $res->getBody();

        $token = null;
        if ($result && $result = json_decode($result, true)) {
            if (!empty($result['error'])) {
                throw new Exception($result['error_description']);
            }

            if (!empty($result['access_token'])) {
                $this->accessToken = $token = $result['access_token'];
            }
        }

        if (empty($token)) {
            throw new InvalidTokenException('token not available.');
        }

        return $token;
    }
1339712
public function withToken(Token $token)
    {
        $this->grant = 'provided_token';
        $this->token = new AccessToken([
            'access_token' => $token->jwt(),
            'expires' => $token->expires()->timestamp,
        ]);

        return $this;
    }
65076
def get_token(params, access_token_opts={})
      params = params.merge(:parse => :json)
      access_token_opts = access_token_opts.merge({:header_format => "OAuth2 %s", :param_name => "access_token"})
      
      @token = super(params, access_token_opts)
    end
1140927
public function getAuthorizeURL($token, $sign_in_with_twitter = true, $force_login = false)
	{
		if (is_array($token))
		{
			$token = $token['oauth_token'];
		}

		if ($force_login)
		{
			return $this->tconfig['AUTHENTICATE_URL'] . "?oauth_token={$token}&force_login=true";
		}
		else if (empty($sign_in_with_twitter))
		{
			return $this->tconfig['AUTHORIZE_URL']. "?oauth_token={$token}";
		}
		else
		{
			return $this->tconfig['AUTHENTICATE_URL'] . "?oauth_token={$token}";
		}
	}
404315
function AuthenticationOAuth(options) {
    AuthenticationAbstract.call(this, options);
    options = options || {};
    this._token = {
        access: options.accessToken || null
    };
}