[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework 4 * 5 * LICENSE 6 * 7 * This source file is subject to the new BSD license that is bundled 8 * with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://framework.zend.com/license/new-bsd 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 [email protected] so we can send you a copy immediately. 14 * 15 * @category Zend 16 * @package Zend_Oauth 17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) 18 * @license http://framework.zend.com/license/new-bsd New BSD License 19 * @version $Id: Config.php 24593 2012-01-05 20:35:02Z matthew $ 20 */ 21 22 /** Zend_Oauth */ 23 require_once 'Zend/Oauth.php'; 24 25 /** Zend_Uri */ 26 require_once 'Zend/Uri.php'; 27 28 /** Zend_Oauth_Config_Interface */ 29 require_once 'Zend/Oauth/Config/ConfigInterface.php'; 30 31 /** 32 * @category Zend 33 * @package Zend_Oauth 34 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) 35 * @license http://framework.zend.com/license/new-bsd New BSD License 36 */ 37 class Zend_Oauth_Config implements Zend_Oauth_Config_ConfigInterface 38 { 39 /** 40 * Signature method used when signing all parameters for an HTTP request 41 * 42 * @var string 43 */ 44 protected $_signatureMethod = 'HMAC-SHA1'; 45 46 /** 47 * Three request schemes are defined by OAuth, of which passing 48 * all OAuth parameters by Header is preferred. The other two are 49 * POST Body and Query String. 50 * 51 * @var string 52 */ 53 protected $_requestScheme = Zend_Oauth::REQUEST_SCHEME_HEADER; 54 55 /** 56 * Preferred request Method - one of GET or POST - which Zend_Oauth 57 * will enforce as standard throughout the library. Generally a default 58 * of POST works fine unless a Provider specifically requires otherwise. 59 * 60 * @var string 61 */ 62 protected $_requestMethod = Zend_Oauth::POST; 63 64 /** 65 * OAuth Version; This defaults to 1.0 - Must not be changed! 66 * 67 * @var string 68 */ 69 protected $_version = '1.0'; 70 71 /** 72 * This optional value is used to define where the user is redirected to 73 * after authorizing a Request Token from an OAuth Providers website. 74 * It's optional since a Provider may ask for this to be defined in advance 75 * when registering a new application for a Consumer Key. 76 * 77 * @var string 78 */ 79 protected $_callbackUrl = null; 80 81 /** 82 * The URL root to append default OAuth endpoint paths. 83 * 84 * @var string 85 */ 86 protected $_siteUrl = null; 87 88 /** 89 * The URL to which requests for a Request Token should be directed. 90 * When absent, assumed siteUrl+'/request_token' 91 * 92 * @var string 93 */ 94 protected $_requestTokenUrl = null; 95 96 /** 97 * The URL to which requests for an Access Token should be directed. 98 * When absent, assumed siteUrl+'/access_token' 99 * 100 * @var string 101 */ 102 protected $_accessTokenUrl = null; 103 104 /** 105 * The URL to which users should be redirected to authorize a Request Token. 106 * When absent, assumed siteUrl+'/authorize' 107 * 108 * @var string 109 */ 110 protected $_authorizeUrl = null; 111 112 /** 113 * An OAuth application's Consumer Key. 114 * 115 * @var string 116 */ 117 protected $_consumerKey = null; 118 119 /** 120 * Every Consumer Key has a Consumer Secret unless you're in RSA-land. 121 * 122 * @var string 123 */ 124 protected $_consumerSecret = null; 125 126 /** 127 * If relevant, a PEM encoded RSA private key encapsulated as a 128 * Zend_Crypt_Rsa Key 129 * 130 * @var Zend_Crypt_Rsa_Key_Private 131 */ 132 protected $_rsaPrivateKey = null; 133 134 /** 135 * If relevant, a PEM encoded RSA public key encapsulated as a 136 * Zend_Crypt_Rsa Key 137 * 138 * @var Zend_Crypt_Rsa_Key_Public 139 */ 140 protected $_rsaPublicKey = null; 141 142 /** 143 * Generally this will nearly always be an Access Token represented as a 144 * Zend_Oauth_Token_Access object. 145 * 146 * @var Zend_Oauth_Token 147 */ 148 protected $_token = null; 149 150 /** 151 * Define the OAuth realm 152 * 153 * @var string 154 */ 155 protected $_realm = null; 156 157 /** 158 * Constructor; create a new object with an optional array|Zend_Config 159 * instance containing initialising options. 160 * 161 * @param array|Zend_Config $options 162 * @return void 163 */ 164 public function __construct($options = null) 165 { 166 if ($options !== null) { 167 if ($options instanceof Zend_Config) { 168 $options = $options->toArray(); 169 } 170 $this->setOptions($options); 171 } 172 } 173 174 /** 175 * Parse option array or Zend_Config instance and setup options using their 176 * relevant mutators. 177 * 178 * @param array|Zend_Config $options 179 * @return Zend_Oauth_Config 180 */ 181 public function setOptions(array $options) 182 { 183 foreach ($options as $key => $value) { 184 switch ($key) { 185 case 'consumerKey': 186 $this->setConsumerKey($value); 187 break; 188 case 'consumerSecret': 189 $this->setConsumerSecret($value); 190 break; 191 case 'signatureMethod': 192 $this->setSignatureMethod($value); 193 break; 194 case 'version': 195 $this->setVersion($value); 196 break; 197 case 'callbackUrl': 198 $this->setCallbackUrl($value); 199 break; 200 case 'siteUrl': 201 $this->setSiteUrl($value); 202 break; 203 case 'requestTokenUrl': 204 $this->setRequestTokenUrl($value); 205 break; 206 case 'accessTokenUrl': 207 $this->setAccessTokenUrl($value); 208 break; 209 case 'userAuthorizationUrl': 210 $this->setUserAuthorizationUrl($value); 211 break; 212 case 'authorizeUrl': 213 $this->setAuthorizeUrl($value); 214 break; 215 case 'requestMethod': 216 $this->setRequestMethod($value); 217 break; 218 case 'rsaPrivateKey': 219 $this->setRsaPrivateKey($value); 220 break; 221 case 'rsaPublicKey': 222 $this->setRsaPublicKey($value); 223 break; 224 case 'realm': 225 $this->setRealm($value); 226 break; 227 } 228 } 229 if (isset($options['requestScheme'])) { 230 $this->setRequestScheme($options['requestScheme']); 231 } 232 233 return $this; 234 } 235 236 /** 237 * Set consumer key 238 * 239 * @param string $key 240 * @return Zend_Oauth_Config 241 */ 242 public function setConsumerKey($key) 243 { 244 $this->_consumerKey = $key; 245 return $this; 246 } 247 248 /** 249 * Get consumer key 250 * 251 * @return string 252 */ 253 public function getConsumerKey() 254 { 255 return $this->_consumerKey; 256 } 257 258 /** 259 * Set consumer secret 260 * 261 * @param string $secret 262 * @return Zend_Oauth_Config 263 */ 264 public function setConsumerSecret($secret) 265 { 266 $this->_consumerSecret = $secret; 267 return $this; 268 } 269 270 /** 271 * Get consumer secret 272 * 273 * Returns RSA private key if set; otherwise, returns any previously set 274 * consumer secret. 275 * 276 * @return string 277 */ 278 public function getConsumerSecret() 279 { 280 if ($this->_rsaPrivateKey !== null) { 281 return $this->_rsaPrivateKey; 282 } 283 return $this->_consumerSecret; 284 } 285 286 /** 287 * Set signature method 288 * 289 * @param string $method 290 * @return Zend_Oauth_Config 291 * @throws Zend_Oauth_Exception if unsupported signature method specified 292 */ 293 public function setSignatureMethod($method) 294 { 295 $method = strtoupper($method); 296 if (!in_array($method, array( 297 'HMAC-SHA1', 'HMAC-SHA256', 'RSA-SHA1', 'PLAINTEXT' 298 )) 299 ) { 300 require_once 'Zend/Oauth/Exception.php'; 301 throw new Zend_Oauth_Exception('Unsupported signature method: ' 302 . $method 303 . '. Supported are HMAC-SHA1, RSA-SHA1, PLAINTEXT and HMAC-SHA256'); 304 } 305 $this->_signatureMethod = $method;; 306 return $this; 307 } 308 309 /** 310 * Get signature method 311 * 312 * @return string 313 */ 314 public function getSignatureMethod() 315 { 316 return $this->_signatureMethod; 317 } 318 319 /** 320 * Set request scheme 321 * 322 * @param string $scheme 323 * @return Zend_Oauth_Config 324 * @throws Zend_Oauth_Exception if invalid scheme specified, or if POSTBODY set when request method of GET is specified 325 */ 326 public function setRequestScheme($scheme) 327 { 328 $scheme = strtolower($scheme); 329 if (!in_array($scheme, array( 330 Zend_Oauth::REQUEST_SCHEME_HEADER, 331 Zend_Oauth::REQUEST_SCHEME_POSTBODY, 332 Zend_Oauth::REQUEST_SCHEME_QUERYSTRING, 333 )) 334 ) { 335 require_once 'Zend/Oauth/Exception.php'; 336 throw new Zend_Oauth_Exception( 337 '\'' . $scheme . '\' is an unsupported request scheme' 338 ); 339 } 340 if ($scheme == Zend_Oauth::REQUEST_SCHEME_POSTBODY 341 && $this->getRequestMethod() == Zend_Oauth::GET 342 ) { 343 require_once 'Zend/Oauth/Exception.php'; 344 throw new Zend_Oauth_Exception( 345 'Cannot set POSTBODY request method if HTTP method set to GET' 346 ); 347 } 348 $this->_requestScheme = $scheme; 349 return $this; 350 } 351 352 /** 353 * Get request scheme 354 * 355 * @return string 356 */ 357 public function getRequestScheme() 358 { 359 return $this->_requestScheme; 360 } 361 362 /** 363 * Set version 364 * 365 * @param string $version 366 * @return Zend_Oauth_Config 367 */ 368 public function setVersion($version) 369 { 370 $this->_version = $version; 371 return $this; 372 } 373 374 /** 375 * Get version 376 * 377 * @return string 378 */ 379 public function getVersion() 380 { 381 return $this->_version; 382 } 383 384 /** 385 * Set callback URL 386 * 387 * @param string $url 388 * @return Zend_Oauth_Config 389 * @throws Zend_Oauth_Exception for invalid URLs 390 */ 391 public function setCallbackUrl($url) 392 { 393 if (!Zend_Uri::check($url) && $url !== 'oob') { 394 require_once 'Zend/Oauth/Exception.php'; 395 throw new Zend_Oauth_Exception( 396 '\'' . $url . '\' is not a valid URI' 397 ); 398 } 399 $this->_callbackUrl = $url; 400 return $this; 401 } 402 403 /** 404 * Get callback URL 405 * 406 * @return string 407 */ 408 public function getCallbackUrl() 409 { 410 return $this->_callbackUrl; 411 } 412 413 /** 414 * Set site URL 415 * 416 * @param string $url 417 * @return Zend_Oauth_Config 418 * @throws Zend_Oauth_Exception for invalid URLs 419 */ 420 public function setSiteUrl($url) 421 { 422 if (!Zend_Uri::check($url)) { 423 require_once 'Zend/Oauth/Exception.php'; 424 throw new Zend_Oauth_Exception( 425 '\'' . $url . '\' is not a valid URI' 426 ); 427 } 428 $this->_siteUrl = $url; 429 return $this; 430 } 431 432 /** 433 * Get site URL 434 * 435 * @return string 436 */ 437 public function getSiteUrl() 438 { 439 return $this->_siteUrl; 440 } 441 442 /** 443 * Set request token URL 444 * 445 * @param string $url 446 * @return Zend_Oauth_Config 447 * @throws Zend_Oauth_Exception for invalid URLs 448 */ 449 public function setRequestTokenUrl($url) 450 { 451 if (!Zend_Uri::check($url)) { 452 require_once 'Zend/Oauth/Exception.php'; 453 throw new Zend_Oauth_Exception( 454 '\'' . $url . '\' is not a valid URI' 455 ); 456 } 457 $this->_requestTokenUrl = rtrim($url, '/'); 458 return $this; 459 } 460 461 /** 462 * Get request token URL 463 * 464 * If no request token URL has been set, but a site URL has, returns the 465 * site URL with the string "/request_token" appended. 466 * 467 * @return string 468 */ 469 public function getRequestTokenUrl() 470 { 471 if (!$this->_requestTokenUrl && $this->_siteUrl) { 472 return $this->_siteUrl . '/request_token'; 473 } 474 return $this->_requestTokenUrl; 475 } 476 477 /** 478 * Set access token URL 479 * 480 * @param string $url 481 * @return Zend_Oauth_Config 482 * @throws Zend_Oauth_Exception for invalid URLs 483 */ 484 public function setAccessTokenUrl($url) 485 { 486 if (!Zend_Uri::check($url)) { 487 require_once 'Zend/Oauth/Exception.php'; 488 throw new Zend_Oauth_Exception( 489 '\'' . $url . '\' is not a valid URI' 490 ); 491 } 492 $this->_accessTokenUrl = rtrim($url, '/'); 493 return $this; 494 } 495 496 /** 497 * Get access token URL 498 * 499 * If no access token URL has been set, but a site URL has, returns the 500 * site URL with the string "/access_token" appended. 501 * 502 * @return string 503 */ 504 public function getAccessTokenUrl() 505 { 506 if (!$this->_accessTokenUrl && $this->_siteUrl) { 507 return $this->_siteUrl . '/access_token'; 508 } 509 return $this->_accessTokenUrl; 510 } 511 512 /** 513 * Set user authorization URL 514 * 515 * @param string $url 516 * @return Zend_Oauth_Config 517 * @throws Zend_Oauth_Exception for invalid URLs 518 */ 519 public function setUserAuthorizationUrl($url) 520 { 521 return $this->setAuthorizeUrl($url); 522 } 523 524 /** 525 * Set authorization URL 526 * 527 * @param string $url 528 * @return Zend_Oauth_Config 529 * @throws Zend_Oauth_Exception for invalid URLs 530 */ 531 public function setAuthorizeUrl($url) 532 { 533 if (!Zend_Uri::check($url)) { 534 require_once 'Zend/Oauth/Exception.php'; 535 throw new Zend_Oauth_Exception( 536 '\'' . $url . '\' is not a valid URI' 537 ); 538 } 539 $this->_authorizeUrl = rtrim($url, '/'); 540 return $this; 541 } 542 543 /** 544 * Get user authorization URL 545 * 546 * @return string 547 */ 548 public function getUserAuthorizationUrl() 549 { 550 return $this->getAuthorizeUrl(); 551 } 552 553 /** 554 * Get authorization URL 555 * 556 * If no authorization URL has been set, but a site URL has, returns the 557 * site URL with the string "/authorize" appended. 558 * 559 * @return string 560 */ 561 public function getAuthorizeUrl() 562 { 563 if (!$this->_authorizeUrl && $this->_siteUrl) { 564 return $this->_siteUrl . '/authorize'; 565 } 566 return $this->_authorizeUrl; 567 } 568 569 /** 570 * Set request method 571 * 572 * @param string $method 573 * @return Zend_Oauth_Config 574 * @throws Zend_Oauth_Exception for invalid request methods 575 */ 576 public function setRequestMethod($method) 577 { 578 $method = strtoupper($method); 579 if (!in_array($method, array( 580 Zend_Oauth::GET, 581 Zend_Oauth::POST, 582 Zend_Oauth::PUT, 583 Zend_Oauth::DELETE, 584 )) 585 ) { 586 require_once 'Zend/Oauth/Exception.php'; 587 throw new Zend_Oauth_Exception('Invalid method: ' . $method); 588 } 589 $this->_requestMethod = $method; 590 return $this; 591 } 592 593 /** 594 * Get request method 595 * 596 * @return string 597 */ 598 public function getRequestMethod() 599 { 600 return $this->_requestMethod; 601 } 602 603 /** 604 * Set RSA public key 605 * 606 * @param Zend_Crypt_Rsa_Key_Public $key 607 * @return Zend_Oauth_Config 608 */ 609 public function setRsaPublicKey(Zend_Crypt_Rsa_Key_Public $key) 610 { 611 $this->_rsaPublicKey = $key; 612 return $this; 613 } 614 615 /** 616 * Get RSA public key 617 * 618 * @return Zend_Crypt_Rsa_Key_Public 619 */ 620 public function getRsaPublicKey() 621 { 622 return $this->_rsaPublicKey; 623 } 624 625 /** 626 * Set RSA private key 627 * 628 * @param Zend_Crypt_Rsa_Key_Private $key 629 * @return Zend_Oauth_Config 630 */ 631 public function setRsaPrivateKey(Zend_Crypt_Rsa_Key_Private $key) 632 { 633 $this->_rsaPrivateKey = $key; 634 return $this; 635 } 636 637 /** 638 * Get RSA private key 639 * 640 * @return Zend_Crypt_Rsa_Key_Private 641 */ 642 public function getRsaPrivateKey() 643 { 644 return $this->_rsaPrivateKey; 645 } 646 647 /** 648 * Set OAuth token 649 * 650 * @param Zend_Oauth_Token $token 651 * @return Zend_Oauth_Config 652 */ 653 public function setToken(Zend_Oauth_Token $token) 654 { 655 $this->_token = $token; 656 return $this; 657 } 658 659 /** 660 * Get OAuth token 661 * 662 * @return Zend_Oauth_Token 663 */ 664 public function getToken() 665 { 666 return $this->_token; 667 } 668 669 /** 670 * Set OAuth realm 671 * 672 * @param string $realm 673 * @return Zend_Oauth_Config 674 */ 675 public function setRealm($realm) 676 { 677 $this->_realm = $realm; 678 return $this; 679 } 680 681 /** 682 * Get OAuth realm 683 * 684 * @return string 685 */ 686 public function getRealm() 687 { 688 return $this->_realm; 689 } 690 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |