Available in Ariadne > 2.7.3

ar\connect\oauth

The ariadne Open Auth client is based on PHP's pecl OAuth extension. You need to install this extension manually, it is not compiled in by default. See http://www.php.net/manual/en/install.pecl.pear.php and http://www.php.net/oauth for more information.

Example: (from the twitter login method)

<pinp>
$client = ar('connect/oauth')->client( $consKey, $consSecret );
$session = ar('loader')->session();
  $access_token        = $session->getvar('access_token');
  $access_token_secret = $session->getvar('access_token_secret');
  if ( $access_token && $access_token_secret ) {
   $client->setToken( $access_token, $access_token_secret );
    return true;
  }
  
  $oauth_verifier     = $session->getvar('oauth_verifier');
  $oauth_token        = $session->getvar('oauth_token');
  $oauth_token_secret = $session->getvar('oauth_token_secret');
  if ( !$oauth_verifier ) {
   $oauth_token_arg = ar::getvar('oauth_token');
    $oauth_verifier  = ar::getvar('oauth_verifier');
    if ( $oauth_verifier ) {
     $session->putvar( 'oauth_verifier', $oauth_verifier );
    } else {
     if ( !$callback ) {
      $callback = 'oob';
     }
     $info = $client->getRequestToken(
'http://api.twitter.com/oauth/request_token',
$callback
);
      if ( ar_error::isError($info) ) {
       $info->debugInfo = $client->debugInfo;
      return $info;
      }
    $client->setToken(
$info['oauth_token'],
$info['oauth_token_secret']
);
    $session->putvar( 'oauth_token', $info['oauth_token'] );
     $session->putvar(
'oauth_token_secret',
$info['oauth_token_secret']
);
      ar('loader')->redirect(
'http://api.twitter.com/oauth/authorize?oauth_token='
. RawUrlEncode( $info['oauth_token'] )
);
     return false;
    } else {
      return ar::url(
'http://api.twitter.com/oauth/authorize?oauth_token='
. RawUrlEncode( $info['oauth_token'] )
);
    }
  }

  if ( $oauth_verifier ) {
   $client->setToken( $oauth_token, $oauth_token_secret );
    $info = $client->getAccessToken(
'http://api.twitter.com/oauth/access_token',
'',
$oauth_verifier
);
    if ( ar_error::isError( $info ) ) {
      $info->debugInfo = $client->debugInfo;
      return $info;
    }
    $access_token = $info['oauth_token'];
    $access_token_secret = $info['oauth_token_secret'];
    $client->setToken( $access_token, $access_token_secret ); 
    $session->putvar( 'access_token', $access_token );
    $session->putvar( 'access_token_secret', $access_token_secret );
    return $info;
  }
 
  return false;
</pinp> 

methods

(object) client Returns a new OAuth client or consumer.

client

(object) ar('connect/oauth')->client( $consumerKey, $consumerSecret, $signatureMethod = OAUTH_SIG_METHOD_HMACSHA1, $authType = 0 )

(string) $consumerKey The consumer key provided by the service provider.
(string) $consumerSecret The consumer secret provided by the service provider.
(string) $signatureMethod Optional. Defines which signature method to use.
(int) $authType Optional. Defines how to pass the OAuth parameters to a consumer.

This method returns a new ar_connect_oauthClient client object. You can use this client to request web pages or send POST requests, etc. This client is based on the PHP pecl OAuth extension. It implements the ar_httpClient. interface.

There is one difference, instead of being able to set any streaming context option, you can only specify extra headers to send with ar_connect_oauthClient. This is because the underlying OAuth client doesn't accept the other parameters and creates its own streaming context.

For all other purposes the OAuth client can work as a plugin replacement for ar_httpClient.

The ar_connect_oathClient client also implements all the methods of PHP's OAuth client.