public function getAuthUrl() { $consumerKey = $this->getConsumerKey(); $consumerSecret = $this->getConsumerSecret(); $callback = YahooUtil::current_url() . '?in_popup'; return YahooSession::createAuthorizationUrl($consumerKey, $consumerSecret, $callback); }
public function saveAction() { require 'Yahoo/Yahoo.inc'; $helper = Mage::helper('referralreward'); //YahooLogger::setDebug(true); //YahooLogger::setDebugDestination('LOG'); define('OAUTH_CONSUMER_KEY', $helper->storeConfig('yahoo/key')); define('OAUTH_CONSUMER_SECRET', $helper->storeConfig('yahoo/secret')); define('OAUTH_DOMAIN', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)); define('OAUTH_APP_ID', $helper->storeConfig('yahoo/appid')); $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($hasSession == FALSE) { $callback = YahooUtil::current_url() . "?in_popup"; $sessionStore = new NativeSessionStore(); $authUrl = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, $sessionStore); header("Location: " . $authUrl); exit; } else { $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($session) { $user = $session->getSessionedUser(); //$profile = $user->getProfile(); $contacts = $user->getContactSync(); if ($contacts) { $contacts = $this->XmltoArray($contacts); $names = array(); $emails = array(); foreach ($contacts['contactsync']['contacts'] as $key => $profileContact) { foreach ($profileContact['fields'] as $contact) { $emails[] = $contact['value']; $names[] = ''; } } YahooSession::clearSession(); $customer_id = (int) $this->_getSession()->getId(); $count = Mage::getModel('referralreward/friends')->saveFriends($customer_id, $emails, $names); if ($count['enable']) { if ($count['enable'] > 1) { $this->_getSession()->addSuccess($this->__('%s have been added', $count['enable'])); } else { $this->_getSession()->addSuccess($this->__('%s has been added', $count['enable'])); } } if ($count['disable']) { $this->_getSession()->addSuccess($this->__('%s already registered', $count['disable'])); } if ($count['enable'] == 0 && $count['disable'] == 0) { $this->_getSession()->addError($this->__("no emails were added")); } } else { $this->_getSession()->addError($this->__("no emails were added")); } } echo "<script>\n window.opener.location.reload(true);\n window.close();\n </script>"; } }
/** * @Yahoo login action * * Connect Yahoo Using oAuth coonection. * * @return string URL eiether customer save and loggedin or an error if any occurs */ public function yahoopostAction() { /** * Include @Yahoo library files for oAuth connection */ require 'sociallogin/lib/Yahoo.inc'; YahooLogger::setDebug(true); YahooLogger::setDebugDestination('LOG'); /** * * @param string $yahoo_client_id, * $yahoo_client_secret and $yahoo_developer_key * * Using this params setting up the connection to yahoo */ $yahooClientId = Mage::getStoreConfig('sociallogin/yahoo/yahoo_id'); $yahooClientSecret = Mage::getStoreConfig('sociallogin/yahoo/yahoo_secret'); $yahooDeveloperKey = Mage::getStoreConfig('sociallogin/yahoo/yahoo_develop'); $yahooDomain = Mage::getUrl(); /** * Use memcache to store oauth credentials via php native sessions * * Make sure you obtain application keys before continuing by visiting:<https://developer.yahoo.com/dashboard/createKey.html> */ define('OAUTH_CONSUMER_KEY', "{$yahooClientId}"); define('OAUTH_CONSUMER_SECRET', "{$yahooClientSecret}"); define('OAUTH_DOMAIN', "{$yahooDomain}"); define('OAUTH_APP_ID', "{$yahooDeveloperKey}"); $para = $this->getRequest()->getParams(); $data = $this->getRequest()->getParam('fb'); if (array_key_exists("logout", $para)) { YahooSession::clearSession(); $url = "index.php"; $this->_redirectUrl($url); } $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); YahooUtil::current_url(); if (!$hasSession) { $callback = YahooUtil::current_url() . "?in_popup"; $sessionStore = new NativeSessionStore(); $authUrl = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, $sessionStore); if ($authUrl) { $this->_redirectUrl($authUrl); } } else { $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($session) { $user = $session->getSessionedUser(); $profile = $user->getProfile(); $profile->guid; $email = $profile->emails[0]->handle; $firstName = $profile->givenName; $lastName = $profile->familyName; if ($email == '') { Mage::getSingleton('customer/session')->addError($this->__('Yahoo Login connection failed')); $url = Mage::helper('customer')->getAccountUrl(); return $this->_redirectUrl($url); } else { $this->customerAction($firstName, $lastName, $email, 'Yahoo', $data); } } } }
define('OAUTH_CONSUMER_SECRET', '###'); define('OAUTH_DOMAIN', '###'); define('OAUTH_APP_ID', '###'); if (array_key_exists("logout", $_GET)) { // if a session exists and the logout flag is detected // clear the session tokens and reload the page. YahooSession::clearSession(); header("Location: sampleapp.php"); } // check for the existance of a session. // this will determine if we need to show a pop-up and fetch the auth url, // or fetch the user's social data. $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($hasSession == FALSE) { // create the callback url, $callback = YahooUtil::current_url() . "?in_popup"; // pass the credentials to get an auth url. // this URL will be used for the pop-up. $auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback); } else { // pass the credentials to initiate a session $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); // if the in_popup flag is detected, // the pop-up has loaded the callback_url and we can close this window. if (array_key_exists("in_popup", $_GET)) { close_popup(); exit; } // if a session is initialized, fetch the user's profile information if ($session) { // Get the currently sessioned user.
/** * Creates authorization URLs, allowing applications to manage their * user experience when the user needs to be sent to Yahoo! to authorize * the application to access their account. * * @param $consumerKey The OAuth consumer key. * @param $consumerSecret The OAuth consumer key secret. * @param $callback The callback URL to redirect the user to after * they verify the application access. If no callback * is provided, the current page URL will be used. * Use the "oob" callback for desktop clients or for * web clients where no callback should be used. * @param $sessionStore The session store implementation to use. See * YahooSessionStore for more information. If no * session store is provided, createAuthorizationUrl * will instantiate a NativeSessionStore and use that. * @return stdclass A PHP object with two properties: "urlWithCallback" * and "urlWithoutCallback". This allows the application * to mix and match authorizations that do and don't * have callbacks in the URLs. urlWithoutCallback is * useful for JavaScript popup windows while * urlWithCallback is useful for normal <a href> * tags. */ function createAuthorizationUrl($consumerKey, $consumerSecret, $callback = NULL, $sessionStore = NULL) { global $GLOBAL_YAHOO_SESSION; if(is_null($sessionStore)) { $sessionStore = new NativeSessionStore(); } // No callback URL supplied. Build one from the current URL. if(is_null($callback)) { $callback = YahooUtil::current_url(); } // Redirect the user to log in. $requestToken = YahooAuthorization::getRequestToken($consumerKey, $consumerSecret, $callback); if(!is_null($requestToken)) { $sessionStore->storeRequestToken($requestToken); $url = YahooAuthorization::createAuthorizationUrl($requestToken, $callback); return $url; } else { YahooLogger::error("Failed to create request token"); $GLOBAL_YAHOO_SESSION = NULL; return null; } }