public function setUp()
 {
     parent::setUp();
     $oauthStorageBackend = 'OAuth\\' . $this->_config->getValue('storageBackend');
     $storage = new $oauthStorageBackend($this->_config);
     $resourceOwnerOne = array("id" => "fkooman", "entitlement" => array("urn:x-foo:service:access", "urn:x-bar:privilege:admin"), "ext" => array());
     $resourceOwnerTwo = array("id" => "frko", "entitlement" => array(), "ext" => array());
     $storage->updateResourceOwner(new MockResourceOwner($resourceOwnerOne));
     $storage->updateResourceOwner(new MockResourceOwner($resourceOwnerTwo));
     $storage->storeAccessToken("foo", time(), "testclient", "fkooman", "foo bar", 1234);
     $storage->storeAccessToken("bar", time(), "testclient", "frko", "a b c", 1234);
 }
Exemplo n.º 2
0
 public function setUp()
 {
     parent::setUp();
     // enable Api
     $this->_config->setSectionValue("Api", "enableApi", TRUE);
     $this->_api = new Api($this->_config, NULL);
     $oauthStorageBackend = 'OAuth\\' . $this->_config->getValue('storageBackend');
     $storage = new $oauthStorageBackend($this->_config);
     $resourceOwner = array("id" => "fkooman", "entitlement" => array(), "ext" => array());
     $storage->updateResourceOwner(new MockResourceOwner($resourceOwner));
     $storage->addApproval('testclient', 'fkooman', 'read', NULL);
     $storage->storeAccessToken('12345abc', time(), 'testcodeclient', 'fkooman', 'authorizations', 3600);
 }
 public function setUp()
 {
     parent::setUp();
     $oauthStorageBackend = 'OAuth\\' . $this->_config->getValue('storageBackend');
     $storage = new $oauthStorageBackend($this->_config);
     $resourceOwner = array("id" => "fkooman", "entitlement" => array(), "ext" => array());
     $storage->updateResourceOwner(new MockResourceOwner($resourceOwner));
     $storage->addApproval('testcodeclient', 'fkooman', 'read write foo', 'r3fr3sh');
     $storage->addApproval('testnativeclient', 'fkooman', 'read', 'n4t1v3r3fr3sh');
     $storage->storeAuthorizationCode("4uth0r1z4t10n", "fkooman", time(), "testcodeclient", NULL, "read");
     $storage->storeAuthorizationCode("3xp1r3d4uth0r1z4t10n", "fkooman", time() - 1000, "testcodeclient", NULL, "read");
     $storage->storeAuthorizationCode("n4t1v34uth0r1z4t10n", "fkooman", time(), "testnativeclient", NULL, "read");
     $storage->storeAuthorizationCode("authorizeRequestWithRedirectUri", "fkooman", time(), "testcodeclient", "http://localhost/php-oauth/unit/test.html", "read");
 }
	public function __construct($config) {
		$system = array(
			'requires' => array(
				'id' => true,
				'secret' => false,
				'access_token' => false,
				'acess_token_secret' => false,
				'private_key' => false,
				'public_key' => false,
				'callback' => true,
				'scope' => true,
			),
			'legs' => array(
				'request_token' => 'https://www.google.com/accounts/OAuthGetRequestToken?scope=$info[scope]',
				'authorize' => 'https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=$info[request_token]',
				'access_token' => 'https://www.google.com/accounts/OAuthGetAccessToken',
			),
			'use_auth_header' => true,
			'version' => '1.0',
		);
		parent::__construct($system,$config);
		
		$this->default_parse_mode = 'xml';
	}
	public function __construct($config) {
		$system = array(
			'requires' => array(
				'id' => true,
				'secret' => true,
				'access_token' => false,
				'access_token_secret' => false,
				'private_key' => false,
				'public_key' => false,
				'callback' => false,
			),
			'legs' => array(
				'request_token' => 'http://twitter.com/oauth/request_token',
				//'authorize' => 'http://twitter.com/oauth/authorize?oauth_token=$info[request_token]',
				'authorize' => 'http://twitter.com/oauth/authenticate?oauth_token=$info[request_token]', //use this to make the process as fast as possible
				'access_token' => 'http://twitter.com/oauth/access_token',
			),
			'use_auth_header' => false,
			'version' => '1.0',
		);
		parent::__construct($system,$config);
		
		$this->default_parse_mode = 'xml';
	}
Exemplo n.º 6
0
 public function fetch($uri, $method, $parameters = array(), $parse_mode = null, $expect_http_code = 200)
 {
     switch ($this->system['version']) {
         case '1.0':
             $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, $method, $uri, $parameters);
             if ($this->system['info']['secret'] === false) {
                 $request->sign_request(new SystemBasedOAuthSignatureMethod_RSA_SHA1($this->system['info']), $this->consumer, $this->access_token);
             } else {
                 $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $this->consumer, $this->access_token);
             }
             $this->debug('BASE STRING: ' . $request->get_signature_base_string());
             if ($this->system['use_auth_header']) {
                 $to_header = $request->to_header();
                 $response_raw = $this->sendRequest($uri, $method, $request->to_postdata(), array($to_header));
             } else {
                 $response_raw = $this->sendRequest($request->to_url(), $method, $request->to_postdata());
             }
             break;
         case '2.0':
             if ($this->system['info']['access_token']) {
                 if (strpos($uri, '?') === false) {
                     $uri .= '?';
                 } else {
                     $uri .= '&';
                 }
                 $uri .= 'access_token=' . $this->system['info']['access_token'];
             }
             $response_raw = $this->sendRequest($uri, $method, $parameters);
             break;
     }
     if (!is_numeric($expect_http_code) or $expect_http_code == $this->http_code) {
         $response = false;
         if ($parse_mode === null) {
             $parse_mode = $this->default_parse_mode;
         }
         switch ($parse_mode) {
             case 'xml':
                 $this->debug('Parsing as XML');
                 $response = OAuthHelper::parse_xml($response_raw);
                 break;
             case 'json':
                 $this->debug('Parsing as JSON');
                 $response = OAuthHelper::parse_json($response_raw);
                 break;
             case 'param':
                 $this->debug('Parsing as Parametters');
                 parse_str($response_raw, $response);
                 break;
             case 'none':
                 $this->debug('No parsing!');
                 $response = $response_raw;
                 break;
             case 'custom':
             default:
                 $this->debug('Calling custom parsing method');
                 $response = $this->parse_response($response_raw, $parse_mode);
                 break;
         }
     } else {
         $this->debug('UNEXPECTED HTTP CODE: ' . $this->http_code . ' (SHOULD BE ' . $expect_http_code . ')');
         $response = $response_raw;
     }
     $this->debug('Response: <pre>' . var_export($response, true) . '</pre><hr/>');
     return $response;
 }
Exemplo n.º 7
0
 protected function parse_response($raw, $mode)
 {
     if ($mode == 'fb_json') {
         $response = OAuthHelper::parse_json($raw);
         if (isset($response['data'])) {
             $data = $response['data'];
             unset($response);
         } else {
             $data =& $response;
         }
         foreach (array_keys($data) as $key) {
             if (!is_array($data[$key])) {
                 continue;
             }
             $type = false;
             $has = array();
             //album
             if (strpos($data[$key]['link'], 'album.php') !== false) {
                 $type = 'album';
                 $has = array('photos' => 'photo', 'comments' => 'comment');
             } else {
                 if (isset($data[$key]['start_time']) and isset($data[$key]['venue'])) {
                     $type = 'event';
                     $has = array('feed' => 'post', 'picture' => 'picture', 'noreply' => 'user', 'maybe' => 'user', 'invited' => 'user', 'attending' => 'user', 'declined' => 'user');
                 } else {
                     if (isset($data[$key]['venue'])) {
                         $type = 'group';
                         $has = array('feed' => 'post', 'members' => 'user', 'picture' => 'picture');
                     } else {
                         if (isset($data[$key]['to']) and isset($data[$key]['message'])) {
                             $type = 'message';
                             $has = array('comments' => 'comment');
                         } else {
                             if (isset($data[$key]['subject']) and isset($data[$key]['message'])) {
                                 $type = 'note';
                                 $has = array('comments' => 'comment');
                             } else {
                                 if (isset($data[$key]['category'])) {
                                     $type = 'page';
                                     $has = array('feed' => 'post', 'picture' => 'picture', 'tagged' => 'post', 'links' => 'post', 'photos' => 'photo', 'groups' => 'group', 'albums' => 'album', 'statuses' => 'post', 'videos' => 'video', 'notes' => 'note', 'posts' => 'post', 'events' => 'event');
                                 } else {
                                     if (isset($data[$key]['picture'])) {
                                         $type = 'photo';
                                         $has = array('comments' => 'comment');
                                     } else {
                                         if (isset($data[$key]['first_name']) and isset($data[$key]['last_name'])) {
                                             $type = 'user';
                                             $has = array('home' => 'post', 'feed' => 'post', 'tagged' => 'post', 'posts' => 'post', 'picture' => 'picture', 'friends' => 'user', 'activities' => 'page', 'interests' => 'page', 'music' => 'page', 'books' => 'page', 'movies' => 'page', 'television' => 'page', 'likes' => 'page', 'photos' => 'photo', 'albums' => 'album', 'videos' => 'video', 'groups' => 'group', 'statuses' => 'post', 'links' => 'post', 'notes' => 'note', 'events' => 'event', 'inbox' => 'message', 'outbox' => 'message', 'updates' => 'message');
                                         } else {
                                             if (isset($data[$key]['length'])) {
                                                 $type = 'video';
                                                 $has = array('comments' => 'comment');
                                             } else {
                                                 if (isset($data[$key]['from'])) {
                                                     //maybe a post
                                                     $type = 'post';
                                                     $has = array('comments' => 'comment');
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         return $data;
     } else {
         return parent::parse_response($raw, $mode);
     }
 }
Exemplo n.º 8
0
require_once '../include/PassHash.php';
require_once '../include/OAuthHelper.php';
require '.././libs/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
/**
 * User Registration
 * url - /register
 * method - POST
 * params - access_type
 *       1: name, email, password
 *       2: service_id, access_token
 *       3: service_id, access_token 
 */
$app->post('/register', function () use($app) {
    $oauthHelper = new OAuthHelper();
    // check for required access_type
    verifyRequiredParams(array('access_type', 'passkey', 'passcode'));
    $access_type = $app->request->post('access_type');
    $passkey = $app->request->post('passkey');
    $passcode = $app->request->post('passcode');
    // verify parameters based on access_type
    if ($access_type == AUTHENTICATION_METHOD_PASSWORD) {
        // email/password
        $res = $oauthHelper->createUserByUsernameAndPassword($passkey, $passcode);
    } else {
        if ($access_type == AUTHENTICATION_METHOD_FACEBOOK) {
            // facebook
            $res = $oauthHelper->createUserByFacebook($passkey, $passcode);
        } else {
            if ($access_type == AUTHENTICATION_METHOD_TWITTER) {