public static function performOAuthLogin($consumerKey, $consumerSecret, osapiStorage $storage, osapiProvider $provider, $localUserId = null, $userId = null)
 {
     $auth = new osapiOAuth3Legged($consumerKey, $consumerSecret, $storage, $provider, $localUserId, $userId);
     if (($token = $storage->get($auth->storageKey)) !== false) {
         $auth->accessToken = $token;
     } else {
         if (isset($_GET['oauth_continue'])) {
             $token = $auth->upgradeRequestToken($_GET['token'], $_GET['key']);
             $auth->redirectToOriginal();
         } else {
             // Initialize the OAuth dance, first request a request token, then kick the client to the authorize URL
             // First we store the current URL in our storage, so that when the oauth dance is completed we can return there
             $callbackUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
             $token = $auth->obtainRequestToken($callbackUrl);
             $callbackUrl .= (strpos($_SERVER['REQUEST_URI'], '?') !== false ? '&' : '?') . 'oauth_continue=1&token=' . $token->key . '&key=' . urldecode($token->secret);
             $auth->redirectToAuthorization($token, $callbackUrl);
         }
     }
     return $auth;
 }
Exemplo n.º 2
0
 /**
  * The 3 legged oauth class needs a way to store the access key and token
  * it uses the osapiStorage class to do so.
  *
  * Constructing this class will initiate the 3 legged oauth work flow, including redirecting
  * to the OAuth provider's site if required(!)
  *
  * @param string $consumerKey
  * @param string $consumerSecret
  * @param osapiStorage $storage storage class to use (file,apc,memcache,mysql)
  * @param osapiProvider $provider the provider configuration (required to get the oauth endpoints)
  * @param any $localUser the *local* user ID (this is not the user's ID on the social network site, but the user id on YOUR site, this is used to link the oauth access token to a local login)
  * @param any $userId the *remote* user ID, you can supply this user id if known but it's completely optional. If set it will be included in the oauth requests in the xoauth_requestor_id field)
  * @return osapiOAuth3Legged the logged-in provider instance
  */
 public static function performOAuthLogin($consumerKey, $consumerSecret, osapiStorage $storage, osapiProvider $provider, $localUserId = null, $userId = null)
 {
     $auth = new osapiOAuth3Legged($consumerKey, $consumerSecret, $storage, $provider, $localUserId, $userId);
     if (($token = $storage->get($auth->storageKey)) !== false) {
         $auth->accessToken = $token;
     } else {
         if (isset($_GET['oauth_verifier']) && isset($_GET['oauth_token']) && isset($_GET['uid'])) {
             $uid = $_GET['uid'];
             $secret = $auth->storage->get($auth->storageKey . ":nonce" . $uid);
             $auth->storage->delete($auth->storageKey . ":nonce" . $uid);
             $token = $auth->upgradeRequestToken($_GET['oauth_token'], $secret, $_GET['oauth_verifier']);
             $auth->redirectToOriginal();
         } else {
             // Initialize the OAuth dance, first request a request token, then kick the client to the authorize URL
             // First we store the current URL in our storage, so that when the oauth dance is completed we can return there
             $callbackUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
             $uid = uniqid();
             $token = $auth->obtainRequestToken($callbackUrl, $uid);
             $auth->storage->set($auth->storageKey . ":nonce" . $uid, $token->secret);
             $auth->redirectToAuthorization($token);
         }
     }
     return $auth;
 }