private function transferSystemToken($namespace)
 {
     try {
         if (file_exists(CRAFT_PLUGINS_PATH . 'oauth/vendor/autoload.php')) {
             require_once CRAFT_PLUGINS_PATH . 'oauth/vendor/autoload.php';
         }
         if (class_exists('OAuth\\OAuth1\\Token\\StdOAuth1Token')) {
             // get token record
             $row = craft()->db->createCommand()->select('*')->from('oauth_old_tokens')->where('namespace = :namespace', array(':namespace' => $namespace))->queryRow();
             if ($row) {
                 // transform token
                 $token = @unserialize(base64_decode($row['token']));
                 if ($token) {
                     // oauth 1
                     $newToken = new \OAuth\OAuth1\Token\StdOAuth1Token();
                     $newToken->setAccessToken($token->access_token);
                     $newToken->setRequestToken($token->access_token);
                     $newToken->setRequestTokenSecret($token->secret);
                     $newToken->setAccessTokenSecret($token->secret);
                     $this->saveToken($newToken);
                 } else {
                     Craft::log('Token error.', LogLevel::Info, true);
                 }
             } else {
                 Craft::log('Token record error.', LogLevel::Info, true);
             }
         } else {
             Craft::log('Class error.', LogLevel::Info, true);
         }
     } catch (\Exception $e) {
         Craft::log($e->getMessage(), LogLevel::Info, true);
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function getAuthAccess(RequestTokenInterface $requestToken, $token, $verifier, $code)
 {
     // Get OAuth libray Service instance
     $libService = $this->getLibService();
     // Check OAuth version
     if ($libService::OAUTH_VERSION == 1) {
         // Check token paramter is valid
         if (!empty($token) && $token != $requestToken->getToken()) {
             throw new \Exception('OAuth token parameter is invalid.');
         }
         // Create and store Oauth library token using request token
         $libStorage = $libService->getStorage();
         $libToken = new \OAuth\OAuth1\Token\StdOAuth1Token();
         $libToken->setRequestToken($requestToken->getToken());
         $libToken->setAccessToken($requestToken->getToken());
         $libToken->setRequestTokenSecret($requestToken->getSecret());
         $libToken->setAccessTokenSecret($requestToken->getSecret());
         $libStorage->storeAccessToken($libService->service(), $libToken);
         // Build access token from token returned by service provider API
         $oauthAccessToken = $libService->requestAccessToken($token, $verifier);
         $accessToken = new AccessToken($oauthAccessToken->getAccessToken(), $oauthAccessToken->getAccessTokenSecret());
     } else {
         // Check code parameter is valid
         if (empty($code)) {
             throw new \Exception('OAuth code parameter is invalid.');
         }
         // Build access token from token returned by service provider API
         $oauthAccessToken = $libService->requestAccessToken($code);
         $accessToken = new AccessToken($oauthAccessToken->getAccessToken(), null);
     }
     // Build AccessToken and return
     return $accessToken;
 }