Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $callbackUrl is a path to your file with OAuth authentication example for the Customer user
- $callbackUrl = "http://www.seocompanyinpune.co.in/demo/ecom2/oauth_customer.php";
- $temporaryCredentialsRequestUrl = "http://www.seocompanyinpune.co.in/demo/ecom2/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
- $customerAuthorizationUrl = 'http://www.seocompanyinpune.co.in/demo/ecom2/oauth/authorize/apiLogin';
- $accessTokenRequestUrl = 'http://www.seocompanyinpune.co.in/demo/ecom2/oauth/token';
- $apiUrl = 'http://www.seocompanyinpune.co.in/demo/ecom2/api/rest';
- $consumerKey = 'd19df3aa6784569c19b51d38c8aaf620';
- $consumerSecret = '17c26fc92a71004c546b61a9d46d7fe8';
- session_start();
- $postdata = file_get_contents("php://input");
- $request = json_decode($postdata);
- $username = $request->email;
- $password = $request->pass;
- if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
- $_SESSION['state'] = 0;
- }
- try {
- $authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
- $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
- $oauthClient->enableDebug();
- if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
- $requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
- $_SESSION['secret'] = $requestToken['oauth_token_secret'];
- $_SESSION['state'] = 1;
- header('Location: ' . $customerAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token'] . '&username=' . $username . '&password=' . $password );
- exit;
- } else if ($_SESSION['state'] == 1) {
- $oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
- $accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
- $_SESSION['state'] = 2;
- $_SESSION['token'] = $accessToken['oauth_token'];
- $_SESSION['secret'] = $accessToken['oauth_token_secret'];
- header('Location: ' . $callbackUrl);
- exit;
- } else {
- $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
- $resourceUrl = "$apiUrl/customers";
- $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => 'application/json'));
- $res['secret'] = $_SESSION['secret'];
- $res['token'] = $_SESSION['token'];
- $res['message'] = 'Login successfull';
- $res['customer'] = json_decode($oauthClient->getLastResponse());
- echo json_encode($res);
- include('logout.php');
- session_destroy();
- }
- } catch (OAuthException $e) {
- print_r($e->getMessage());
- echo "<br/>";
- print_r($e->lastResponse);
- }
- public function apiLoginAction($simple = false)
- {
- /** @var $server Mage_Oauth_Model_Server */
- $server = Mage::getModel('oauth/server');
- /** @var $session Mage_Customer_Model_Session */
- $session = Mage::getSingleton($this->_sessionName);
- $isException = false;
- try {
- $server->checkAuthorizeRequest();
- } catch (Mage_Core_Exception $e) {
- $session->addError($e->getMessage());
- } catch (Mage_Oauth_Exception $e) {
- $isException = true;
- $session->addException($e, $this->__('An error occurred. Your authorization request is invalid.'));
- } catch (Exception $e) {
- $isException = true;
- $session->addException($e, $this->__('An error occurred.'));
- }
- $this->loadLayout();
- $layout = $this->getLayout();
- $logged = $session->isLoggedIn();
- $contentBlock = $layout->getBlock('content');
- $form_key = "lAv9vvP9dCvSVBYl";
- $oauth_token = $this->getRequest()->getQuery('oauth_token');
- $username = $_GET['username'];
- $password = $_GET['password'];
- unset($_SESSION['username']);
- unset($_SESSION['password']);
- $url = "http://www.seocompanyinpune.co.in/demo/ecom2/customer/account/loginGet?form_key=$form_key&login[username]=$username&login[password]=$password&oauth_token=$oauth_token&send=";
- header("Location: $url");
- die();
- /** @var $helper Mage_Core_Helper_Url */
- /*$helper = Mage::helper('core/url');
- $session->setAfterAuthUrl(Mage::getUrl('customer/account/login', array('_nosid' => true)))
- ->setBeforeAuthUrl($helper->getCurrentUrl());
- $block->setIsSimple($simple)->setToken($this->getRequest()->getQuery('oauth_token'))
- ->setHasException($isException);
- return $this;*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement