Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Oauth_Adminhtml_Oauth_Admin_TokenController
  • Mage_Oauth_Adminhtml_Oauth_AuthorizeController
  • Mage_Oauth_Adminhtml_Oauth_AuthorizedTokensController
  • Mage_Oauth_Adminhtml_Oauth_ConsumerController
  • Mage_Oauth_AuthorizeController
  • Mage_Oauth_Block_Adminhtml_Oauth_Admin_Token
  • Mage_Oauth_Block_Adminhtml_Oauth_Admin_Token_Grid
  • Mage_Oauth_Block_Adminhtml_Oauth_Authorize
  • Mage_Oauth_Block_Adminhtml_Oauth_Authorize_Button
  • Mage_Oauth_Block_Adminhtml_Oauth_AuthorizedTokens
  • Mage_Oauth_Block_Adminhtml_Oauth_AuthorizedTokens_Grid
  • Mage_Oauth_Block_Adminhtml_Oauth_Consumer
  • Mage_Oauth_Block_Adminhtml_Oauth_Consumer_Edit
  • Mage_Oauth_Block_Adminhtml_Oauth_Consumer_Edit_Form
  • Mage_Oauth_Block_Adminhtml_Oauth_Consumer_Grid
  • Mage_Oauth_Block_Authorize
  • Mage_Oauth_Block_Authorize_Abstract
  • Mage_Oauth_Block_Authorize_Button
  • Mage_Oauth_Block_Authorize_ButtonBaseAbstract
  • Mage_Oauth_Block_AuthorizeBaseAbstract
  • Mage_Oauth_Block_Customer_Token_List
  • Mage_Oauth_Customer_TokenController
  • Mage_Oauth_Exception
  • Mage_Oauth_Helper_Data
  • Mage_Oauth_InitiateController
  • Mage_Oauth_Model_Consumer
  • Mage_Oauth_Model_Consumer_Validator_KeyLength
  • Mage_Oauth_Model_Nonce
  • Mage_Oauth_Model_Observer
  • Mage_Oauth_Model_Resource_Consumer
  • Mage_Oauth_Model_Resource_Consumer_Collection
  • Mage_Oauth_Model_Resource_Nonce
  • Mage_Oauth_Model_Resource_Nonce_Collection
  • Mage_Oauth_Model_Resource_Setup
  • Mage_Oauth_Model_Resource_Token
  • Mage_Oauth_Model_Resource_Token_Collection
  • Mage_Oauth_Model_Server
  • Mage_Oauth_Model_Token
  • Mage_Oauth_TokenController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Oauth
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * OAuth Helper
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Oauth
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Oauth_Helper_Data extends Mage_Core_Helper_Abstract
 35: {
 36:     /**#@+
 37:      * Endpoint types with appropriate routes
 38:      */
 39:     const ENDPOINT_AUTHORIZE_CUSTOMER        = 'oauth/authorize';
 40:     const ENDPOINT_AUTHORIZE_ADMIN           = 'adminhtml/oauth_authorize';
 41:     const ENDPOINT_AUTHORIZE_CUSTOMER_SIMPLE = 'oauth/authorize/simple';
 42:     const ENDPOINT_AUTHORIZE_ADMIN_SIMPLE    = 'adminhtml/oauth_authorize/simple';
 43:     const ENDPOINT_INITIATE                  = 'oauth/initiate';
 44:     const ENDPOINT_TOKEN                     = 'oauth/token';
 45:     /**#@-*/
 46: 
 47:     /**#@+
 48:      * Cleanup xpath config settings
 49:      */
 50:     const XML_PATH_CLEANUP_PROBABILITY       = 'oauth/cleanup/cleanup_probability';
 51:     const XML_PATH_CLEANUP_EXPIRATION_PERIOD = 'oauth/cleanup/expiration_period';
 52:     /**#@-*/
 53: 
 54:     /**#@+ Email template */
 55:     const XML_PATH_EMAIL_TEMPLATE = 'oauth/email/template';
 56:     const XML_PATH_EMAIL_IDENTITY = 'oauth/email/identity';
 57:     /**#@-*/
 58: 
 59:     /**
 60:      * Cleanup expiration period in minutes
 61:      */
 62:     const CLEANUP_EXPIRATION_PERIOD_DEFAULT = 120;
 63: 
 64:     /**
 65:      * Query parameter as a sign that user rejects
 66:      */
 67:     const QUERY_PARAM_REJECTED = 'rejected';
 68: 
 69:     /**
 70:      * Available endpoints list
 71:      *
 72:      * @var array
 73:      */
 74:     protected $_endpoints = array(
 75:         self::ENDPOINT_AUTHORIZE_CUSTOMER,
 76:         self::ENDPOINT_AUTHORIZE_ADMIN,
 77:         self::ENDPOINT_AUTHORIZE_CUSTOMER_SIMPLE,
 78:         self::ENDPOINT_AUTHORIZE_ADMIN_SIMPLE,
 79:         self::ENDPOINT_INITIATE,
 80:         self::ENDPOINT_TOKEN
 81:     );
 82: 
 83:     /**
 84:      * Generate random string for token or secret or verifier
 85:      *
 86:      * @param int $length String length
 87:      * @return string
 88:      */
 89:     protected function _generateRandomString($length)
 90:     {
 91: 
 92:         /** @var $helper Mage_Core_Helper_Data */
 93:         $helper = Mage::helper('core');
 94: 
 95:         return $helper->getRandomString(
 96:             $length, Mage_Core_Helper_Data::CHARS_DIGITS . Mage_Core_Helper_Data::CHARS_LOWERS
 97:         );
 98:     }
 99: 
100:     /**
101:      * Generate random string for token
102:      *
103:      * @return string
104:      */
105:     public function generateToken()
106:     {
107:         return $this->_generateRandomString(Mage_Oauth_Model_Token::LENGTH_TOKEN);
108:     }
109: 
110:     /**
111:      * Generate random string for token secret
112:      *
113:      * @return string
114:      */
115:     public function generateTokenSecret()
116:     {
117:         return $this->_generateRandomString(Mage_Oauth_Model_Token::LENGTH_SECRET);
118:     }
119: 
120:     /**
121:      * Generate random string for verifier
122:      *
123:      * @return string
124:      */
125:     public function generateVerifier()
126:     {
127:         return $this->_generateRandomString(Mage_Oauth_Model_Token::LENGTH_VERIFIER);
128:     }
129: 
130:     /**
131:      * Generate random string for consumer key
132:      *
133:      * @return string
134:      */
135:     public function generateConsumerKey()
136:     {
137:         return $this->_generateRandomString(Mage_Oauth_Model_Consumer::KEY_LENGTH);
138:     }
139: 
140:     /**
141:      * Generate random string for consumer secret
142:      *
143:      * @return string
144:      */
145:     public function generateConsumerSecret()
146:     {
147:         return $this->_generateRandomString(Mage_Oauth_Model_Consumer::SECRET_LENGTH);
148:     }
149: 
150:     /**
151:      * Return complete callback URL or boolean FALSE if no callback provided
152:      *
153:      * @param Mage_Oauth_Model_Token $token Token object
154:      * @param bool $rejected OPTIONAL Add user reject sign
155:      * @return bool|string
156:      */
157:     public function getFullCallbackUrl(Mage_Oauth_Model_Token $token, $rejected = false)
158:     {
159:         $callbackUrl = $token->getCallbackUrl();
160: 
161:         if (Mage_Oauth_Model_Server::CALLBACK_ESTABLISHED == $callbackUrl) {
162:             return false;
163:         }
164:         if ($rejected) {
165:             /** @var $consumer Mage_Oauth_Model_Consumer */
166:             $consumer = Mage::getModel('oauth/consumer')->load($token->getConsumerId());
167: 
168:             if ($consumer->getId() && $consumer->getRejectedCallbackUrl()) {
169:                 $callbackUrl = $consumer->getRejectedCallbackUrl();
170:             }
171:         } elseif (!$token->getAuthorized()) {
172:             Mage::throwException('Token is not authorized');
173:         }
174:         $callbackUrl .= (false === strpos($callbackUrl, '?') ? '?' : '&');
175:         $callbackUrl .= 'oauth_token=' . $token->getToken() . '&';
176:         $callbackUrl .= $rejected ? self::QUERY_PARAM_REJECTED . '=1' : 'oauth_verifier=' . $token->getVerifier();
177: 
178:         return $callbackUrl;
179:     }
180: 
181:     /**
182:      * Retrieve URL of specified endpoint.
183:      *
184:      * @param string $type Endpoint type (one of ENDPOINT_ constants)
185:      * @return string
186:      * @throws Exception    Exception when endpoint not found
187:      */
188:     public function getProtocolEndpointUrl($type)
189:     {
190:         if (!in_array($type, $this->_endpoints)) {
191:             throw new Exception('Invalid endpoint type passed.');
192:         }
193:         return rtrim(Mage::getUrl($type), '/');
194:     }
195: 
196:     /**
197:      * Calculate cleanup possibility for data with lifetime property
198:      *
199:      * @return bool
200:      */
201:     public function isCleanupProbability()
202:     {
203:         // Safe get cleanup probability value from system configuration
204:         $configValue = (int) Mage::getStoreConfig(self::XML_PATH_CLEANUP_PROBABILITY);
205:         return $configValue > 0 ? 1 == mt_rand(1, $configValue) : false;
206:     }
207: 
208:     /**
209:      * Get cleanup expiration period value from system configuration in minutes
210:      *
211:      * @return int
212:      */
213:     public function getCleanupExpirationPeriod()
214:     {
215:         $minutes = (int) Mage::getStoreConfig(self::XML_PATH_CLEANUP_EXPIRATION_PERIOD);
216:         return $minutes > 0 ? $minutes : self::CLEANUP_EXPIRATION_PERIOD_DEFAULT;
217:     }
218: 
219:     /**
220:      * Send Email to Token owner
221:      *
222:      * @param string $userEmail
223:      * @param string $userName
224:      * @param string $applicationName
225:      * @param string $status
226:      */
227:     public function sendNotificationOnTokenStatusChange($userEmail, $userName, $applicationName, $status)
228:     {
229:         /* @var $mailTemplate Mage_Core_Model_Email_Template */
230:         $mailTemplate = Mage::getModel('core/email_template');
231: 
232:         $mailTemplate->sendTransactional(
233:             Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
234:             Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY),
235:             $userEmail,
236:             $userName,
237:             array(
238:                 'name'              => $userName,
239:                 'email'             => $userEmail,
240:                 'applicationName'   => $applicationName,
241:                 'status'            => $status,
242: 
243:             )
244:         );
245:     }
246: 
247:     /**
248:      * Is current authorize page is simple
249:      *
250:      * @return boolean
251:      */
252:     protected function _getIsSimple()
253:     {
254:         $simple = false;
255:         if (stristr($this->_getRequest()->getActionName(), 'simple')
256:             || !is_null($this->_getRequest()->getParam('simple', null))
257:         ) {
258:             $simple = true;
259:         }
260: 
261:         return $simple;
262:     }
263: 
264:     /**
265:      * Get authorize endpoint url
266:      *
267:      * @param string $userType
268:      * @return string
269:      */
270:     public function getAuthorizeUrl($userType)
271:     {
272:         $simple = $this->_getIsSimple();
273: 
274:         if (Mage_Oauth_Model_Token::USER_TYPE_CUSTOMER == $userType) {
275:             if ($simple) {
276:                 $route = self::ENDPOINT_AUTHORIZE_CUSTOMER_SIMPLE;
277:             } else {
278:                 $route = self::ENDPOINT_AUTHORIZE_CUSTOMER;
279:             }
280:         } elseif (Mage_Oauth_Model_Token::USER_TYPE_ADMIN == $userType) {
281:             if ($simple) {
282:                 $route = self::ENDPOINT_AUTHORIZE_ADMIN_SIMPLE;
283:             } else {
284:                 $route = self::ENDPOINT_AUTHORIZE_ADMIN;
285:             }
286:         } else {
287:             throw new Exception('Invalid user type.');
288:         }
289: 
290:         return $this->_getUrl($route, array('_query' => array('oauth_token' => $this->getOauthToken())));
291:     }
292: 
293:     /**
294:      * Retrieve oauth_token param from request
295:      *
296:      * @return string|null
297:      */
298:     public function getOauthToken()
299:     {
300:         return $this->_getRequest()->getParam('oauth_token', null);
301:     }
302: }
303: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0