Exemple #1
0
 /**
  * Get access token
  *
  * @param	string $verifier OAuth verifier, got after authorization
  * @access	protected
  * @return	array
  */
 protected function _setupAccessToken($verifier)
 {
     ApiDebug::p('requesting access token');
     $oauth = $this->_getOAuthInstance(OAUTH_AUTH_TYPE_FORM);
     $oauth->setToken(self::$_requestToken, self::$_requestSecret);
     $accessTokenInfo = $oauth->getAccessToken(ApiUtils::getFullUrl(self::URL_ATOKEN, 'api'), null, $verifier);
     ApiDebug::p('got access token info', $accessTokenInfo);
     self::$_accessToken = $accessTokenInfo['oauth_token'];
     self::$_accessSecret = $accessTokenInfo['oauth_token_secret'];
     return $accessTokenInfo;
 }
Exemple #2
0
 /**
  * @test
  */
 public function testGetFullUrl()
 {
     $url = Utils::getFullUrl('/auth/v1/oauth/token/access', 'api');
     $this->assertEquals('https://www.odesk.com/api/auth/v1/oauth/token/access', $url);
 }
Exemple #3
0
 /**
  * Auth process 
  * 
  * @access  public
  * @return  string
  */
 public function auth()
 {
     ApiDebug::p('running auth process in ' . __CLASS__);
     if (self::$_accessToken === null && self::$_verifier === null) {
         if (self::$_requestToken === null && self::$_requestSecret === null) {
             // web-based application should setup and save request token itself
             // to be able use it after callback
             $this->setupRequestToken();
         }
         $authUrl = ApiUtils::getFullUrl(self::URL_AUTH) . '?oauth_token=' . self::$_requestToken;
         if (self::$_mode === 'web') {
             // authorize web application via browser
             header('Location: ' . $authUrl);
         } elseif (self::$_mode === 'nonweb') {
             // authorize nonweb application
             ApiDebug::p('found [nonweb] mode, need to autorize application manually');
             $prompt = 'Visit ' . $authUrl . "\n" . 'and provide oauth_verifier for further authorization' . "\n" . '$ ';
             if (PHP_OS == 'WINNT') {
                 echo $prompt;
                 $verifier = stream_get_line(STDIN, 1024, PHP_EOL);
             } else {
                 $verifier = readline($prompt);
             }
             // get access token
             $this->_setupAccessToken($verifier);
         }
     } elseif (self::$_accessToken == null && self::$_verifier !== null) {
         // get access token, web-based callback
         $this->_setupAccessToken(self::$_verifier);
     } else {
         // access_token isset
     }
     return array('access_token' => self::$_accessToken, 'access_secret' => self::$_accessSecret);
 }
Exemple #4
0
 /**
  * Get OAuth instance
  *
  * @param   integer $authType (Optional) Auth type
  * @access  protected
  * @return  object
  */
 protected function _getOAuthInstance($authType = null)
 {
     ApiDebug::p('get OAuth instance');
     $options = array('consumer_key' => self::$_apiKey, 'consumer_secret' => self::$_secret, 'server_uri' => ODESK_BASE_URL, 'request_token_uri' => ApiUtils::getFullUrl(self::URL_RTOKEN, 'api'), 'authorize_uri' => self::URL_AUTH, 'access_token_uri' => ApiUtils::getFullUrl(self::URL_ATOKEN, 'api'));
     $oauth = \OAuthStore::instance('Session', $options);
     return $oauth;
 }