├── CHANGELOG ├── LICENSE ├── README.md ├── VERSION ├── composer.json ├── lib ├── Semantics3.php ├── Semantics3 │ ├── ApiConnector.php │ ├── AuthenticationError.php │ ├── Error.php │ ├── ParameterError.php │ └── Products.php └── oauth-php │ ├── LICENSE │ ├── README │ ├── example │ ├── client │ │ ├── googledocs.php │ │ ├── twolegged.php │ │ ├── twoleggedtest.php │ │ └── twoleggedtwitter.php │ └── server │ │ ├── INSTALL │ │ ├── core │ │ ├── init.php │ │ └── templates │ │ │ ├── inc │ │ │ ├── footer.tpl │ │ │ └── header.tpl │ │ │ ├── index.tpl │ │ │ ├── logon.tpl │ │ │ └── register.tpl │ │ └── www │ │ ├── hello.php │ │ ├── index.php │ │ ├── logon.php │ │ ├── oauth.php │ │ ├── register.php │ │ └── services.xrds.php │ ├── library │ ├── OAuthDiscovery.php │ ├── OAuthException2.php │ ├── OAuthRequest.php │ ├── OAuthRequestLogger.php │ ├── OAuthRequestSigner.php │ ├── OAuthRequestVerifier.php │ ├── OAuthRequester.php │ ├── OAuthServer.php │ ├── OAuthSession.php │ ├── OAuthStore.php │ ├── body │ │ ├── OAuthBodyContentDisposition.php │ │ └── OAuthBodyMultipartFormdata.php │ ├── discovery │ │ ├── xrds_parse.php │ │ └── xrds_parse.txt │ ├── session │ │ ├── OAuthSessionAbstract.class.php │ │ └── OAuthSessionSESSION.php │ ├── signature_method │ │ ├── OAuthSignatureMethod.class.php │ │ ├── OAuthSignatureMethod_HMAC_SHA1.php │ │ ├── OAuthSignatureMethod_MD5.php │ │ ├── OAuthSignatureMethod_PLAINTEXT.php │ │ └── OAuthSignatureMethod_RSA_SHA1.php │ └── store │ │ ├── OAuthStore2Leg.php │ │ ├── OAuthStoreAbstract.class.php │ │ ├── OAuthStoreAnyMeta.php │ │ ├── OAuthStoreMySQL.php │ │ ├── OAuthStoreMySQLi.php │ │ ├── OAuthStoreOracle.php │ │ ├── OAuthStorePDO.php │ │ ├── OAuthStorePostgreSQL.php │ │ ├── OAuthStoreSQL.php │ │ ├── OAuthStoreSession.php │ │ ├── mysql │ │ ├── install.php │ │ └── mysql.sql │ │ ├── oracle │ │ ├── OracleDB │ │ │ ├── 1_Tables │ │ │ │ └── TABLES.sql │ │ │ ├── 2_Sequences │ │ │ │ └── SEQUENCES.sql │ │ │ └── 3_Procedures │ │ │ │ ├── SP_ADD_CONSUMER_REQUEST_TOKEN.prc │ │ │ │ ├── SP_ADD_LOG.prc │ │ │ │ ├── SP_ADD_SERVER_TOKEN.prc │ │ │ │ ├── SP_AUTH_CONSUMER_REQ_TOKEN.prc │ │ │ │ ├── SP_CHECK_SERVER_NONCE.prc │ │ │ │ ├── SP_CONSUMER_STATIC_SAVE.prc │ │ │ │ ├── SP_COUNT_CONSUMER_ACCESS_TOKEN.prc │ │ │ │ ├── SP_COUNT_SERVICE_TOKENS.prc │ │ │ │ ├── SP_DELETE_CONSUMER.prc │ │ │ │ ├── SP_DELETE_SERVER.prc │ │ │ │ ├── SP_DELETE_SERVER_TOKEN.prc │ │ │ │ ├── SP_DEL_CONSUMER_ACCESS_TOKEN.prc │ │ │ │ ├── SP_DEL_CONSUMER_REQUEST_TOKEN.prc │ │ │ │ ├── SP_EXCH_CONS_REQ_FOR_ACC_TOKEN.prc │ │ │ │ ├── SP_GET_CONSUMER.prc │ │ │ │ ├── SP_GET_CONSUMER_ACCESS_TOKEN.prc │ │ │ │ ├── SP_GET_CONSUMER_REQUEST_TOKEN.prc │ │ │ │ ├── SP_GET_CONSUMER_STATIC_SELECT.prc │ │ │ │ ├── SP_GET_SECRETS_FOR_SIGNATURE.prc │ │ │ │ ├── SP_GET_SECRETS_FOR_VERIFY.prc │ │ │ │ ├── SP_GET_SERVER.prc │ │ │ │ ├── SP_GET_SERVER_FOR_URI.prc │ │ │ │ ├── SP_GET_SERVER_TOKEN.prc │ │ │ │ ├── SP_GET_SERVER_TOKEN_SECRETS.prc │ │ │ │ ├── SP_LIST_CONSUMERS.prc │ │ │ │ ├── SP_LIST_CONSUMER_TOKENS.prc │ │ │ │ ├── SP_LIST_LOG.prc │ │ │ │ ├── SP_LIST_SERVERS.prc │ │ │ │ ├── SP_LIST_SERVER_TOKENS.prc │ │ │ │ ├── SP_SET_CONSUMER_ACC_TOKEN_TTL.prc │ │ │ │ ├── SP_SET_SERVER_TOKEN_TTL.prc │ │ │ │ ├── SP_UPDATE_CONSUMER.prc │ │ │ │ └── SP_UPDATE_SERVER.prc │ │ └── install.php │ │ └── postgresql │ │ └── pgsql.sql │ └── test │ ├── discovery │ ├── xrds-fireeagle.xrds │ ├── xrds-getsatisfaction.xrds │ └── xrds-magnolia.xrds │ └── oauth_test.php └── test.php /CHANGELOG: -------------------------------------------------------------------------------- 1 | === 1.0.0 2013-02-12 2 | 3 | * First version of the Products API bindings 4 | 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2013 Semantics3 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.0.0 -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "semantics3/semantics3-php", 3 | "description": "PHP library bindings for the Semantics3 APIs", 4 | "keywords": [ 5 | "semantics3", 6 | "products data", 7 | "api" 8 | ], 9 | "homepage": "https://www.semantics3.com/", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Semantics3 and contributors", 14 | "homepage": "https://github.com/semantics3/semantics3-php/contributors" 15 | } 16 | ], 17 | "require": { 18 | "php": ">=5.4" 19 | }, 20 | "autoload": { 21 | "classmap": ["lib/Semantics3/"] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/Semantics3.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 10 | $this->apiSecret = $apiSecret; 11 | $this->apiBase = is_null($apiBase) ? "https://api.semantics3.com/v1/" : $apiBase; 12 | } 13 | 14 | public function run_query($endpoint, $params, $method="GET", array $requestOptions = []) 15 | { 16 | if (!$this->apiKey) 17 | throw new Semantics3_AuthenticationError('No API key provided.'); 18 | 19 | if (!$this->apiSecret) 20 | throw new Semantics3_AuthenticationError('No API secret provided.'); 21 | 22 | $options = array( 'consumer_key' => $this->apiKey, 'consumer_secret' => $this->apiSecret ); 23 | OAuthStore::instance("2Leg", $options ); 24 | $url = $this->apiBase.$endpoint; 25 | if ($method == "GET") { 26 | $url = $url."?q=".urlencode(json_encode($params)); 27 | } 28 | else { 29 | $params = json_encode($params); 30 | } 31 | 32 | try 33 | { 34 | switch ($method) { 35 | case "GET": 36 | $request = new OAuthRequester($url, $method); 37 | break; 38 | case "POST": 39 | $request = new OAuthRequester($url, $method, '', $params); 40 | break; 41 | case "DELETE": 42 | $request = new OAuthRequester($url, $method); 43 | break; 44 | default: 45 | $request = new OAuthRequester($url, $method); 46 | } 47 | 48 | $usrId = array_key_exists('usrId', $requestOptions) ? $requestOptions['usrId'] : 0; 49 | $curlOptions = array_key_exists('curlOptions', $requestOptions) ? $requestOptions['curlOptions'] : []; 50 | $options = array_key_exists('options', $requestOptions) ? $requestOptions['options'] : []; 51 | 52 | $result = $request->doRequest($usrId, $curlOptions, $options); 53 | return $result['body']; 54 | } 55 | catch(OAuthException2 $e) 56 | { 57 | print "\n"; 58 | $error = $e->getMessage(); 59 | print $error."\n"; 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /lib/Semantics3/AuthenticationError.php: -------------------------------------------------------------------------------- 1 | http_status = $http_status; 9 | $this->http_body = $http_body; 10 | $this->json_body = $json_body; 11 | } 12 | 13 | public function getHttpStatus() 14 | { 15 | return $this->http_status; 16 | } 17 | 18 | public function getHttpBody() 19 | { 20 | return $this->http_body; 21 | } 22 | 23 | public function getJsonBody() 24 | { 25 | return $this->json_body; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/Semantics3/ParameterError.php: -------------------------------------------------------------------------------- 1 | _data_query)){ 48 | $this->_data_query[$endpoint] = array(); 49 | } 50 | $this->_data_query[$endpoint] = array_merge_recursive((array)$this->_data_query[$endpoint], call_user_func_array("self::_nest_arguments", $args) ); 51 | 52 | } 53 | 54 | public function remove(){ 55 | $args = func_get_args(); 56 | $endpoint = array_shift($args); 57 | 58 | $query = &$this->_data_query[$endpoint]; 59 | 60 | foreach ($args as $value){ 61 | if (array_key_exists($value,(array)$query)){ 62 | if (end($args) == $value){ 63 | unset($query[$value]); 64 | } 65 | else 66 | $query = &$query[$value]; 67 | } 68 | else { 69 | throw new Semantics3_ParameterError("Attempted to detele something which didn't exist."); 70 | } 71 | } 72 | } 73 | 74 | /** 75 | * get the categories from the API 76 | * 77 | * This function calls the API and returns the categories based on the query 78 | */ 79 | public function get_categories(){ 80 | $this->_query_result = parent::run_query("categories",$this->_data_query["categories"]); 81 | return $this->_query_result; 82 | } 83 | 84 | public function get_offers(){ 85 | $this->_query_result = parent::run_query("offers",$this->_data_query["offers"]); 86 | return $this->_query_result; 87 | } 88 | 89 | private function _nest_arguments(){ 90 | $args = func_get_args(); 91 | 92 | $query_key = $args[0]; 93 | if (count($args) == 2){ 94 | $query[$query_key] = $args[1]; 95 | } 96 | else if (count($args) > 2) { 97 | unset($args[0]); 98 | $args = array_values($args); 99 | $query[$query_key] = call_user_func_array("self::_nest_arguments", $args); 100 | } 101 | 102 | return $query; 103 | } 104 | 105 | /** 106 | * set the sitedetails fields 107 | * 108 | * This function sets the sitedetails fields 109 | */ 110 | public function sitedetails(){ 111 | $args = func_get_args(); 112 | array_unshift($args, "sitedetails"); 113 | 114 | call_user_func_array("self::products_field", $args); 115 | } 116 | 117 | /** 118 | * set the latestoffers fields 119 | * 120 | * This function sets the latestoffers fields 121 | */ 122 | public function latestoffers($field_name, $field_value1, $field_value2){ 123 | $args = array("sitedetails", $field_name, $field_value1, $field_value2); 124 | 125 | call_user_func_array("self::products_field", $args); 126 | } 127 | 128 | public function limit($limit){ 129 | $args = array("limit", $limit); 130 | 131 | call_user_func_array("self::products_field", $args); 132 | } 133 | 134 | public function offset($offset){ 135 | $args = array("offset", $offset); 136 | 137 | call_user_func_array("self::products_field", $args); 138 | } 139 | 140 | public function sort_list($sort_field, $sort_value){ 141 | $args = array("sort", $sort_field, $sort_value); 142 | 143 | call_user_func_array("self::products_field", $args); 144 | } 145 | 146 | private function _get_products_field(){ 147 | # Throw exception if no product field 148 | return json_encode($this->_data_query["products"]); 149 | } 150 | 151 | public function clear_query(){ 152 | $this->_data_query = array(); 153 | $this->_query_result = array(); 154 | } 155 | 156 | public function iterate_products(){ 157 | if (gettype($this->_query_result) == "string"){ 158 | $query_result = json_decode($this->_query_result, true); 159 | if (!array_key_exists('total_results_count', $query_result) || (array_key_exists('offset', $query_result) && $query_result['offset'] >= $query_result['total_results_count'])) 160 | return 0; 161 | 162 | $limit = 10; 163 | 164 | if (array_key_exists('limit', $this->_data_query["products"])) 165 | $limit = $this->_data_query["products"]['limit']; 166 | 167 | if (!array_key_exists('offset', $query_result)) 168 | $this->_data_query["products"]['offset'] = 0; 169 | else 170 | $this->_data_query["products"]['offset'] = $query_result['offset']; 171 | 172 | $this->_data_query["products"]['offset'] += $limit; 173 | } 174 | return $this->get_products(); 175 | } 176 | 177 | public function all_products(){ 178 | $query_result = json_decode($this->_query_result, true); 179 | return array_key_exists('results', $query_result) ? $query_result['results'] : 0; 180 | } 181 | 182 | public function query_json($endpoint, $query_json){ 183 | $this->_query_result = parent::run_query($endpoint,json_decode($query_json)); 184 | return $this->_query_result; 185 | } 186 | 187 | public function get_query_json($endpoint = null){ 188 | if ($endpoint == null){ 189 | throw new Semantics3_ParameterError("Query Endpoint was not defined. You need to provide one. Eg: products"); 190 | } 191 | return json_encode($this->_data_query[$endpoint]); 192 | } 193 | 194 | public function get_query($endpoint = null){ 195 | if ($endpoint == null){ 196 | throw new Semantics3_ParameterError("Query Endpoint was not defined. You need to provide one. Eg: products"); 197 | } 198 | return $this->_data_query[$endpoint]; 199 | } 200 | 201 | public function get_products(){ 202 | $this->_query_result = parent::run_query("products",$this->_data_query["products"]); 203 | return $this->_query_result; 204 | } 205 | 206 | public function query($endpoint, $query_arr = array()){ 207 | $this->_query_result = parent::run_query($endpoint,$query_arr); 208 | return $this->_query_result; 209 | } 210 | 211 | } 212 | -------------------------------------------------------------------------------- /lib/oauth-php/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2007-2009 Mediamatic Lab 4 | Copyright (c) 2010 Corollarium Technologies 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. -------------------------------------------------------------------------------- /lib/oauth-php/README: -------------------------------------------------------------------------------- 1 | Please see http://code.google.com/p/oauth-php/ for documentation and help. 2 | -------------------------------------------------------------------------------- /lib/oauth-php/example/client/googledocs.php: -------------------------------------------------------------------------------- 1 | GOOGLE_CONSUMER_KEY, 48 | 'consumer_secret' => GOOGLE_CONSUMER_SECRET, 49 | 'server_uri' => GOOGLE_OAUTH_HOST, 50 | 'request_token_uri' => GOOGLE_REQUEST_TOKEN_URL, 51 | 'authorize_uri' => GOOGLE_AUTHORIZE_URL, 52 | 'access_token_uri' => GOOGLE_ACCESS_TOKEN_URL 53 | ); 54 | // Note: do not use "Session" storage in production. Prefer a database 55 | // storage, such as MySQL. 56 | OAuthStore::instance("Session", $options); 57 | 58 | try 59 | { 60 | // STEP 1: If we do not have an OAuth token yet, go get one 61 | if (empty($_GET["oauth_token"])) 62 | { 63 | $getAuthTokenParams = array('scope' => 64 | 'http://docs.google.com/feeds/', 65 | 'xoauth_displayname' => 'Oauth test', 66 | 'oauth_callback' => 'http://likeorhate.local/google.php'); 67 | 68 | // get a request token 69 | $tokenResultParams = OAuthRequester::requestRequestToken(GOOGLE_CONSUMER_KEY, 0, $getAuthTokenParams); 70 | 71 | // redirect to the google authorization page, they will redirect back 72 | header("Location: " . GOOGLE_AUTHORIZE_URL . "?btmpl=mobile&oauth_token=" . $tokenResultParams['token']); 73 | } 74 | else { 75 | // STEP 2: Get an access token 76 | $oauthToken = $_GET["oauth_token"]; 77 | 78 | // echo "oauth_verifier = '" . $oauthVerifier . "'
"; 79 | $tokenResultParams = $_GET; 80 | 81 | try { 82 | OAuthRequester::requestAccessToken(GOOGLE_CONSUMER_KEY, $oauthToken, 0, 'POST', $_GET); 83 | } 84 | catch (OAuthException2 $e) 85 | { 86 | var_dump($e); 87 | // Something wrong with the oauth_token. 88 | // Could be: 89 | // 1. Was already ok 90 | // 2. We were not authorized 91 | return; 92 | } 93 | 94 | // make the docs requestrequest. 95 | $request = new OAuthRequester("http://docs.google.com/feeds/documents/private/full", 'GET', $tokenResultParams); 96 | $result = $request->doRequest(0); 97 | if ($result['code'] == 200) { 98 | var_dump($result['body']); 99 | } 100 | else { 101 | echo 'Error'; 102 | } 103 | } 104 | } 105 | catch(OAuthException2 $e) { 106 | echo "OAuthException: " . $e->getMessage(); 107 | var_dump($e); 108 | } 109 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/example/client/twolegged.php: -------------------------------------------------------------------------------- 1 | $key, 'consumer_secret' => $secret); 44 | OAuthStore::instance("2Leg", $options); 45 | 46 | $method = "GET"; 47 | $params = null; 48 | 49 | try 50 | { 51 | // Obtain a request object for the request we want to make 52 | $request = new OAuthRequester($url, $method, $params); 53 | 54 | // Sign the request, perform a curl request and return the results, 55 | // throws OAuthException2 exception on an error 56 | // $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string) 57 | $result = $request->doRequest(); 58 | 59 | $response = $result['body']; 60 | var_dump($response); 61 | } 62 | catch(OAuthException2 $e) 63 | { 64 | echo "Exception"; 65 | } 66 | 67 | ?> 68 | -------------------------------------------------------------------------------- /lib/oauth-php/example/client/twoleggedtest.php: -------------------------------------------------------------------------------- 1 | $key, 'consumer_secret' => $secret); 45 | OAuthStore::instance("2Leg", $options); 46 | 47 | $method = "GET"; 48 | $params = null; 49 | 50 | try 51 | { 52 | // Obtain a request object for the request we want to make 53 | $request = new OAuthRequester($url, $method, $params); 54 | 55 | // Sign the request, perform a curl request and return the results, 56 | // throws OAuthException2 exception on an error 57 | // $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string) 58 | $result = $request->doRequest(); 59 | 60 | $response = $result['body']; 61 | 62 | if ($response != 'oauth_token=requestkey&oauth_token_secret=requestsecret') 63 | { 64 | echo 'Error! $response ' . $response; 65 | } 66 | else 67 | { 68 | } 69 | 70 | 71 | var_dump($response); 72 | } 73 | catch(OAuthException2 $e) 74 | { 75 | echo "Exception" . $e->getMessage(); 76 | } 77 | 78 | ?> 79 | -------------------------------------------------------------------------------- /lib/oauth-php/example/client/twoleggedtwitter.php: -------------------------------------------------------------------------------- 1 | TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET); 49 | OAuthStore::instance("2Leg", $options); 50 | 51 | try 52 | { 53 | // Obtain a request object for the request we want to make 54 | $request = new OAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST"); 55 | $result = $request->doRequest(0); 56 | parse_str($result['body'], $params); 57 | 58 | echo "aa"; 59 | 60 | // now make the request. 61 | $request = new OAuthRequester(TWITTER_PUBLIC_TIMELINE_API, 'GET', $params); 62 | $result = $request->doRequest(); 63 | } 64 | catch(OAuthException2 $e) 65 | { 66 | echo "Exception" . $e->getMessage(); 67 | } 68 | 69 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/example/server/INSTALL: -------------------------------------------------------------------------------- 1 | In this example I assume that oauth-php lives in /home/john/src/oauth-php 2 | 3 | 4 | 1) Create a virtual host and set the DB_DSN VARIABLE to the DSN of your (mysql) database. 5 | 6 | Example 7 | 8 | ServerAdmin admin@localhost 9 | ServerName hello.local 10 | DocumentRoot /home/john/src/oauth-php/example/server/www 11 | 12 | UseCanonicalName Off 13 | ServerSignature On 14 | 15 | SetEnv DB_DSN mysql://foo:bar@localhost/oauth_example_server_db 16 | 17 | 18 | Options Indexes FollowSymLinks MultiViews 19 | AllowOverride None 20 | Order allow,deny 21 | Allow from all 22 | 23 | 24 | php_value magic_quotes_gpc 0 25 | php_value register_globals 0 26 | php_value session.auto_start 0 27 | 28 | 29 | 30 | 31 | 32 | 33 | 2) Create the database structure for the server: 34 | 35 | # mysql -u foo -p bar -h localhost < /home/john/src/oauth-php/library/store/mysql/mysql.sql 36 | 37 | 38 | 39 | 3) Download and install smarty into the smarty/core/smarty directory: 40 | 41 | # cd /home/john/src/oauth-php/example/server/core 42 | # wget 'http://www.smarty.net/do_download.php?download_file=Smarty-2.6.19.tar.gz' 43 | # tar zxf Smarty-2.6.19.tar.gz 44 | # mv Smarty-2.6.19 smarty 45 | 46 | 47 | 4) That's it! Point your browser to 48 | 49 | http://hello.local/ 50 | 51 | To get started. 52 | 53 | Arjan Scherpenisse , July 2008 54 | -------------------------------------------------------------------------------- /lib/oauth-php/example/server/core/init.php: -------------------------------------------------------------------------------- 1 | 10 | * 11 | * 12 | * The MIT License 13 | * 14 | * Copyright (c) 2007-2008 Mediamatic Lab 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy 17 | * of this software and associated documentation files (the "Software"), to deal 18 | * in the Software without restriction, including without limitation the rights 19 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | * copies of the Software, and to permit persons to whom the Software is 21 | * furnished to do so, subject to the following conditions: 22 | * 23 | * The above copyright notice and this permission notice shall be included in 24 | * all copies or substantial portions of the Software. 25 | * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | * THE SOFTWARE. 33 | */ 34 | 35 | 36 | /* 37 | * Simple 'user management' 38 | */ 39 | define ('USERNAME', 'sysadmin'); 40 | define ('PASSWORD', 'sysadmin'); 41 | 42 | 43 | /* 44 | * Always announce XRDS OAuth discovery 45 | */ 46 | header('X-XRDS-Location: http://' . $_SERVER['SERVER_NAME'] . '/services.xrds'); 47 | 48 | 49 | /* 50 | * Initialize the database connection 51 | */ 52 | $info = parse_url(getenv('DB_DSN')); 53 | ($GLOBALS['db_conn'] = mysql_connect($info['host'], $info['user'], $info['pass'])) || die(mysql_error()); 54 | mysql_select_db(basename($info['path']), $GLOBALS['db_conn']) || die(mysql_error()); 55 | unset($info); 56 | 57 | 58 | require_once '../../../library/OAuthServer.php'; 59 | 60 | /* 61 | * Initialize OAuth store 62 | */ 63 | require_once '../../../library/OAuthStore.php'; 64 | OAuthStore::instance('MySQL', array('conn' => $GLOBALS['db_conn'])); 65 | 66 | 67 | /* 68 | * Session 69 | */ 70 | session_start(); 71 | 72 | 73 | /* 74 | * Template handling 75 | */ 76 | require_once 'smarty/libs/Smarty.class.php'; 77 | function session_smarty() 78 | { 79 | if (!isset($GLOBALS['smarty'])) 80 | { 81 | $GLOBALS['smarty'] = new Smarty; 82 | $GLOBALS['smarty']->template_dir = dirname(__FILE__) . '/templates/'; 83 | $GLOBALS['smarty']->compile_dir = dirname(__FILE__) . '/../cache/templates_c'; 84 | } 85 | 86 | return $GLOBALS['smarty']; 87 | } 88 | 89 | function assert_logged_in() 90 | { 91 | if (empty($_SESSION['authorized'])) 92 | { 93 | $uri = $_SERVER['REQUEST_URI']; 94 | header('Location: /logon?goto=' . urlencode($uri)); 95 | exit(); 96 | } 97 | } 98 | 99 | function assert_request_vars() 100 | { 101 | foreach(func_get_args() as $a) 102 | { 103 | if (!isset($_REQUEST[$a])) 104 | { 105 | header('HTTP/1.1 400 Bad Request'); 106 | echo 'Bad request.'; 107 | exit; 108 | } 109 | } 110 | } 111 | 112 | function assert_request_vars_all() 113 | { 114 | foreach($_REQUEST as $row) 115 | { 116 | foreach(func_get_args() as $a) 117 | { 118 | if (!isset($row[$a])) 119 | { 120 | header('HTTP/1.1 400 Bad Request'); 121 | echo 'Bad request.'; 122 | exit; 123 | } 124 | } 125 | } 126 | } 127 | 128 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/example/server/core/templates/inc/footer.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /lib/oauth-php/example/server/core/templates/inc/header.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /lib/oauth-php/example/server/core/templates/index.tpl: -------------------------------------------------------------------------------- 1 | {include file='inc/header.tpl'} 2 | 3 |

OAuth server

4 | Go to: 5 | 6 | 10 | 11 | Afterwards, make an OAuth test request to http://{$smarty.server.name}/hello to test your connection.

12 | 13 | {include file='inc/footer.tpl'} 14 | -------------------------------------------------------------------------------- /lib/oauth-php/example/server/core/templates/logon.tpl: -------------------------------------------------------------------------------- 1 | {include file='inc/header.tpl'} 2 | 3 |

Login

4 | 5 |
6 | 7 | 8 |
9 | 10 | 11 |

12 | 13 |
14 | 15 | 16 |

17 | 18 | 19 |
20 | 21 | {include file='inc/footer.tpl'} 22 | -------------------------------------------------------------------------------- /lib/oauth-php/example/server/core/templates/register.tpl: -------------------------------------------------------------------------------- 1 | {include file='inc/header.tpl'} 2 | 3 |

Register server

4 | 5 |

Register a server which is gonna act as an identity client.

6 | 7 |
8 | 9 |
10 | About You 11 | 12 |

13 |
14 | 15 |

16 | 17 |

18 |
19 | 20 |

21 |
22 | 23 |
24 | Location Of Your Application Or Site 25 | 26 |

27 |
28 | 29 |

30 | 31 |

32 |
33 | 34 |

35 |
36 | 37 |
38 | 39 |
40 | 41 | {include file='inc/footer.tpl'} 42 | -------------------------------------------------------------------------------- /lib/oauth-php/example/server/www/hello.php: -------------------------------------------------------------------------------- 1 | 11 | * 12 | * 13 | * The MIT License 14 | * 15 | * Copyright (c) 2007-2008 Mediamatic Lab 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy 18 | * of this software and associated documentation files (the "Software"), to deal 19 | * in the Software without restriction, including without limitation the rights 20 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 21 | * copies of the Software, and to permit persons to whom the Software is 22 | * furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included in 25 | * all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 30 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 32 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 33 | * THE SOFTWARE. 34 | */ 35 | 36 | require_once '../core/init.php'; 37 | 38 | $authorized = false; 39 | $server = new OAuthServer(); 40 | try 41 | { 42 | if ($server->verifyIfSigned()) 43 | { 44 | $authorized = true; 45 | } 46 | } 47 | catch (OAuthException2 $e) 48 | { 49 | } 50 | 51 | if (!$authorized) 52 | { 53 | header('HTTP/1.1 401 Unauthorized'); 54 | header('Content-Type: text/plain'); 55 | 56 | echo "OAuth Verification Failed: " . $e->getMessage(); 57 | die; 58 | } 59 | 60 | // From here on we are authenticated with OAuth. 61 | 62 | header('Content-type: text/plain'); 63 | echo 'Hello, world!'; 64 | 65 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/example/server/www/index.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * 9 | * The MIT License 10 | * 11 | * Copyright (c) 2007-2008 Mediamatic Lab 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | require '../core/init.php'; 33 | 34 | $smarty = session_smarty(); 35 | $smarty->display('index.tpl'); 36 | 37 | ?> 38 | -------------------------------------------------------------------------------- /lib/oauth-php/example/server/www/logon.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * 11 | * The MIT License 12 | * 13 | * Copyright (c) 2007-2008 Mediamatic Lab 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | */ 33 | 34 | require_once '../core/init.php'; 35 | 36 | if (isset($_POST['username']) && isset($_POST['password'])) 37 | { 38 | if ($_POST['username'] == USERNAME && $_POST['password'] == PASSWORD) 39 | { 40 | $_SESSION['authorized'] = true; 41 | if (!empty($_REQUEST['goto'])) 42 | { 43 | header('Location: ' . $_REQUEST['goto']); 44 | die; 45 | } 46 | 47 | echo "Logon succesfull."; 48 | die; 49 | } 50 | } 51 | 52 | $smarty = session_smarty(); 53 | $smarty->display('logon.tpl'); 54 | 55 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/example/server/www/oauth.php: -------------------------------------------------------------------------------- 1 | 12 | * 13 | * 14 | * The MIT License 15 | * 16 | * Copyright (c) 2007-2008 Mediamatic Lab 17 | * 18 | * Permission is hereby granted, free of charge, to any person obtaining a copy 19 | * of this software and associated documentation files (the "Software"), to deal 20 | * in the Software without restriction, including without limitation the rights 21 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 22 | * copies of the Software, and to permit persons to whom the Software is 23 | * furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included in 26 | * all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 33 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 34 | * THE SOFTWARE. 35 | */ 36 | 37 | require_once '../core/init.php'; 38 | 39 | $server = new OAuthServer(); 40 | 41 | switch($_SERVER['PATH_INFO']) 42 | { 43 | case '/request_token': 44 | $server->requestToken(); 45 | exit; 46 | 47 | case '/access_token': 48 | $server->accessToken(); 49 | exit; 50 | 51 | case '/authorize': 52 | # logon 53 | 54 | assert_logged_in(); 55 | 56 | try 57 | { 58 | $server->authorizeVerify(); 59 | $server->authorizeFinish(true, 1); 60 | } 61 | catch (OAuthException2 $e) 62 | { 63 | header('HTTP/1.1 400 Bad Request'); 64 | header('Content-Type: text/plain'); 65 | 66 | echo "Failed OAuth Request: " . $e->getMessage(); 67 | } 68 | exit; 69 | 70 | 71 | default: 72 | header('HTTP/1.1 500 Internal Server Error'); 73 | header('Content-Type: text/plain'); 74 | echo "Unknown request"; 75 | } 76 | 77 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/example/server/www/register.php: -------------------------------------------------------------------------------- 1 | updateConsumer($_POST, $user_id, true); 14 | 15 | $c = $store->getConsumer($key, $user_id); 16 | echo 'Your consumer key is: ' . $c['consumer_key'] . '
'; 17 | echo 'Your consumer secret is: ' . $c['consumer_secret'] . '
'; 18 | } 19 | catch (OAuthException2 $e) 20 | { 21 | echo 'Error: ' . $e->getMessage() . '
'; 22 | } 23 | } 24 | 25 | 26 | $smarty = session_smarty(); 27 | $smarty->display('register.tpl'); 28 | 29 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/example/server/www/services.xrds.php: -------------------------------------------------------------------------------- 1 | 10 | * 11 | * 12 | * The MIT License 13 | * 14 | * Copyright (c) 2007-2008 Mediamatic Lab 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy 17 | * of this software and associated documentation files (the "Software"), to deal 18 | * in the Software without restriction, including without limitation the rights 19 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | * copies of the Software, and to permit persons to whom the Software is 21 | * furnished to do so, subject to the following conditions: 22 | * 23 | * The above copyright notice and this permission notice shall be included in 24 | * all copies or substantial portions of the Software. 25 | * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | * THE SOFTWARE. 33 | */ 34 | 35 | header('Content-Type: application/xrds+xml'); 36 | 37 | $server = $_SERVER['SERVER_NAME']; 38 | 39 | echo '' . "\n"; 40 | 41 | ?> 42 | 43 | 44 | xri://$xrds*simple 45 | 46 | http://oauth.net/discovery/1.0 47 | #main 48 | 49 | 50 | http://oauth.net/core/1.0/endpoint/request 51 | http://oauth.net/core/1.0/parameters/auth-header 52 | http://oauth.net/core/1.0/parameters/uri-query 53 | http://oauth.net/core/1.0/signature/HMAC-SHA1 54 | http://oauth.net/core/1.0/signature/PLAINTEXT 55 | http:///oauth/request_token 56 | 57 | 58 | http://oauth.net/core/1.0/endpoint/authorize 59 | http://oauth.net/core/1.0/parameters/uri-query 60 | http:///oauth/authorize 61 | 62 | 63 | http://oauth.net/core/1.0/endpoint/access 64 | http://oauth.net/core/1.0/parameters/auth-header 65 | http://oauth.net/core/1.0/parameters/uri-query 66 | http://oauth.net/core/1.0/signature/HMAC-SHA1 67 | http://oauth.net/core/1.0/signature/PLAINTEXT 68 | http:///oauth/access_token 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /lib/oauth-php/library/OAuthDiscovery.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Sep 4, 2008 5:05:19 PM 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | require_once dirname(__FILE__).'/discovery/xrds_parse.php'; 34 | 35 | require_once dirname(__FILE__).'/OAuthException2.php'; 36 | require_once dirname(__FILE__).'/OAuthRequestLogger.php'; 37 | 38 | 39 | class OAuthDiscovery 40 | { 41 | /** 42 | * Return a description how we can do a consumer allocation. Prefers static allocation if 43 | * possible. If static allocation is possible 44 | * 45 | * See also: http://oauth.net/discovery/#consumer_identity_types 46 | * 47 | * @param string uri 48 | * @return array provider description 49 | */ 50 | static function discover ( $uri ) 51 | { 52 | // See what kind of consumer allocations are available 53 | $xrds_file = self::discoverXRDS($uri); 54 | if (!empty($xrds_file)) 55 | { 56 | $xrds = xrds_parse($xrds_file); 57 | if (empty($xrds)) 58 | { 59 | throw new OAuthException2('Could not discover OAuth information for '.$uri); 60 | } 61 | } 62 | else 63 | { 64 | throw new OAuthException2('Could not discover XRDS file at '.$uri); 65 | } 66 | 67 | // Fill an OAuthServer record for the uri found 68 | $ps = parse_url($uri); 69 | $host = isset($ps['host']) ? $ps['host'] : 'localhost'; 70 | $server_uri = $ps['scheme'].'://'.$host.'/'; 71 | 72 | $p = array( 73 | 'user_id' => null, 74 | 'consumer_key' => '', 75 | 'consumer_secret' => '', 76 | 'signature_methods' => '', 77 | 'server_uri' => $server_uri, 78 | 'request_token_uri' => '', 79 | 'authorize_uri' => '', 80 | 'access_token_uri' => '' 81 | ); 82 | 83 | 84 | // Consumer identity (out of bounds or static) 85 | if (isset($xrds['consumer_identity'])) 86 | { 87 | // Try to find a static consumer allocation, we like those :) 88 | foreach ($xrds['consumer_identity'] as $ci) 89 | { 90 | if ($ci['method'] == 'static' && !empty($ci['consumer_key'])) 91 | { 92 | $p['consumer_key'] = $ci['consumer_key']; 93 | $p['consumer_secret'] = ''; 94 | } 95 | else if ($ci['method'] == 'oob' && !empty($ci['uri'])) 96 | { 97 | // TODO: Keep this uri somewhere for the user? 98 | $p['consumer_oob_uri'] = $ci['uri']; 99 | } 100 | } 101 | } 102 | 103 | // The token uris 104 | if (isset($xrds['request'][0]['uri'])) 105 | { 106 | $p['request_token_uri'] = $xrds['request'][0]['uri']; 107 | if (!empty($xrds['request'][0]['signature_method'])) 108 | { 109 | $p['signature_methods'] = $xrds['request'][0]['signature_method']; 110 | } 111 | } 112 | if (isset($xrds['authorize'][0]['uri'])) 113 | { 114 | $p['authorize_uri'] = $xrds['authorize'][0]['uri']; 115 | if (!empty($xrds['authorize'][0]['signature_method'])) 116 | { 117 | $p['signature_methods'] = $xrds['authorize'][0]['signature_method']; 118 | } 119 | } 120 | if (isset($xrds['access'][0]['uri'])) 121 | { 122 | $p['access_token_uri'] = $xrds['access'][0]['uri']; 123 | if (!empty($xrds['access'][0]['signature_method'])) 124 | { 125 | $p['signature_methods'] = $xrds['access'][0]['signature_method']; 126 | } 127 | } 128 | return $p; 129 | } 130 | 131 | 132 | /** 133 | * Discover the XRDS file at the uri. This is a bit primitive, you should overrule 134 | * this function so that the XRDS file can be cached for later referral. 135 | * 136 | * @param string uri 137 | * @return string false when no XRDS file found 138 | */ 139 | static protected function discoverXRDS ( $uri, $recur = 0 ) 140 | { 141 | // Bail out when we are following redirects 142 | if ($recur > 10) 143 | { 144 | return false; 145 | } 146 | 147 | $data = self::curl($uri); 148 | 149 | // Check what we got back, could be: 150 | // 1. The XRDS discovery file itself (check content-type) 151 | // 2. The X-XRDS-Location header 152 | 153 | if (is_string($data) && !empty($data)) 154 | { 155 | list($head,$body) = explode("\r\n\r\n", $data); 156 | $body = trim($body); 157 | $m = false; 158 | 159 | // See if we got the XRDS file itself or we have to follow a location header 160 | if ( preg_match('/^Content-Type:\s*application\/xrds+xml/im', $head) 161 | || preg_match('/^<\?xml[^>]*\?>\s* -------------------------------------------------------------------------------- /lib/oauth-php/library/OAuthException2.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Nov 29, 2007 5:33:54 PM 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | // TODO: something with the HTTP return code matching to the problem 34 | 35 | require_once dirname(__FILE__) . '/OAuthRequestLogger.php'; 36 | 37 | class OAuthException2 extends Exception 38 | { 39 | function __construct ( $message ) 40 | { 41 | Exception::__construct($message); 42 | OAuthRequestLogger::addNote('OAuthException2: '.$message); 43 | } 44 | 45 | } 46 | 47 | 48 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 49 | 50 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/OAuthRequestSigner.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Nov 16, 2007 4:02:49 PM 9 | * 10 | * 11 | * The MIT License 12 | * 13 | * Copyright (c) 2007-2008 Mediamatic Lab 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | */ 33 | 34 | 35 | require_once dirname(__FILE__) . '/OAuthStore.php'; 36 | require_once dirname(__FILE__) . '/OAuthRequest.php'; 37 | 38 | 39 | class OAuthRequestSigner extends OAuthRequest 40 | { 41 | protected $request; 42 | protected $store; 43 | protected $usr_id = 0; 44 | private $signed = false; 45 | 46 | 47 | /** 48 | * Construct the request to be signed. Parses or appends the parameters in the params url. 49 | * When you supply an params array, then the params should not be urlencoded. 50 | * When you supply a string, then it is assumed it is of the type application/x-www-form-urlencoded 51 | * 52 | * @param string request url 53 | * @param string method PUT, GET, POST etc. 54 | * @param mixed params string (for urlencoded data, or array with name/value pairs) 55 | * @param string body optional body for PUT and/or POST requests 56 | */ 57 | function __construct ( $request, $method = null, $params = null, $body = null ) 58 | { 59 | $this->store = OAuthStore::instance(); 60 | 61 | if (is_string($params)) 62 | { 63 | parent::__construct($request, $method, $params); 64 | } 65 | else 66 | { 67 | parent::__construct($request, $method); 68 | if (is_array($params)) 69 | { 70 | foreach ($params as $name => $value) 71 | { 72 | $this->setParam($name, $value); 73 | } 74 | } 75 | } 76 | 77 | // With put/ post we might have a body (not for application/x-www-form-urlencoded requests) 78 | if (strcasecmp($method, 'PUT') == 0 || strcasecmp($method, 'POST') == 0) 79 | { 80 | $this->setBody($body); 81 | } 82 | } 83 | 84 | 85 | /** 86 | * Reset the 'signed' flag, so that any changes in the parameters force a recalculation 87 | * of the signature. 88 | */ 89 | function setUnsigned () 90 | { 91 | $this->signed = false; 92 | } 93 | 94 | 95 | /** 96 | * Sign our message in the way the server understands. 97 | * Set the needed oauth_xxxx parameters. 98 | * 99 | * @param int usr_id (optional) user that wants to sign this request 100 | * @param array secrets secrets used for signing, when empty then secrets will be fetched from the token registry 101 | * @param string name name of the token to be used for signing 102 | * @exception OAuthException2 when there is no oauth relation with the server 103 | * @exception OAuthException2 when we don't support the signing methods of the server 104 | */ 105 | function sign ( $usr_id = 0, $secrets = null, $name = '', $token_type = null) 106 | { 107 | $url = $this->getRequestUrl(); 108 | if (empty($secrets)) 109 | { 110 | // get the access tokens for the site (on an user by user basis) 111 | $secrets = $this->store->getSecretsForSignature($url, $usr_id, $name); 112 | } 113 | if (empty($secrets)) 114 | { 115 | throw new OAuthException2('No OAuth relation with the server for at "'.$url.'"'); 116 | } 117 | 118 | $signature_method = $this->selectSignatureMethod($secrets['signature_methods']); 119 | 120 | $token = isset($secrets['token']) ? $secrets['token'] : ''; 121 | $token_secret = isset($secrets['token_secret']) ? $secrets['token_secret'] : ''; 122 | 123 | if (!$token) { 124 | $token = $this->getParam('oauth_token'); 125 | } 126 | 127 | $this->setParam('oauth_signature_method',$signature_method); 128 | $this->setParam('oauth_signature', ''); 129 | $this->setParam('oauth_nonce', !empty($secrets['nonce']) ? $secrets['nonce'] : uniqid('')); 130 | $this->setParam('oauth_timestamp', !empty($secrets['timestamp']) ? $secrets['timestamp'] : time()); 131 | if ($token_type != 'requestToken') 132 | $this->setParam('oauth_token', $token); 133 | $this->setParam('oauth_consumer_key', $secrets['consumer_key']); 134 | $this->setParam('oauth_version', '1.0'); 135 | 136 | $body = $this->getBody(); 137 | if (!is_null($body)) 138 | { 139 | // We also need to sign the body, use the default signature method 140 | $body_signature = $this->calculateDataSignature($body, $secrets['consumer_secret'], $token_secret, $signature_method); 141 | $this->setParam('xoauth_body_signature', $body_signature, true); 142 | } 143 | 144 | $signature = $this->calculateSignature($secrets['consumer_secret'], $token_secret, $token_type); 145 | $this->setParam('oauth_signature', $signature, true); 146 | // $this->setParam('oauth_signature', urldecode($signature), true); 147 | 148 | $this->signed = true; 149 | $this->usr_id = $usr_id; 150 | } 151 | 152 | 153 | /** 154 | * Builds the Authorization header for the request. 155 | * Adds all oauth_ and xoauth_ parameters to the Authorization header. 156 | * 157 | * @return string 158 | */ 159 | function getAuthorizationHeader () 160 | { 161 | if (!$this->signed) 162 | { 163 | $this->sign($this->usr_id); 164 | } 165 | $h = array(); 166 | $h[] = 'Authorization: OAuth realm=""'; 167 | foreach ($this->param as $name => $value) 168 | { 169 | if (strncmp($name, 'oauth_', 6) == 0 || strncmp($name, 'xoauth_', 7) == 0) 170 | { 171 | $h[] = $name.'="'.$value.'"'; 172 | } 173 | } 174 | $hs = implode(', ', $h); 175 | return $hs; 176 | } 177 | 178 | 179 | /** 180 | * Builds the application/x-www-form-urlencoded parameter string. Can be appended as 181 | * the query part to a GET or inside the request body for a POST. 182 | * 183 | * @param boolean oauth_as_header (optional) set to false to include oauth parameters 184 | * @return string 185 | */ 186 | function getQueryString ( $oauth_as_header = true ) 187 | { 188 | $parms = array(); 189 | foreach ($this->param as $name => $value) 190 | { 191 | if ( !$oauth_as_header 192 | || (strncmp($name, 'oauth_', 6) != 0 && strncmp($name, 'xoauth_', 7) != 0)) 193 | { 194 | if (is_array($value)) 195 | { 196 | foreach ($value as $v) 197 | { 198 | $parms[] = $name.'='.$v; 199 | } 200 | } 201 | else 202 | { 203 | $parms[] = $name.'='.$value; 204 | } 205 | } 206 | } 207 | return implode('&', $parms); 208 | } 209 | 210 | } 211 | 212 | 213 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 214 | 215 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/OAuthSession.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/oauth-php/library/OAuthStore.php: -------------------------------------------------------------------------------- 1 | 9 | * @date Nov 16, 2007 4:03:30 PM 10 | * 11 | * 12 | * The MIT License 13 | * 14 | * Copyright (c) 2007-2008 Mediamatic Lab 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy 17 | * of this software and associated documentation files (the "Software"), to deal 18 | * in the Software without restriction, including without limitation the rights 19 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | * copies of the Software, and to permit persons to whom the Software is 21 | * furnished to do so, subject to the following conditions: 22 | * 23 | * The above copyright notice and this permission notice shall be included in 24 | * all copies or substantial portions of the Software. 25 | * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | * THE SOFTWARE. 33 | */ 34 | 35 | require_once dirname(__FILE__) . '/OAuthException2.php'; 36 | 37 | class OAuthStore 38 | { 39 | static private $instance = false; 40 | 41 | /** 42 | * Request an instance of the OAuthStore 43 | */ 44 | public static function instance ( $store = 'MySQL', $options = array() ) 45 | { 46 | if (!OAuthStore::$instance) 47 | { 48 | // Select the store you want to use 49 | if (strpos($store, '/') === false) 50 | { 51 | $class = 'OAuthStore'.$store; 52 | $file = dirname(__FILE__) . '/store/'.$class.'.php'; 53 | } 54 | else 55 | { 56 | $file = $store; 57 | $store = basename($file, '.php'); 58 | $class = $store; 59 | } 60 | 61 | if (is_file($file)) 62 | { 63 | require_once $file; 64 | 65 | if (class_exists($class)) 66 | { 67 | OAuthStore::$instance = new $class($options); 68 | } 69 | else 70 | { 71 | throw new OAuthException2('Could not find class '.$class.' in file '.$file); 72 | } 73 | } 74 | else 75 | { 76 | throw new OAuthException2('No OAuthStore for '.$store.' (file '.$file.')'); 77 | } 78 | } 79 | return OAuthStore::$instance; 80 | } 81 | } 82 | 83 | 84 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 85 | 86 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/body/OAuthBodyContentDisposition.php: -------------------------------------------------------------------------------- 1 | 8 | * 9 | * The MIT License 10 | * 11 | * Copyright (c) 2007-2008 Mediamatic Lab 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | class OAuthBodyContentDisposition 33 | { 34 | /** 35 | * Builds the request string. 36 | * 37 | * The files array can be a combination of the following (either data or file): 38 | * 39 | * file => "path/to/file", filename=, mime=, data= 40 | * 41 | * @param array files (name => filedesc) (not urlencoded) 42 | * @return array (headers, body) 43 | */ 44 | static function encodeBody ( $files ) 45 | { 46 | $headers = array(); 47 | $body = null; 48 | 49 | // 1. Add all the files to the post 50 | if (!empty($files)) 51 | { 52 | foreach ($files as $name => $f) 53 | { 54 | $data = false; 55 | $filename = false; 56 | 57 | if (isset($f['filename'])) 58 | { 59 | $filename = $f['filename']; 60 | } 61 | 62 | if (!empty($f['file'])) 63 | { 64 | $data = @file_get_contents($f['file']); 65 | if ($data === false) 66 | { 67 | throw new OAuthException2(sprintf('Could not read the file "%s" for request body', $f['file'])); 68 | } 69 | if (empty($filename)) 70 | { 71 | $filename = basename($f['file']); 72 | } 73 | } 74 | else if (isset($f['data'])) 75 | { 76 | $data = $f['data']; 77 | } 78 | 79 | // When there is data, add it as a request body, otherwise silently skip the upload 80 | if ($data !== false) 81 | { 82 | if (isset($headers['Content-Disposition'])) 83 | { 84 | throw new OAuthException2('Only a single file (or data) allowed in a signed PUT/POST request body.'); 85 | } 86 | 87 | if (empty($filename)) 88 | { 89 | $filename = 'untitled'; 90 | } 91 | $mime = !empty($f['mime']) ? $f['mime'] : 'application/octet-stream'; 92 | 93 | $headers['Content-Disposition'] = 'attachment; filename="'.OAuthBodyContentDisposition::encodeParameterName($filename).'"'; 94 | $headers['Content-Type'] = $mime; 95 | 96 | $body = $data; 97 | } 98 | 99 | } 100 | 101 | // When we have a body, add the content-length 102 | if (!is_null($body)) 103 | { 104 | $headers['Content-Length'] = strlen($body); 105 | } 106 | } 107 | return array($headers, $body); 108 | } 109 | 110 | 111 | /** 112 | * Encode a parameter's name for use in a multipart header. 113 | * For now we do a simple filter that removes some unwanted characters. 114 | * We might want to implement RFC1522 here. See http://tools.ietf.org/html/rfc1522 115 | * 116 | * @param string name 117 | * @return string 118 | */ 119 | static function encodeParameterName ( $name ) 120 | { 121 | return preg_replace('/[^\x20-\x7f]|"/', '-', $name); 122 | } 123 | } 124 | 125 | 126 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 127 | 128 | 129 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/body/OAuthBodyMultipartFormdata.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Jan 31, 2008 12:50:05 PM 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | 34 | class OAuthBodyMultipartFormdata 35 | { 36 | /** 37 | * Builds the request string. 38 | * 39 | * The files array can be a combination of the following (either data or file): 40 | * 41 | * file => "path/to/file", filename=, mime=, data= 42 | * 43 | * @param array params (name => value) (all names and values should be urlencoded) 44 | * @param array files (name => filedesc) (not urlencoded) 45 | * @return array (headers, body) 46 | */ 47 | static function encodeBody ( $params, $files ) 48 | { 49 | $headers = array(); 50 | $body = ''; 51 | $boundary = 'OAuthRequester_'.md5(uniqid('multipart') . microtime()); 52 | $headers['Content-Type'] = 'multipart/form-data; boundary=' . $boundary; 53 | 54 | 55 | // 1. Add the parameters to the post 56 | if (!empty($params)) 57 | { 58 | foreach ($params as $name => $value) 59 | { 60 | $body .= '--'.$boundary."\r\n"; 61 | $body .= 'Content-Disposition: form-data; name="'.OAuthBodyMultipartFormdata::encodeParameterName(rawurldecode($name)).'"'; 62 | $body .= "\r\n\r\n"; 63 | $body .= urldecode($value); 64 | $body .= "\r\n"; 65 | } 66 | } 67 | 68 | // 2. Add all the files to the post 69 | if (!empty($files)) 70 | { 71 | $untitled = 1; 72 | 73 | foreach ($files as $name => $f) 74 | { 75 | $data = false; 76 | $filename = false; 77 | 78 | if (isset($f['filename'])) 79 | { 80 | $filename = $f['filename']; 81 | } 82 | 83 | if (!empty($f['file'])) 84 | { 85 | $data = @file_get_contents($f['file']); 86 | if ($data === false) 87 | { 88 | throw new OAuthException2(sprintf('Could not read the file "%s" for form-data part', $f['file'])); 89 | } 90 | if (empty($filename)) 91 | { 92 | $filename = basename($f['file']); 93 | } 94 | } 95 | else if (isset($f['data'])) 96 | { 97 | $data = $f['data']; 98 | } 99 | 100 | // When there is data, add it as a form-data part, otherwise silently skip the upload 101 | if ($data !== false) 102 | { 103 | if (empty($filename)) 104 | { 105 | $filename = sprintf('untitled-%d', $untitled++); 106 | } 107 | $mime = !empty($f['mime']) ? $f['mime'] : 'application/octet-stream'; 108 | $body .= '--'.$boundary."\r\n"; 109 | $body .= 'Content-Disposition: form-data; name="'.OAuthBodyMultipartFormdata::encodeParameterName($name).'"; filename="'.OAuthBodyMultipartFormdata::encodeParameterName($filename).'"'."\r\n"; 110 | $body .= 'Content-Type: '.$mime; 111 | $body .= "\r\n\r\n"; 112 | $body .= $data; 113 | $body .= "\r\n"; 114 | } 115 | 116 | } 117 | } 118 | $body .= '--'.$boundary."--\r\n"; 119 | 120 | $headers['Content-Length'] = strlen($body); 121 | return array($headers, $body); 122 | } 123 | 124 | 125 | /** 126 | * Encode a parameter's name for use in a multipart header. 127 | * For now we do a simple filter that removes some unwanted characters. 128 | * We might want to implement RFC1522 here. See http://tools.ietf.org/html/rfc1522 129 | * 130 | * @param string name 131 | * @return string 132 | */ 133 | static function encodeParameterName ( $name ) 134 | { 135 | return preg_replace('/[^\x20-\x7f]|"/', '-', $name); 136 | } 137 | } 138 | 139 | 140 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 141 | 142 | 143 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/discovery/xrds_parse.txt: -------------------------------------------------------------------------------- 1 | The xrds_parse.php script contains the function: 2 | 3 | function xrds_parse ( $data. ) 4 | 5 | $data Contains the contents of a XRDS XML file. 6 | When the data is invalid XML then this will throw an exception. 7 | 8 | After parsing a XRDS definition it will return a datastructure much like the one below. 9 | 10 | Array 11 | ( 12 | [expires] => 2008-04-13T07:34:58Z 13 | [request] => Array 14 | ( 15 | [0] => Array 16 | ( 17 | [uri] => https://ma.gnolia.com/oauth/get_request_token 18 | [signature_method] => Array 19 | ( 20 | [0] => HMAC-SHA1 21 | [1] => RSA-SHA1 22 | [2] => PLAINTEXT 23 | ) 24 | 25 | [parameters] => Array 26 | ( 27 | [0] => auth-header 28 | [1] => post-body 29 | [2] => uri-query 30 | ) 31 | ) 32 | ) 33 | 34 | [authorize] => Array 35 | ( 36 | [0] => Array 37 | ( 38 | [uri] => http://ma.gnolia.com/oauth/authorize 39 | [signature_method] => Array 40 | ( 41 | ) 42 | 43 | [parameters] => Array 44 | ( 45 | [0] => auth-header 46 | [1] => uri-query 47 | ) 48 | ) 49 | ) 50 | 51 | [access] => Array 52 | ( 53 | [0] => Array 54 | ( 55 | [uri] => https://ma.gnolia.com/oauth/get_access_token 56 | [signature_method] => Array 57 | ( 58 | [0] => HMAC-SHA1 59 | [1] => RSA-SHA1 60 | [2] => PLAINTEXT 61 | ) 62 | 63 | [parameters] => Array 64 | ( 65 | [0] => auth-header 66 | [1] => post-body 67 | [2] => uri-query 68 | ) 69 | ) 70 | ) 71 | 72 | [resource] => Array 73 | ( 74 | [0] => Array 75 | ( 76 | [uri] => 77 | [signature_method] => Array 78 | ( 79 | [0] => HMAC-SHA1 80 | [1] => RSA-SHA1 81 | ) 82 | 83 | [parameters] => Array 84 | ( 85 | [0] => auth-header 86 | [1] => post-body 87 | [2] => uri-query 88 | ) 89 | ) 90 | ) 91 | 92 | [consumer_identity] => Array 93 | ( 94 | [0] => Array 95 | ( 96 | [uri] => http://ma.gnolia.com/applications/new 97 | [method] => oob 98 | ) 99 | ) 100 | ) 101 | 102 | -------------------------------------------------------------------------------- /lib/oauth-php/library/session/OAuthSessionAbstract.class.php: -------------------------------------------------------------------------------- 1 | 8 | * 9 | * The MIT License 10 | * 11 | * Copyright (c) 2010 Corollarium Technologies 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | /** 33 | * This class is used to store Session information on the server. Most 34 | * people will use the $_SESSION based implementation, but you may prefer 35 | * a SQL, Memcache or other implementation. 36 | * 37 | */ 38 | abstract class OAuthSessionAbstract 39 | { 40 | abstract public function get ( $key ); 41 | abstract public function set ( $key, $data ); 42 | } 43 | 44 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/session/OAuthSessionSESSION.php: -------------------------------------------------------------------------------- 1 | 8 | * 9 | * The MIT License 10 | * 11 | * Copyright (c) 2010 Corollarium Technologies 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | require_once dirname(__FILE__) . '/OAuthSessionAbstract.class.php'; 33 | 34 | class OAuthSessionSESSION extends OAuthSessionAbstract 35 | { 36 | public function __construct( $options = array() ) 37 | { 38 | } 39 | 40 | /** 41 | * Gets a variable value 42 | * 43 | * @param string $key 44 | * @return The value or null if not set. 45 | */ 46 | public function get ( $key ) 47 | { 48 | return @$_SESSION[$key]; 49 | } 50 | 51 | /** 52 | * Sets a variable value 53 | * 54 | * @param string $key The key 55 | * @param any $data The data 56 | */ 57 | public function set ( $key, $data ) 58 | { 59 | $_SESSION[$key] = $data; 60 | } 61 | } 62 | 63 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/signature_method/OAuthSignatureMethod.class.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Sep 8, 2008 12:04:35 PM 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | abstract class OAuthSignatureMethod 34 | { 35 | /** 36 | * Return the name of this signature 37 | * 38 | * @return string 39 | */ 40 | abstract public function name(); 41 | 42 | /** 43 | * Return the signature for the given request 44 | * 45 | * @param OAuthRequest request 46 | * @param string base_string 47 | * @param string consumer_secret 48 | * @param string token_secret 49 | * @return string 50 | */ 51 | abstract public function signature ( $request, $base_string, $consumer_secret, $token_secret ); 52 | 53 | /** 54 | * Check if the request signature corresponds to the one calculated for the request. 55 | * 56 | * @param OAuthRequest request 57 | * @param string base_string data to be signed, usually the base string, can be a request body 58 | * @param string consumer_secret 59 | * @param string token_secret 60 | * @param string signature from the request, still urlencoded 61 | * @return string 62 | */ 63 | abstract public function verify ( $request, $base_string, $consumer_secret, $token_secret, $signature ); 64 | } 65 | 66 | 67 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 68 | 69 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/signature_method/OAuthSignatureMethod_HMAC_SHA1.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Sep 8, 2008 12:21:19 PM 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | 34 | require_once dirname(__FILE__).'/OAuthSignatureMethod.class.php'; 35 | 36 | 37 | class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod 38 | { 39 | public function name () 40 | { 41 | return 'HMAC-SHA1'; 42 | } 43 | 44 | 45 | /** 46 | * Calculate the signature using HMAC-SHA1 47 | * This function is copyright Andy Smith, 2007. 48 | * 49 | * @param OAuthRequest request 50 | * @param string base_string 51 | * @param string consumer_secret 52 | * @param string token_secret 53 | * @return string 54 | */ 55 | function signature ( $request, $base_string, $consumer_secret, $token_secret ) 56 | { 57 | $key = $request->urlencode($consumer_secret).'&'.$request->urlencode($token_secret); 58 | if (function_exists('hash_hmac')) 59 | { 60 | $signature = base64_encode(hash_hmac("sha1", $base_string, $key, true)); 61 | } 62 | else 63 | { 64 | $blocksize = 64; 65 | $hashfunc = 'sha1'; 66 | if (strlen($key) > $blocksize) 67 | { 68 | $key = pack('H*', $hashfunc($key)); 69 | } 70 | $key = str_pad($key,$blocksize,chr(0x00)); 71 | $ipad = str_repeat(chr(0x36),$blocksize); 72 | $opad = str_repeat(chr(0x5c),$blocksize); 73 | $hmac = pack( 74 | 'H*',$hashfunc( 75 | ($key^$opad).pack( 76 | 'H*',$hashfunc( 77 | ($key^$ipad).$base_string 78 | ) 79 | ) 80 | ) 81 | ); 82 | $signature = base64_encode($hmac); 83 | } 84 | return $request->urlencode($signature); 85 | } 86 | 87 | 88 | /** 89 | * Check if the request signature corresponds to the one calculated for the request. 90 | * 91 | * @param OAuthRequest request 92 | * @param string base_string data to be signed, usually the base string, can be a request body 93 | * @param string consumer_secret 94 | * @param string token_secret 95 | * @param string signature from the request, still urlencoded 96 | * @return string 97 | */ 98 | public function verify ( $request, $base_string, $consumer_secret, $token_secret, $signature ) 99 | { 100 | $a = $request->urldecode($signature); 101 | $b = $request->urldecode($this->signature($request, $base_string, $consumer_secret, $token_secret)); 102 | 103 | // We have to compare the decoded values 104 | $valA = base64_decode($a); 105 | $valB = base64_decode($b); 106 | 107 | // Crude binary comparison 108 | return rawurlencode($valA) == rawurlencode($valB); 109 | } 110 | } 111 | 112 | 113 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 114 | 115 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/signature_method/OAuthSignatureMethod_MD5.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Sep 8, 2008 12:09:43 PM 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | require_once dirname(__FILE__).'/OAuthSignatureMethod.class.php'; 34 | 35 | 36 | class OAuthSignatureMethod_MD5 extends OAuthSignatureMethod 37 | { 38 | public function name () 39 | { 40 | return 'MD5'; 41 | } 42 | 43 | 44 | /** 45 | * Calculate the signature using MD5 46 | * Binary md5 digest, as distinct from PHP's built-in hexdigest. 47 | * This function is copyright Andy Smith, 2007. 48 | * 49 | * @param OAuthRequest request 50 | * @param string base_string 51 | * @param string consumer_secret 52 | * @param string token_secret 53 | * @return string 54 | */ 55 | function signature ( $request, $base_string, $consumer_secret, $token_secret ) 56 | { 57 | $s .= '&'.$request->urlencode($consumer_secret).'&'.$request->urlencode($token_secret); 58 | $md5 = md5($base_string); 59 | $bin = ''; 60 | 61 | for ($i = 0; $i < strlen($md5); $i += 2) 62 | { 63 | $bin .= chr(hexdec($md5{$i+1}) + hexdec($md5{$i}) * 16); 64 | } 65 | return $request->urlencode(base64_encode($bin)); 66 | } 67 | 68 | 69 | /** 70 | * Check if the request signature corresponds to the one calculated for the request. 71 | * 72 | * @param OAuthRequest request 73 | * @param string base_string data to be signed, usually the base string, can be a request body 74 | * @param string consumer_secret 75 | * @param string token_secret 76 | * @param string signature from the request, still urlencoded 77 | * @return string 78 | */ 79 | public function verify ( $request, $base_string, $consumer_secret, $token_secret, $signature ) 80 | { 81 | $a = $request->urldecode($signature); 82 | $b = $request->urldecode($this->signature($request, $base_string, $consumer_secret, $token_secret)); 83 | 84 | // We have to compare the decoded values 85 | $valA = base64_decode($a); 86 | $valB = base64_decode($b); 87 | 88 | // Crude binary comparison 89 | return rawurlencode($valA) == rawurlencode($valB); 90 | } 91 | } 92 | 93 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 94 | 95 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/signature_method/OAuthSignatureMethod_PLAINTEXT.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Sep 8, 2008 12:09:43 PM 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | require_once dirname(__FILE__).'/OAuthSignatureMethod.class.php'; 34 | 35 | 36 | class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod 37 | { 38 | public function name () 39 | { 40 | return 'PLAINTEXT'; 41 | } 42 | 43 | 44 | /** 45 | * Calculate the signature using PLAINTEXT 46 | * 47 | * @param OAuthRequest request 48 | * @param string base_string 49 | * @param string consumer_secret 50 | * @param string token_secret 51 | * @return string 52 | */ 53 | function signature ( $request, $base_string, $consumer_secret, $token_secret ) 54 | { 55 | return $request->urlencode($request->urlencode($consumer_secret).'&'.$request->urlencode($token_secret)); 56 | } 57 | 58 | 59 | /** 60 | * Check if the request signature corresponds to the one calculated for the request. 61 | * 62 | * @param OAuthRequest request 63 | * @param string base_string data to be signed, usually the base string, can be a request body 64 | * @param string consumer_secret 65 | * @param string token_secret 66 | * @param string signature from the request, still urlencoded 67 | * @return string 68 | */ 69 | public function verify ( $request, $base_string, $consumer_secret, $token_secret, $signature ) 70 | { 71 | $a = $request->urldecode($signature); 72 | $b = $request->urldecode($this->signature($request, $base_string, $consumer_secret, $token_secret)); 73 | 74 | return $request->urldecode($a) == $request->urldecode($b); 75 | } 76 | } 77 | 78 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 79 | 80 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/signature_method/OAuthSignatureMethod_RSA_SHA1.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Sep 8, 2008 12:00:14 PM 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | 34 | require_once dirname(__FILE__).'/OAuthSignatureMethod.class.php'; 35 | 36 | class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod 37 | { 38 | public function name() 39 | { 40 | return 'RSA-SHA1'; 41 | } 42 | 43 | 44 | /** 45 | * Fetch the public CERT key for the signature 46 | * 47 | * @param OAuthRequest request 48 | * @return string public key 49 | */ 50 | protected function fetch_public_cert ( $request ) 51 | { 52 | // not implemented yet, ideas are: 53 | // (1) do a lookup in a table of trusted certs keyed off of consumer 54 | // (2) fetch via http using a url provided by the requester 55 | // (3) some sort of specific discovery code based on request 56 | // 57 | // either way should return a string representation of the certificate 58 | throw OAuthException2("OAuthSignatureMethod_RSA_SHA1::fetch_public_cert not implemented"); 59 | } 60 | 61 | 62 | /** 63 | * Fetch the private CERT key for the signature 64 | * 65 | * @param OAuthRequest request 66 | * @return string private key 67 | */ 68 | protected function fetch_private_cert ( $request ) 69 | { 70 | // not implemented yet, ideas are: 71 | // (1) do a lookup in a table of trusted certs keyed off of consumer 72 | // 73 | // either way should return a string representation of the certificate 74 | throw OAuthException2("OAuthSignatureMethod_RSA_SHA1::fetch_private_cert not implemented"); 75 | } 76 | 77 | 78 | /** 79 | * Calculate the signature using RSA-SHA1 80 | * This function is copyright Andy Smith, 2008. 81 | * 82 | * @param OAuthRequest request 83 | * @param string base_string 84 | * @param string consumer_secret 85 | * @param string token_secret 86 | * @return string 87 | */ 88 | public function signature ( $request, $base_string, $consumer_secret, $token_secret ) 89 | { 90 | // Fetch the private key cert based on the request 91 | $cert = $this->fetch_private_cert($request); 92 | 93 | // Pull the private key ID from the certificate 94 | $privatekeyid = openssl_get_privatekey($cert); 95 | 96 | // Sign using the key 97 | $sig = false; 98 | $ok = openssl_sign($base_string, $sig, $privatekeyid); 99 | 100 | // Release the key resource 101 | openssl_free_key($privatekeyid); 102 | 103 | return $request->urlencode(base64_encode($sig)); 104 | } 105 | 106 | 107 | /** 108 | * Check if the request signature is the same as the one calculated for the request. 109 | * 110 | * @param OAuthRequest request 111 | * @param string base_string 112 | * @param string consumer_secret 113 | * @param string token_secret 114 | * @param string signature 115 | * @return string 116 | */ 117 | public function verify ( $request, $base_string, $consumer_secret, $token_secret, $signature ) 118 | { 119 | $decoded_sig = base64_decode($request->urldecode($signature)); 120 | 121 | // Fetch the public key cert based on the request 122 | $cert = $this->fetch_public_cert($request); 123 | 124 | // Pull the public key ID from the certificate 125 | $publickeyid = openssl_get_publickey($cert); 126 | 127 | // Check the computed signature against the one passed in the query 128 | $ok = openssl_verify($base_string, $decoded_sig, $publickeyid); 129 | 130 | // Release the key resource 131 | openssl_free_key($publickeyid); 132 | return $ok == 1; 133 | } 134 | 135 | } 136 | 137 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 138 | 139 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/store/OAuthStore2Leg.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * The MIT License 11 | * 12 | * Copyright (c) 2007-2008 Mediamatic Lab 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | require_once dirname(__FILE__) . '/OAuthStoreAbstract.class.php'; 34 | 35 | class OAuthStore2Leg extends OAuthStoreAbstract 36 | { 37 | protected $consumer_key; 38 | protected $consumer_secret; 39 | protected $signature_method = array('HMAC-SHA1'); 40 | protected $token_type = false; 41 | 42 | /* 43 | * Takes two options: consumer_key and consumer_secret 44 | */ 45 | public function __construct( $options = array() ) 46 | { 47 | if(isset($options['consumer_key']) && isset($options['consumer_secret'])) 48 | { 49 | $this->consumer_key = $options['consumer_key']; 50 | $this->consumer_secret = $options['consumer_secret']; 51 | } 52 | else 53 | { 54 | throw new OAuthException2("OAuthStore2Leg needs consumer_token and consumer_secret"); 55 | } 56 | } 57 | 58 | public function getSecretsForVerify ( $consumer_key, $token, $token_type = 'access' ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 59 | public function getSecretsForSignature ( $uri, $user_id ) 60 | { 61 | return array( 62 | 'consumer_key' => $this->consumer_key, 63 | 'consumer_secret' => $this->consumer_secret, 64 | 'signature_methods' => $this->signature_method, 65 | 'token' => $this->token_type 66 | ); 67 | } 68 | public function getServerTokenSecrets ( $consumer_key, $token, $token_type, $user_id, $name = '' ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 69 | public function addServerToken ( $consumer_key, $token_type, $token, $token_secret, $user_id, $options = array() ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 70 | 71 | public function deleteServer ( $consumer_key, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 72 | public function getServer( $consumer_key, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 73 | public function getServerForUri ( $uri, $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 74 | public function listServerTokens ( $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 75 | public function countServerTokens ( $consumer_key ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 76 | public function getServerToken ( $consumer_key, $token, $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 77 | public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 78 | public function setServerTokenTtl ( $consumer_key, $token, $token_ttl ) 79 | { 80 | //This method just needs to exist. It doesn't have to do anything! 81 | } 82 | 83 | public function listServers ( $q = '', $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 84 | public function updateServer ( $server, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 85 | 86 | public function updateConsumer ( $consumer, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 87 | public function deleteConsumer ( $consumer_key, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 88 | public function getConsumer ( $consumer_key, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 89 | public function getConsumerStatic () { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 90 | 91 | public function addConsumerRequestToken ( $consumer_key, $options = array() ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 92 | public function getConsumerRequestToken ( $token ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 93 | public function deleteConsumerRequestToken ( $token ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 94 | public function authorizeConsumerRequestToken ( $token, $user_id, $referrer_host = '' ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 95 | public function countConsumerAccessTokens ( $consumer_key ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 96 | public function exchangeConsumerRequestForAccessToken ( $token, $options = array() ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 97 | public function getConsumerAccessToken ( $token, $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 98 | public function deleteConsumerAccessToken ( $token, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 99 | public function setConsumerAccessTokenTtl ( $token, $ttl ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 100 | 101 | public function listConsumers ( $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 102 | public function listConsumerApplications( $begin = 0, $total = 25 ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 103 | public function listConsumerTokens ( $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 104 | 105 | public function checkServerNonce ( $consumer_key, $token, $timestamp, $nonce ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 106 | 107 | public function addLog ( $keys, $received, $sent, $base_string, $notes, $user_id = null ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 108 | public function listLog ( $options, $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 109 | 110 | public function install () { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); } 111 | } 112 | 113 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/store/OAuthStoreAbstract.class.php: -------------------------------------------------------------------------------- 1 | 8 | * 9 | * The MIT License 10 | * 11 | * Copyright (c) 2007-2008 Mediamatic Lab 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | abstract class OAuthStoreAbstract 33 | { 34 | abstract public function getSecretsForVerify ( $consumer_key, $token, $token_type = 'access' ); 35 | abstract public function getSecretsForSignature ( $uri, $user_id ); 36 | abstract public function getServerTokenSecrets ( $consumer_key, $token, $token_type, $user_id, $name = '' ); 37 | abstract public function addServerToken ( $consumer_key, $token_type, $token, $token_secret, $user_id, $options = array() ); 38 | 39 | abstract public function deleteServer ( $consumer_key, $user_id, $user_is_admin = false ); 40 | abstract public function getServer( $consumer_key, $user_id, $user_is_admin = false ); 41 | abstract public function getServerForUri ( $uri, $user_id ); 42 | abstract public function listServerTokens ( $user_id ); 43 | abstract public function countServerTokens ( $consumer_key ); 44 | abstract public function getServerToken ( $consumer_key, $token, $user_id ); 45 | abstract public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_admin = false ); 46 | abstract public function listServers ( $q = '', $user_id ); 47 | abstract public function updateServer ( $server, $user_id, $user_is_admin = false ); 48 | 49 | abstract public function updateConsumer ( $consumer, $user_id, $user_is_admin = false ); 50 | abstract public function deleteConsumer ( $consumer_key, $user_id, $user_is_admin = false ); 51 | abstract public function getConsumer ( $consumer_key, $user_id, $user_is_admin = false ); 52 | abstract public function getConsumerStatic (); 53 | 54 | abstract public function addConsumerRequestToken ( $consumer_key, $options = array() ); 55 | abstract public function getConsumerRequestToken ( $token ); 56 | abstract public function deleteConsumerRequestToken ( $token ); 57 | abstract public function authorizeConsumerRequestToken ( $token, $user_id, $referrer_host = '' ); 58 | abstract public function countConsumerAccessTokens ( $consumer_key ); 59 | abstract public function exchangeConsumerRequestForAccessToken ( $token, $options = array() ); 60 | abstract public function getConsumerAccessToken ( $token, $user_id ); 61 | abstract public function deleteConsumerAccessToken ( $token, $user_id, $user_is_admin = false ); 62 | abstract public function setConsumerAccessTokenTtl ( $token, $ttl ); 63 | 64 | abstract public function listConsumers ( $user_id ); 65 | abstract public function listConsumerApplications( $begin = 0, $total = 25 ); 66 | abstract public function listConsumerTokens ( $user_id ); 67 | 68 | abstract public function checkServerNonce ( $consumer_key, $token, $timestamp, $nonce ); 69 | 70 | abstract public function addLog ( $keys, $received, $sent, $base_string, $notes, $user_id = null ); 71 | abstract public function listLog ( $options, $user_id ); 72 | 73 | abstract public function install (); 74 | 75 | /** 76 | * Fetch the current static consumer key for this site, create it when it was not found. 77 | * The consumer secret for the consumer key is always empty. 78 | * 79 | * @return string consumer key 80 | */ 81 | 82 | 83 | /* ** Some handy utility functions ** */ 84 | 85 | /** 86 | * Generate a unique key 87 | * 88 | * @param boolean unique force the key to be unique 89 | * @return string 90 | */ 91 | public function generateKey ( $unique = false ) 92 | { 93 | $key = md5(uniqid(rand(), true)); 94 | if ($unique) 95 | { 96 | list($usec,$sec) = explode(' ',microtime()); 97 | $key .= dechex($usec).dechex($sec); 98 | } 99 | return $key; 100 | } 101 | 102 | /** 103 | * Check to see if a string is valid utf8 104 | * 105 | * @param string $s 106 | * @return boolean 107 | */ 108 | protected function isUTF8 ( $s ) 109 | { 110 | return preg_match('%(?: 111 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte 112 | |\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs 113 | |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte 114 | |\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates 115 | |\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 116 | |[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 117 | |\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 118 | )+%xs', $s); 119 | } 120 | 121 | 122 | /** 123 | * Make a string utf8, replacing all non-utf8 chars with a '.' 124 | * 125 | * @param string 126 | * @return string 127 | */ 128 | protected function makeUTF8 ( $s ) 129 | { 130 | if (function_exists('iconv')) 131 | { 132 | do 133 | { 134 | $ok = true; 135 | $text = @iconv('UTF-8', 'UTF-8//TRANSLIT', $s); 136 | if (strlen($text) != strlen($s)) 137 | { 138 | // Remove the offending character... 139 | $s = $text . '.' . substr($s, strlen($text) + 1); 140 | $ok = false; 141 | } 142 | } 143 | while (!$ok); 144 | } 145 | return $s; 146 | } 147 | 148 | } 149 | 150 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/store/OAuthStoreMySQL.php: -------------------------------------------------------------------------------- 1 | 9 | * @date Nov 16, 2007 4:03:30 PM 10 | * 11 | * 12 | * The MIT License 13 | * 14 | * Copyright (c) 2007-2008 Mediamatic Lab 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy 17 | * of this software and associated documentation files (the "Software"), to deal 18 | * in the Software without restriction, including without limitation the rights 19 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | * copies of the Software, and to permit persons to whom the Software is 21 | * furnished to do so, subject to the following conditions: 22 | * 23 | * The above copyright notice and this permission notice shall be included in 24 | * all copies or substantial portions of the Software. 25 | * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | * THE SOFTWARE. 33 | */ 34 | 35 | 36 | require_once dirname(__FILE__) . '/OAuthStoreSQL.php'; 37 | 38 | 39 | class OAuthStoreMySQL extends OAuthStoreSQL 40 | { 41 | /** 42 | * The MySQL connection 43 | */ 44 | protected $conn; 45 | 46 | /** 47 | * Initialise the database 48 | */ 49 | public function install () 50 | { 51 | require_once dirname(__FILE__) . '/mysql/install.php'; 52 | } 53 | 54 | 55 | /* ** Some simple helper functions for querying the mysql db ** */ 56 | 57 | /** 58 | * Perform a query, ignore the results 59 | * 60 | * @param string sql 61 | * @param vararg arguments (for sprintf) 62 | */ 63 | protected function query ( $sql ) 64 | { 65 | $sql = $this->sql_printf(func_get_args()); 66 | if (!($res = mysql_query($sql, $this->conn))) 67 | { 68 | $this->sql_errcheck($sql); 69 | } 70 | if (is_resource($res)) 71 | { 72 | mysql_free_result($res); 73 | } 74 | } 75 | 76 | 77 | /** 78 | * Perform a query, ignore the results 79 | * 80 | * @param string sql 81 | * @param vararg arguments (for sprintf) 82 | * @return array 83 | */ 84 | protected function query_all_assoc ( $sql ) 85 | { 86 | $sql = $this->sql_printf(func_get_args()); 87 | if (!($res = mysql_query($sql, $this->conn))) 88 | { 89 | $this->sql_errcheck($sql); 90 | } 91 | $rs = array(); 92 | while ($row = mysql_fetch_assoc($res)) 93 | { 94 | $rs[] = $row; 95 | } 96 | mysql_free_result($res); 97 | return $rs; 98 | } 99 | 100 | 101 | /** 102 | * Perform a query, return the first row 103 | * 104 | * @param string sql 105 | * @param vararg arguments (for sprintf) 106 | * @return array 107 | */ 108 | protected function query_row_assoc ( $sql ) 109 | { 110 | $sql = $this->sql_printf(func_get_args()); 111 | if (!($res = mysql_query($sql, $this->conn))) 112 | { 113 | $this->sql_errcheck($sql); 114 | } 115 | if ($row = mysql_fetch_assoc($res)) 116 | { 117 | $rs = $row; 118 | } 119 | else 120 | { 121 | $rs = false; 122 | } 123 | mysql_free_result($res); 124 | return $rs; 125 | } 126 | 127 | 128 | /** 129 | * Perform a query, return the first row 130 | * 131 | * @param string sql 132 | * @param vararg arguments (for sprintf) 133 | * @return array 134 | */ 135 | protected function query_row ( $sql ) 136 | { 137 | $sql = $this->sql_printf(func_get_args()); 138 | if (!($res = mysql_query($sql, $this->conn))) 139 | { 140 | $this->sql_errcheck($sql); 141 | } 142 | if ($row = mysql_fetch_array($res)) 143 | { 144 | $rs = $row; 145 | } 146 | else 147 | { 148 | $rs = false; 149 | } 150 | mysql_free_result($res); 151 | return $rs; 152 | } 153 | 154 | 155 | /** 156 | * Perform a query, return the first column of the first row 157 | * 158 | * @param string sql 159 | * @param vararg arguments (for sprintf) 160 | * @return mixed 161 | */ 162 | protected function query_one ( $sql ) 163 | { 164 | $sql = $this->sql_printf(func_get_args()); 165 | if (!($res = mysql_query($sql, $this->conn))) 166 | { 167 | $this->sql_errcheck($sql); 168 | } 169 | $val = @mysql_result($res, 0, 0); 170 | mysql_free_result($res); 171 | return $val; 172 | } 173 | 174 | 175 | /** 176 | * Return the number of rows affected in the last query 177 | */ 178 | protected function query_affected_rows () 179 | { 180 | return mysql_affected_rows($this->conn); 181 | } 182 | 183 | 184 | /** 185 | * Return the id of the last inserted row 186 | * 187 | * @return int 188 | */ 189 | protected function query_insert_id () 190 | { 191 | return mysql_insert_id($this->conn); 192 | } 193 | 194 | 195 | protected function sql_printf ( $args ) 196 | { 197 | $sql = array_shift($args); 198 | if (count($args) == 1 && is_array($args[0])) 199 | { 200 | $args = $args[0]; 201 | } 202 | $args = array_map(array($this, 'sql_escape_string'), $args); 203 | return vsprintf($sql, $args); 204 | } 205 | 206 | 207 | protected function sql_escape_string ( $s ) 208 | { 209 | if (is_string($s)) 210 | { 211 | return mysql_real_escape_string($s, $this->conn); 212 | } 213 | else if (is_null($s)) 214 | { 215 | return NULL; 216 | } 217 | else if (is_bool($s)) 218 | { 219 | return intval($s); 220 | } 221 | else if (is_int($s) || is_float($s)) 222 | { 223 | return $s; 224 | } 225 | else 226 | { 227 | return mysql_real_escape_string(strval($s), $this->conn); 228 | } 229 | } 230 | 231 | 232 | protected function sql_errcheck ( $sql ) 233 | { 234 | if (mysql_errno($this->conn)) 235 | { 236 | $msg = "SQL Error in OAuthStoreMySQL: ".mysql_error($this->conn)."\n\n" . $sql; 237 | throw new OAuthException2($msg); 238 | } 239 | } 240 | } 241 | 242 | 243 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 244 | 245 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/store/OAuthStorePDO.php: -------------------------------------------------------------------------------- 1 | Based on code by Marc Worrell 9 | * 10 | * 11 | * The MIT License 12 | * 13 | * Copyright (c) 2007-2008 Mediamatic Lab 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | */ 33 | 34 | require_once dirname(__FILE__) . '/OAuthStoreSQL.php'; 35 | 36 | 37 | class OAuthStorePDO extends OAuthStoreSQL 38 | { 39 | private $conn; // PDO connection 40 | private $lastaffectedrows; 41 | 42 | /** 43 | * Construct the OAuthStorePDO. 44 | * In the options you have to supply either: 45 | * - dsn, username, password and database (for a new PDO connection) 46 | * - conn (for the connection to be used) 47 | * 48 | * @param array options 49 | */ 50 | function __construct ( $options = array() ) 51 | { 52 | if (isset($options['conn'])) 53 | { 54 | $this->conn = $options['conn']; 55 | } 56 | else if (isset($options['dsn'])) 57 | { 58 | try 59 | { 60 | $this->conn = new PDO($options['dsn'], $options['username'], @$options['password']); 61 | } 62 | catch (PDOException $e) 63 | { 64 | throw new OAuthException2('Could not connect to PDO database: ' . $e->getMessage()); 65 | } 66 | 67 | $this->query('set character set utf8'); 68 | } 69 | } 70 | 71 | /** 72 | * Perform a query, ignore the results 73 | * 74 | * @param string sql 75 | * @param vararg arguments (for sprintf) 76 | */ 77 | protected function query ( $sql ) 78 | { 79 | $sql = $this->sql_printf(func_get_args()); 80 | try 81 | { 82 | $this->lastaffectedrows = $this->conn->exec($sql); 83 | if ($this->lastaffectedrows === FALSE) { 84 | $this->sql_errcheck($sql); 85 | } 86 | } 87 | catch (PDOException $e) 88 | { 89 | $this->sql_errcheck($sql); 90 | } 91 | } 92 | 93 | 94 | /** 95 | * Perform a query, ignore the results 96 | * 97 | * @param string sql 98 | * @param vararg arguments (for sprintf) 99 | * @return array 100 | */ 101 | protected function query_all_assoc ( $sql ) 102 | { 103 | $sql = $this->sql_printf(func_get_args()); 104 | $result = array(); 105 | 106 | try 107 | { 108 | $stmt = $this->conn->query($sql); 109 | 110 | $result = $stmt->fetchAll(PDO::FETCH_ASSOC); 111 | } 112 | catch (PDOException $e) 113 | { 114 | $this->sql_errcheck($sql); 115 | } 116 | return $result; 117 | } 118 | 119 | 120 | /** 121 | * Perform a query, return the first row 122 | * 123 | * @param string sql 124 | * @param vararg arguments (for sprintf) 125 | * @return array 126 | */ 127 | protected function query_row_assoc ( $sql ) 128 | { 129 | $sql = $this->sql_printf(func_get_args()); 130 | $result = $this->query_all_assoc($sql); 131 | $val = array_pop($result); 132 | return $val; 133 | } 134 | 135 | 136 | /** 137 | * Perform a query, return the first row 138 | * 139 | * @param string sql 140 | * @param vararg arguments (for sprintf) 141 | * @return array 142 | */ 143 | protected function query_row ( $sql ) 144 | { 145 | $sql = $this->sql_printf(func_get_args()); 146 | try 147 | { 148 | $all = $this->conn->query($sql, PDO::FETCH_NUM); 149 | $row = array(); 150 | foreach ($all as $r) { 151 | $row = $r; 152 | break; 153 | } 154 | } 155 | catch (PDOException $e) 156 | { 157 | $this->sql_errcheck($sql); 158 | } 159 | return $row; 160 | } 161 | 162 | 163 | /** 164 | * Perform a query, return the first column of the first row 165 | * 166 | * @param string sql 167 | * @param vararg arguments (for sprintf) 168 | * @return mixed 169 | */ 170 | protected function query_one ( $sql ) 171 | { 172 | $sql = $this->sql_printf(func_get_args()); 173 | $row = $this->query_row($sql); 174 | $val = array_pop($row); 175 | return $val; 176 | } 177 | 178 | 179 | /** 180 | * Return the number of rows affected in the last query 181 | */ 182 | protected function query_affected_rows () 183 | { 184 | return $this->lastaffectedrows; 185 | } 186 | 187 | 188 | /** 189 | * Return the id of the last inserted row 190 | * 191 | * @return int 192 | */ 193 | protected function query_insert_id () 194 | { 195 | return $this->conn->lastInsertId(); 196 | } 197 | 198 | 199 | protected function sql_printf ( $args ) 200 | { 201 | $sql = array_shift($args); 202 | if (count($args) == 1 && is_array($args[0])) 203 | { 204 | $args = $args[0]; 205 | } 206 | $args = array_map(array($this, 'sql_escape_string'), $args); 207 | return vsprintf($sql, $args); 208 | } 209 | 210 | 211 | protected function sql_escape_string ( $s ) 212 | { 213 | if (is_string($s)) 214 | { 215 | $s = $this->conn->quote($s); 216 | // kludge. Quote already adds quotes, and this conflicts with OAuthStoreSQL. 217 | // so remove the quotes 218 | $len = mb_strlen($s); 219 | if ($len == 0) 220 | return $s; 221 | 222 | $startcut = 0; 223 | while (isset($s[$startcut]) && $s[$startcut] == '\'') 224 | $startcut++; 225 | 226 | $endcut = $len-1; 227 | while (isset($s[$endcut]) && $s[$endcut] == '\'') 228 | $endcut--; 229 | 230 | $s = mb_substr($s, $startcut, $endcut-$startcut+1); 231 | return $s; 232 | } 233 | else if (is_null($s)) 234 | { 235 | return NULL; 236 | } 237 | else if (is_bool($s)) 238 | { 239 | return intval($s); 240 | } 241 | else if (is_int($s) || is_float($s)) 242 | { 243 | return $s; 244 | } 245 | else 246 | { 247 | return $this->conn->quote(strval($s)); 248 | } 249 | } 250 | 251 | 252 | protected function sql_errcheck ( $sql ) 253 | { 254 | $msg = "SQL Error in OAuthStoreMySQL: ". print_r($this->conn->errorInfo(), true) ."\n\n" . $sql; 255 | $backtrace = debug_backtrace(); 256 | $msg .= "\n\nAt file " . $backtrace[1]['file'] . ", line " . $backtrace[1]['line']; 257 | throw new OAuthException2($msg); 258 | } 259 | 260 | /** 261 | * Initialise the database 262 | */ 263 | public function install () 264 | { 265 | // TODO: this depends on mysql extension 266 | require_once dirname(__FILE__) . '/mysql/install.php'; 267 | } 268 | 269 | } 270 | 271 | 272 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 273 | 274 | ?> -------------------------------------------------------------------------------- /lib/oauth-php/library/store/mysql/install.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/1_Tables/TABLES.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE oauth_log 2 | ( 3 | olg_id number, 4 | olg_osr_consumer_key varchar2(64), 5 | olg_ost_token varchar2(64), 6 | olg_ocr_consumer_key varchar2(64), 7 | olg_oct_token varchar2(64), 8 | olg_usa_id_ref number, 9 | olg_received varchar2(500), 10 | olg_sent varchar2(500), 11 | olg_base_string varchar2(500), 12 | olg_notes varchar2(500), 13 | olg_timestamp date default sysdate, 14 | olg_remote_ip varchar2(50) 15 | ); 16 | 17 | alter table oauth_log 18 | add constraint oauth_log_pk primary key (olg_id); 19 | 20 | 21 | CREATE TABLE oauth_consumer_registry 22 | ( 23 | ocr_id number, 24 | ocr_usa_id_ref number, 25 | ocr_consumer_key varchar2(64), 26 | ocr_consumer_secret varchar2(64), 27 | ocr_signature_methods varchar2(255)default 'HMAC-SHA1,PLAINTEXT', 28 | ocr_server_uri varchar2(255), 29 | ocr_server_uri_host varchar2(128), 30 | ocr_server_uri_path varchar2(128), 31 | ocr_request_token_uri varchar2(255), 32 | ocr_authorize_uri varchar2(255), 33 | ocr_access_token_uri varchar2(255), 34 | ocr_timestamp date default sysdate 35 | ) 36 | 37 | alter table oauth_consumer_registry 38 | add constraint oauth_consumer_registry_pk primary key (ocr_id); 39 | 40 | 41 | CREATE TABLE oauth_consumer_token 42 | ( 43 | oct_id number, 44 | oct_ocr_id_ref number, 45 | oct_usa_id_ref number, 46 | oct_name varchar2(64) default '', 47 | oct_token varchar2(64), 48 | oct_token_secret varchar2(64), 49 | oct_token_type varchar2(20), -- enum('request','authorized','access'), 50 | oct_token_ttl date default TO_DATE('9999.12.31', 'yyyy.mm.dd'), 51 | oct_timestamp date default sysdate 52 | ); 53 | 54 | alter table oauth_consumer_token 55 | add constraint oauth_consumer_token_pk primary key (oct_id); 56 | 57 | 58 | CREATE TABLE oauth_server_registry 59 | ( 60 | osr_id number, 61 | osr_usa_id_ref number, 62 | osr_consumer_key varchar2(64), 63 | osr_consumer_secret varchar2(64), 64 | osr_enabled integer default '1', 65 | osr_status varchar2(16), 66 | osr_requester_name varchar2(64), 67 | osr_requester_email varchar2(64), 68 | osr_callback_uri varchar2(255), 69 | osr_application_uri varchar2(255), 70 | osr_application_title varchar2(80), 71 | osr_application_descr varchar2(500), 72 | osr_application_notes varchar2(500), 73 | osr_application_type varchar2(20), 74 | osr_application_commercial integer default '0', 75 | osr_issue_date date, 76 | osr_timestamp date default sysdate 77 | ); 78 | 79 | 80 | alter table oauth_server_registry 81 | add constraint oauth_server_registry_pk primary key (osr_id); 82 | 83 | 84 | CREATE TABLE oauth_server_nonce 85 | ( 86 | osn_id number, 87 | osn_consumer_key varchar2(64), 88 | osn_token varchar2(64), 89 | osn_timestamp number, 90 | osn_nonce varchar2(80) 91 | ); 92 | 93 | alter table oauth_server_nonce 94 | add constraint oauth_server_nonce_pk primary key (osn_id); 95 | 96 | 97 | CREATE TABLE oauth_server_token 98 | ( 99 | ost_id number, 100 | ost_osr_id_ref number, 101 | ost_usa_id_ref number, 102 | ost_token varchar2(64), 103 | ost_token_secret varchar2(64), 104 | ost_token_type varchar2(20), -- enum('request','access'), 105 | ost_authorized integer default '0', 106 | ost_referrer_host varchar2(128), 107 | ost_token_ttl date default TO_DATE('9999.12.31', 'yyyy.mm.dd'), 108 | ost_timestamp date default sysdate, 109 | ost_verifier varchar2(10), 110 | ost_callback_url varchar2(512) 111 | ); 112 | 113 | alter table oauth_server_token 114 | add constraint oauth_server_token_pk primary key (ost_id); -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/2_Sequences/SEQUENCES.sql: -------------------------------------------------------------------------------- 1 | CREATE SEQUENCE SEQ_OCT_ID NOCACHE; 2 | 3 | CREATE SEQUENCE SEQ_OCR_ID NOCACHE; 4 | 5 | CREATE SEQUENCE SEQ_OSR_ID NOCACHE; 6 | 7 | CREATE SEQUENCE SEQ_OSN_ID NOCACHE; 8 | 9 | CREATE SEQUENCE SEQ_OLG_ID NOCACHE; 10 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_ADD_CONSUMER_REQUEST_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_ADD_CONSUMER_REQUEST_TOKEN 2 | ( 3 | P_TOKEN_TTL IN NUMBER, -- IN SECOND 4 | P_CONSUMER_KEY IN VARCHAR2, 5 | P_TOKEN IN VARCHAR2, 6 | P_TOKEN_SECRET IN VARCHAR2, 7 | P_CALLBACK_URL IN VARCHAR2, 8 | P_RESULT OUT NUMBER 9 | ) 10 | AS 11 | 12 | -- PROCEDURE TO Add an unautorized request token to our server. 13 | 14 | V_OSR_ID NUMBER; 15 | V_OSR_ID_REF NUMBER; 16 | 17 | V_EXC_NO_SERVER_EXIST EXCEPTION; 18 | BEGIN 19 | 20 | P_RESULT := 0; 21 | 22 | BEGIN 23 | SELECT OSR_ID INTO V_OSR_ID 24 | FROM OAUTH_SERVER_REGISTRY 25 | WHERE OSR_CONSUMER_KEY = P_CONSUMER_KEY 26 | AND OSR_ENABLED = 1; 27 | EXCEPTION 28 | WHEN NO_DATA_FOUND THEN 29 | RAISE V_EXC_NO_SERVER_EXIST; 30 | END; 31 | 32 | 33 | BEGIN 34 | SELECT OST_OSR_ID_REF INTO V_OSR_ID_REF 35 | FROM OAUTH_SERVER_TOKEN 36 | WHERE OST_OSR_ID_REF = V_OSR_ID; 37 | 38 | UPDATE OAUTH_SERVER_TOKEN 39 | SET OST_OSR_ID_REF = V_OSR_ID, 40 | OST_USA_ID_REF = 1, 41 | OST_TOKEN = P_TOKEN, 42 | OST_TOKEN_SECRET = P_TOKEN_SECRET, 43 | OST_TOKEN_TYPE = 'REQUEST', 44 | OST_TOKEN_TTL = SYSDATE + (P_TOKEN_TTL/(24*60*60)), 45 | OST_CALLBACK_URL = P_CALLBACK_URL, 46 | OST_TIMESTAMP = SYSDATE 47 | WHERE OST_OSR_ID_REF = V_OSR_ID_REF; 48 | 49 | 50 | EXCEPTION 51 | WHEN NO_DATA_FOUND THEN 52 | 53 | INSERT INTO OAUTH_SERVER_TOKEN 54 | (OST_ID, OST_OSR_ID_REF, OST_USA_ID_REF, OST_TOKEN, OST_TOKEN_SECRET, OST_TOKEN_TYPE, 55 | OST_TOKEN_TTL, OST_CALLBACK_URL) 56 | VALUES 57 | (SEQ_OCT_ID.NEXTVAL, V_OSR_ID, 1, P_TOKEN, P_TOKEN_SECRET, 'REQUEST', SYSDATE + (P_TOKEN_TTL/(24*60*60)), 58 | P_CALLBACK_URL); 59 | 60 | END; 61 | 62 | 63 | EXCEPTION 64 | WHEN V_EXC_NO_SERVER_EXIST THEN 65 | P_RESULT := 2; -- NO_SERVER_EXIST 66 | WHEN OTHERS THEN 67 | -- CALL THE FUNCTION TO LOG ERRORS 68 | ROLLBACK; 69 | P_RESULT := 1; -- ERROR 70 | END; 71 | / 72 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_ADD_LOG.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_ADD_LOG 2 | ( 3 | P_RECEIVED IN VARCHAR2, 4 | P_SENT IN VARCHAR2, 5 | P_BASE_STRING IN VARCHAR2, 6 | P_NOTES IN VARCHAR2, 7 | P_USA_ID_REF IN NUMBER, 8 | P_REMOTE_IP IN VARCHAR2, 9 | P_RESULT OUT NUMBER 10 | ) 11 | AS 12 | 13 | -- PROCEDURE TO Add an entry to the log table 14 | 15 | BEGIN 16 | 17 | P_RESULT := 0; 18 | 19 | INSERT INTO oauth_log 20 | (OLG_ID, olg_received, olg_sent, olg_base_string, olg_notes, olg_usa_id_ref, olg_remote_ip) 21 | VALUES 22 | (SEQ_OLG_ID.NEXTVAL, P_RECEIVED, P_SENT, P_BASE_STRING, P_NOTES, NVL(P_USA_ID_REF, 0), P_REMOTE_IP); 23 | 24 | 25 | EXCEPTION 26 | WHEN OTHERS THEN 27 | -- CALL THE FUNCTION TO LOG ERRORS 28 | ROLLBACK; 29 | P_RESULT := 1; -- ERROR 30 | END; 31 | / 32 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_ADD_SERVER_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_ADD_SERVER_TOKEN 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_USER_ID IN NUMBER, 5 | P_NAME IN VARCHAR2, 6 | P_TOKEN_TYPE IN VARCHAR2, 7 | P_TOKEN IN VARCHAR2, 8 | P_TOKEN_SECRET IN VARCHAR2, 9 | P_TOKEN_INTERVAL_IN_SEC IN NUMBER, 10 | P_RESULT OUT NUMBER 11 | ) 12 | AS 13 | 14 | -- Add a request token we obtained from a server. 15 | V_OCR_ID NUMBER; 16 | V_TOKEN_TTL DATE; 17 | 18 | V_EXC_INVALID_CONSUMER_KEY EXCEPTION; 19 | BEGIN 20 | P_RESULT := 0; 21 | 22 | BEGIN 23 | SELECT OCR_ID INTO V_OCR_ID FROM OAUTH_CONSUMER_REGISTRY 24 | WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY AND OCR_USA_ID_REF = P_USER_ID; 25 | EXCEPTION 26 | WHEN NO_DATA_FOUND THEN 27 | RAISE V_EXC_INVALID_CONSUMER_KEY; 28 | END; 29 | 30 | DELETE FROM OAUTH_CONSUMER_TOKEN 31 | WHERE OCT_OCR_ID_REF = V_OCR_ID 32 | AND OCT_USA_ID_REF = P_USER_ID 33 | AND UPPER(OCT_TOKEN_TYPE) = UPPER(P_TOKEN_TYPE) 34 | AND OCT_NAME = P_NAME; 35 | 36 | IF P_TOKEN_INTERVAL_IN_SEC IS NOT NULL THEN 37 | V_TOKEN_TTL := SYSDATE + (P_TOKEN_INTERVAL_IN_SEC/(24*60*60)); 38 | ELSE 39 | V_TOKEN_TTL := TO_DATE('9999.12.31', 'yyyy.mm.dd'); 40 | END IF; 41 | 42 | INSERT INTO OAUTH_CONSUMER_TOKEN 43 | (OCT_ID, OCT_OCR_ID_REF,OCT_USA_ID_REF, OCT_NAME, OCT_TOKEN, OCT_TOKEN_SECRET, OCT_TOKEN_TYPE, OCT_TIMESTAMP, OCT_TOKEN_TTL) 44 | VALUES 45 | (SEQ_OCT_ID.NEXTVAL, V_OCR_ID, P_USER_ID, P_NAME, P_TOKEN, P_TOKEN_SECRET, UPPER(P_TOKEN_TYPE), SYSDATE, V_TOKEN_TTL); 46 | 47 | EXCEPTION 48 | WHEN V_EXC_INVALID_CONSUMER_KEY THEN 49 | P_RESULT := 2; -- INVALID_CONSUMER_KEY 50 | WHEN OTHERS THEN 51 | -- CALL THE FUNCTION TO LOG ERRORS 52 | ROLLBACK; 53 | P_RESULT := 1; -- ERROR 54 | END; 55 | / 56 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_AUTH_CONSUMER_REQ_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_AUTH_CONSUMER_REQ_TOKEN 2 | ( 3 | P_USER_ID IN NUMBER, 4 | P_REFERRER_HOST IN VARCHAR2, 5 | P_VERIFIER IN VARCHAR2, 6 | P_TOKEN IN VARCHAR2, 7 | P_RESULT OUT NUMBER 8 | ) 9 | AS 10 | 11 | -- PROCEDURE TO Fetch the consumer request token, by request token. 12 | BEGIN 13 | P_RESULT := 0; 14 | 15 | 16 | UPDATE OAUTH_SERVER_TOKEN 17 | SET OST_AUTHORIZED = 1, 18 | OST_USA_ID_REF = P_USER_ID, 19 | OST_TIMESTAMP = SYSDATE, 20 | OST_REFERRER_HOST = P_REFERRER_HOST, 21 | OST_VERIFIER = P_VERIFIER 22 | WHERE OST_TOKEN = P_TOKEN 23 | AND OST_TOKEN_TYPE = 'REQUEST'; 24 | 25 | 26 | EXCEPTION 27 | WHEN OTHERS THEN 28 | -- CALL THE FUNCTION TO LOG ERRORS 29 | ROLLBACK; 30 | P_RESULT := 1; -- ERROR 31 | END; 32 | / 33 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_CHECK_SERVER_NONCE.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_CHECK_SERVER_NONCE 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_TOKEN IN VARCHAR2, 5 | P_TIMESTAMP IN NUMBER, 6 | P_MAX_TIMESTAMP_SKEW IN NUMBER, 7 | P_NONCE IN VARCHAR2, 8 | P_RESULT OUT NUMBER 9 | ) 10 | AS 11 | 12 | -- PROCEDURE TO Check an nonce/timestamp combination. Clears any nonce combinations 13 | -- that are older than the one received. 14 | V_IS_MAX NUMBER; 15 | V_MAX_TIMESTAMP NUMBER; 16 | V_IS_DUPLICATE_TIMESTAMP NUMBER; 17 | 18 | V_EXC_INVALID_TIMESTAMP EXCEPTION; 19 | V_EXC_DUPLICATE_TIMESTAMP EXCEPTION; 20 | BEGIN 21 | 22 | P_RESULT := 0; 23 | 24 | BEGIN 25 | SELECT MAX(OSN_TIMESTAMP), 26 | CASE 27 | WHEN MAX(OSN_TIMESTAMP) > (P_TIMESTAMP + P_MAX_TIMESTAMP_SKEW) THEN 1 ELSE 0 28 | END "IS_MAX" INTO V_MAX_TIMESTAMP, V_IS_MAX 29 | FROM OAUTH_SERVER_NONCE 30 | WHERE OSN_CONSUMER_KEY = P_CONSUMER_KEY 31 | AND OSN_TOKEN = P_TOKEN; 32 | 33 | IF V_IS_MAX = 1 THEN 34 | RAISE V_EXC_INVALID_TIMESTAMP; 35 | END IF; 36 | 37 | EXCEPTION 38 | WHEN NO_DATA_FOUND THEN 39 | NULL; 40 | END; 41 | 42 | BEGIN 43 | SELECT 1 INTO V_IS_DUPLICATE_TIMESTAMP FROM DUAL WHERE EXISTS 44 | (SELECT OSN_ID FROM OAUTH_SERVER_NONCE 45 | WHERE OSN_CONSUMER_KEY = P_CONSUMER_KEY 46 | AND OSN_TOKEN = P_TOKEN 47 | AND OSN_TIMESTAMP = P_TIMESTAMP 48 | AND OSN_NONCE = P_NONCE); 49 | 50 | IF V_IS_DUPLICATE_TIMESTAMP = 1 THEN 51 | RAISE V_EXC_DUPLICATE_TIMESTAMP; 52 | END IF; 53 | EXCEPTION 54 | WHEN NO_DATA_FOUND THEN 55 | NULL; 56 | END; 57 | 58 | -- Insert the new combination 59 | INSERT INTO OAUTH_SERVER_NONCE 60 | (OSN_ID, OSN_CONSUMER_KEY, OSN_TOKEN, OSN_TIMESTAMP, OSN_NONCE) 61 | VALUES 62 | (SEQ_OSN_ID.NEXTVAL, P_CONSUMER_KEY, P_TOKEN, P_TIMESTAMP, P_NONCE); 63 | 64 | -- Clean up all timestamps older than the one we just received 65 | DELETE FROM OAUTH_SERVER_NONCE 66 | WHERE OSN_CONSUMER_KEY = P_CONSUMER_KEY 67 | AND OSN_TOKEN = P_TOKEN 68 | AND OSN_TIMESTAMP < (P_TIMESTAMP - P_MAX_TIMESTAMP_SKEW); 69 | 70 | 71 | EXCEPTION 72 | WHEN V_EXC_INVALID_TIMESTAMP THEN 73 | P_RESULT := 2; -- INVALID_TIMESTAMP 74 | WHEN V_EXC_DUPLICATE_TIMESTAMP THEN 75 | P_RESULT := 3; -- DUPLICATE_TIMESTAMP 76 | WHEN OTHERS THEN 77 | -- CALL THE FUNCTION TO LOG ERRORS 78 | ROLLBACK; 79 | P_RESULT := 1; -- ERROR 80 | END; 81 | / 82 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_CONSUMER_STATIC_SAVE.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_CONSUMER_STATIC_SAVE 2 | ( 3 | P_OSR_CONSUMER_KEY IN VARCHAR2, 4 | P_RESULT OUT NUMBER 5 | ) 6 | AS 7 | 8 | -- PROCEDURE TO Fetch the static consumer key for this provider. 9 | BEGIN 10 | P_RESULT := 0; 11 | 12 | 13 | INSERT INTO OAUTH_SERVER_REGISTRY 14 | (OSR_ID, OSR_ENABLED, OSR_STATUS, OSR_USA_ID_REF, OSR_CONSUMER_KEY, OSR_CONSUMER_SECRET, OSR_REQUESTER_NAME, OSR_REQUESTER_EMAIL, OSR_CALLBACK_URI, 15 | OSR_APPLICATION_URI, OSR_APPLICATION_TITLE, OSR_APPLICATION_DESCR, OSR_APPLICATION_NOTES, 16 | OSR_APPLICATION_TYPE, OSR_APPLICATION_COMMERCIAL, OSR_TIMESTAMP,OSR_ISSUE_DATE) 17 | VALUES 18 | (SEQ_OSR_ID.NEXTVAL, 1, 'ACTIVE', NULL, P_OSR_CONSUMER_KEY, '\', '\', '\', '\', '\', 19 | 'STATIC SHARED CONSUMER KEY', '\', 'STATIC SHARED CONSUMER KEY', '\', 0, SYSDATE, SYSDATE); 20 | 21 | 22 | EXCEPTION 23 | WHEN OTHERS THEN 24 | -- CALL THE FUNCTION TO LOG ERRORS 25 | ROLLBACK; 26 | P_RESULT := 1; -- ERROR 27 | END; 28 | / 29 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_COUNT_CONSUMER_ACCESS_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_COUNT_CONSUMER_ACCESS_TOKEN 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_COUNT OUT NUMBER, 5 | P_RESULT OUT NUMBER 6 | ) 7 | AS 8 | -- PROCEDURE TO Count the consumer access tokens for the given consumer. 9 | BEGIN 10 | P_RESULT := 0; 11 | 12 | SELECT COUNT(OST_ID) INTO P_COUNT 13 | FROM OAUTH_SERVER_TOKEN 14 | JOIN OAUTH_SERVER_REGISTRY 15 | ON OST_OSR_ID_REF = OSR_ID 16 | WHERE OST_TOKEN_TYPE = 'ACCESS' 17 | AND OSR_CONSUMER_KEY = P_CONSUMER_KEY 18 | AND OST_TOKEN_TTL >= SYSDATE; 19 | 20 | 21 | EXCEPTION 22 | WHEN OTHERS THEN 23 | -- CALL THE FUNCTION TO LOG ERRORS 24 | ROLLBACK; 25 | P_RESULT := 1; -- ERROR 26 | END; 27 | / 28 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_COUNT_SERVICE_TOKENS.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_COUNT_SERVICE_TOKENS 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_COUNT OUT NUMBER, 5 | P_RESULT OUT NUMBER 6 | ) 7 | AS 8 | 9 | -- PROCEDURE TO Count how many tokens we have for the given server 10 | BEGIN 11 | P_RESULT := 0; 12 | 13 | SELECT COUNT(OCT_ID) INTO P_COUNT 14 | FROM OAUTH_CONSUMER_TOKEN 15 | JOIN OAUTH_CONSUMER_REGISTRY 16 | ON OCT_OCR_ID_REF = OCR_ID 17 | WHERE OCT_TOKEN_TYPE = 'ACCESS' 18 | AND OCR_CONSUMER_KEY = P_CONSUMER_KEY 19 | AND OCT_TOKEN_TTL >= SYSDATE; 20 | 21 | 22 | EXCEPTION 23 | WHEN OTHERS THEN 24 | -- CALL THE FUNCTION TO LOG ERRORS 25 | ROLLBACK; 26 | P_RESULT := 1; -- ERROR 27 | END; 28 | / 29 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_DELETE_CONSUMER.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_DELETE_CONSUMER 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_USER_ID IN NUMBER, 5 | P_USER_IS_ADMIN IN NUMBER, --0:NO; 1:YES 6 | P_RESULT OUT NUMBER 7 | ) 8 | AS 9 | 10 | -- Delete a consumer key. This removes access to our site for all applications using this key. 11 | 12 | BEGIN 13 | P_RESULT := 0; 14 | 15 | IF P_USER_IS_ADMIN = 1 THEN 16 | 17 | DELETE FROM OAUTH_SERVER_REGISTRY 18 | WHERE OSR_CONSUMER_KEY = P_CONSUMER_KEY 19 | AND (OSR_USA_ID_REF = P_USER_ID OR OSR_USA_ID_REF IS NULL); 20 | 21 | ELSIF P_USER_IS_ADMIN = 0 THEN 22 | 23 | DELETE FROM OAUTH_SERVER_REGISTRY 24 | WHERE OSR_CONSUMER_KEY = P_CONSUMER_KEY 25 | AND OSR_USA_ID_REF = P_USER_ID; 26 | 27 | END IF; 28 | 29 | EXCEPTION 30 | WHEN OTHERS THEN 31 | -- CALL THE FUNCTION TO LOG ERRORS 32 | ROLLBACK; 33 | P_RESULT := 1; -- ERROR 34 | END; 35 | / 36 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_DELETE_SERVER.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_DELETE_SERVER 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_USER_ID IN NUMBER, 5 | P_USER_IS_ADMIN IN NUMBER, --0:NO; 1:YES 6 | P_RESULT OUT NUMBER 7 | ) 8 | AS 9 | 10 | -- Delete a server key. This removes access to that site. 11 | 12 | BEGIN 13 | P_RESULT := 0; 14 | 15 | IF P_USER_IS_ADMIN = 1 THEN 16 | 17 | DELETE FROM OAUTH_CONSUMER_REGISTRY 18 | WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY 19 | AND (OCR_USA_ID_REF = P_USER_ID OR OCR_USA_ID_REF IS NULL); 20 | 21 | ELSIF P_USER_IS_ADMIN = 0 THEN 22 | 23 | DELETE FROM OAUTH_CONSUMER_REGISTRY 24 | WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY 25 | AND OCR_USA_ID_REF = P_USER_ID; 26 | 27 | END IF; 28 | 29 | EXCEPTION 30 | WHEN OTHERS THEN 31 | -- CALL THE FUNCTION TO LOG ERRORS 32 | ROLLBACK; 33 | P_RESULT := 1; -- ERROR 34 | END; 35 | / 36 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_DELETE_SERVER_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_DELETE_SERVER_TOKEN 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_USER_ID IN NUMBER, 5 | P_TOKEN IN VARCHAR2, 6 | P_USER_IS_ADMIN IN NUMBER, --0:NO; 1:YES 7 | P_RESULT OUT NUMBER 8 | ) 9 | AS 10 | 11 | -- Delete a token we obtained from a server. 12 | 13 | BEGIN 14 | P_RESULT := 0; 15 | 16 | IF P_USER_IS_ADMIN = 1 THEN 17 | 18 | DELETE FROM OAUTH_CONSUMER_TOKEN 19 | WHERE OCT_TOKEN = P_TOKEN 20 | AND OCT_OCR_ID_REF IN (SELECT OCR_ID FROM OAUTH_CONSUMER_REGISTRY WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY); 21 | 22 | ELSIF P_USER_IS_ADMIN = 0 THEN 23 | 24 | DELETE FROM OAUTH_CONSUMER_TOKEN 25 | WHERE OCT_TOKEN = P_TOKEN 26 | AND OCT_USA_ID_REF = P_USER_ID 27 | AND OCT_OCR_ID_REF IN (SELECT OCR_ID FROM OAUTH_CONSUMER_REGISTRY WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY); 28 | 29 | END IF; 30 | 31 | EXCEPTION 32 | WHEN OTHERS THEN 33 | -- CALL THE FUNCTION TO LOG ERRORS 34 | ROLLBACK; 35 | P_RESULT := 1; -- ERROR 36 | END; 37 | / 38 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_DEL_CONSUMER_ACCESS_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_DEL_CONSUMER_ACCESS_TOKEN 2 | ( 3 | P_USER_ID IN NUMBER, 4 | P_TOKEN IN VARCHAR2, 5 | P_USER_IS_ADMIN IN NUMBER, -- 1:YES; 0:NO 6 | P_RESULT OUT NUMBER 7 | ) 8 | AS 9 | 10 | -- PROCEDURE TO Delete a consumer access token. 11 | 12 | BEGIN 13 | 14 | P_RESULT := 0; 15 | 16 | IF P_USER_IS_ADMIN = 1 THEN 17 | DELETE FROM OAUTH_SERVER_TOKEN 18 | WHERE OST_TOKEN = P_TOKEN 19 | AND OST_TOKEN_TYPE = 'ACCESS'; 20 | ELSE 21 | DELETE FROM OAUTH_SERVER_TOKEN 22 | WHERE OST_TOKEN = P_TOKEN 23 | AND OST_TOKEN_TYPE = 'ACCESS' 24 | AND OST_USA_ID_REF = P_USER_ID; 25 | END IF; 26 | 27 | EXCEPTION 28 | WHEN OTHERS THEN 29 | -- CALL THE FUNCTION TO LOG ERRORS 30 | ROLLBACK; 31 | P_RESULT := 1; -- ERROR 32 | END; 33 | / 34 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_DEL_CONSUMER_REQUEST_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_DEL_CONSUMER_REQUEST_TOKEN 2 | ( 3 | P_TOKEN IN VARCHAR2, 4 | P_RESULT OUT NUMBER 5 | ) 6 | AS 7 | 8 | -- PROCEDURE TO Delete a consumer token. The token must be a request or authorized token. 9 | 10 | BEGIN 11 | 12 | P_RESULT := 0; 13 | 14 | DELETE FROM OAUTH_SERVER_TOKEN 15 | WHERE OST_TOKEN = P_TOKEN 16 | AND OST_TOKEN_TYPE = 'REQUEST'; 17 | 18 | 19 | EXCEPTION 20 | WHEN OTHERS THEN 21 | -- CALL THE FUNCTION TO LOG ERRORS 22 | ROLLBACK; 23 | P_RESULT := 1; -- ERROR 24 | END; 25 | / 26 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_EXCH_CONS_REQ_FOR_ACC_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_EXCH_CONS_REQ_FOR_ACC_TOKEN 2 | ( 3 | P_TOKEN_TTL IN NUMBER, -- IN SECOND 4 | P_NEW_TOKEN IN VARCHAR2, 5 | P_TOKEN IN VARCHAR2, 6 | P_TOKEN_SECRET IN VARCHAR2, 7 | P_VERIFIER IN VARCHAR2, 8 | P_OUT_TOKEN_TTL OUT NUMBER, 9 | P_RESULT OUT NUMBER 10 | ) 11 | AS 12 | 13 | -- PROCEDURE TO Add an unautorized request token to our server. 14 | 15 | V_TOKEN_EXIST NUMBER; 16 | 17 | 18 | V_EXC_NO_TOKEN_EXIST EXCEPTION; 19 | BEGIN 20 | 21 | P_RESULT := 0; 22 | 23 | IF P_VERIFIER IS NOT NULL THEN 24 | 25 | BEGIN 26 | SELECT 1 INTO V_TOKEN_EXIST FROM DUAL WHERE EXISTS 27 | (SELECT OST_TOKEN FROM OAUTH_SERVER_TOKEN 28 | WHERE OST_TOKEN = P_TOKEN 29 | AND OST_TOKEN_TYPE = 'REQUEST' 30 | AND OST_AUTHORIZED = 1 31 | AND OST_TOKEN_TTL >= SYSDATE 32 | AND OST_VERIFIER = P_VERIFIER); 33 | EXCEPTION 34 | WHEN NO_DATA_FOUND THEN 35 | RAISE V_EXC_NO_TOKEN_EXIST; 36 | END; 37 | 38 | UPDATE OAUTH_SERVER_TOKEN 39 | SET OST_TOKEN = P_NEW_TOKEN, 40 | OST_TOKEN_SECRET = P_TOKEN_SECRET, 41 | OST_TOKEN_TYPE = 'ACCESS', 42 | OST_TIMESTAMP = SYSDATE, 43 | OST_TOKEN_TTL = NVL(SYSDATE + (P_TOKEN_TTL/(24*60*60)), TO_DATE('9999.12.31', 'yyyy.mm.dd')) 44 | WHERE OST_TOKEN = P_TOKEN 45 | AND OST_TOKEN_TYPE = 'REQUEST' 46 | AND OST_AUTHORIZED = 1 47 | AND OST_TOKEN_TTL >= SYSDATE 48 | AND OST_VERIFIER = P_VERIFIER; 49 | 50 | ELSE 51 | BEGIN 52 | SELECT 1 INTO V_TOKEN_EXIST FROM DUAL WHERE EXISTS 53 | (SELECT OST_TOKEN FROM OAUTH_SERVER_TOKEN 54 | WHERE OST_TOKEN = P_TOKEN 55 | AND OST_TOKEN_TYPE = 'REQUEST' 56 | AND OST_AUTHORIZED = 1 57 | AND OST_TOKEN_TTL >= SYSDATE); 58 | EXCEPTION 59 | WHEN NO_DATA_FOUND THEN 60 | RAISE V_EXC_NO_TOKEN_EXIST; 61 | END; 62 | 63 | UPDATE OAUTH_SERVER_TOKEN 64 | SET OST_TOKEN = P_NEW_TOKEN, 65 | OST_TOKEN_SECRET = P_TOKEN_SECRET, 66 | OST_TOKEN_TYPE = 'ACCESS', 67 | OST_TIMESTAMP = SYSDATE, 68 | OST_TOKEN_TTL = NVL(SYSDATE + (P_TOKEN_TTL/(24*60*60)), TO_DATE('9999.12.31', 'yyyy.mm.dd')) 69 | WHERE OST_TOKEN = P_TOKEN 70 | AND OST_TOKEN_TYPE = 'REQUEST' 71 | AND OST_AUTHORIZED = 1 72 | AND OST_TOKEN_TTL >= SYSDATE; 73 | 74 | 75 | END IF; 76 | 77 | SELECT CASE 78 | WHEN OST_TOKEN_TTL >= TO_DATE('9999.12.31', 'yyyy.mm.dd') THEN NULL ELSE (OST_TOKEN_TTL - SYSDATE)*24*60*60 79 | END "TOKEN_TTL" INTO P_OUT_TOKEN_TTL 80 | FROM OAUTH_SERVER_TOKEN 81 | WHERE OST_TOKEN = P_NEW_TOKEN; 82 | 83 | 84 | 85 | 86 | 87 | 88 | EXCEPTION 89 | WHEN V_EXC_NO_TOKEN_EXIST THEN 90 | P_RESULT := 2; -- NO_TOKEN_EXIST 91 | WHEN OTHERS THEN 92 | -- CALL THE FUNCTION TO LOG ERRORS 93 | ROLLBACK; 94 | P_RESULT := 1; -- ERROR 95 | END; 96 | / 97 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_CONSUMER.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_CONSUMER 2 | ( 3 | P_CONSUMER_KEY IN STRING, 4 | P_ROWS OUT TYPES.REF_CURSOR, 5 | P_RESULT OUT NUMBER 6 | ) 7 | AS 8 | 9 | -- PROCEDURE TO Fetch a consumer of this server, by consumer_key. 10 | BEGIN 11 | P_RESULT := 0; 12 | 13 | OPEN P_ROWS FOR 14 | SELECT OSR_ID "osr_id", 15 | OSR_USA_ID_REF "osr_usa_id_ref", 16 | OSR_CONSUMER_KEY "osr_consumer_key", 17 | OSR_CONSUMER_SECRET "osr_consumer_secret", 18 | OSR_ENABLED "osr_enabled", 19 | OSR_STATUS "osr_status", 20 | OSR_REQUESTER_NAME "osr_requester_name", 21 | OSR_REQUESTER_EMAIL "osr_requester_email", 22 | OSR_CALLBACK_URI "osr_callback_uri", 23 | OSR_APPLICATION_URI "osr_application_uri", 24 | OSR_APPLICATION_TITLE "osr_application_title", 25 | OSR_APPLICATION_DESCR "osr_application_descr", 26 | OSR_APPLICATION_NOTES "osr_application_notes", 27 | OSR_APPLICATION_TYPE "osr_application_type", 28 | OSR_APPLICATION_COMMERCIAL "osr_application_commercial", 29 | OSR_ISSUE_DATE "osr_issue_date", 30 | OSR_TIMESTAMP "osr_timestamp" 31 | FROM OAUTH_SERVER_REGISTRY 32 | WHERE OSR_CONSUMER_KEY = P_CONSUMER_KEY; 33 | 34 | 35 | EXCEPTION 36 | WHEN OTHERS THEN 37 | -- CALL THE FUNCTION TO LOG ERRORS 38 | ROLLBACK; 39 | P_RESULT := 1; -- ERROR 40 | END; 41 | / 42 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_CONSUMER_ACCESS_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_CONSUMER_ACCESS_TOKEN 2 | ( 3 | P_USER_ID IN NUMBER, 4 | P_TOKEN IN VARCHAR2, 5 | P_ROWS OUT TYPES.REF_CURSOR, 6 | P_RESULT OUT NUMBER 7 | ) 8 | AS 9 | 10 | -- PROCEDURE TO Fetch the consumer access token, by access token. 11 | 12 | BEGIN 13 | 14 | P_RESULT := 0; 15 | 16 | 17 | OPEN P_ROWS FOR 18 | SELECT OST_TOKEN "token", 19 | OST_TOKEN_SECRET "token_secret", 20 | OST_REFERRER_HOST "token_referrer_host", 21 | OSR_CONSUMER_KEY "consumer_key", 22 | OSR_CONSUMER_SECRET "consumer_secret", 23 | OSR_APPLICATION_URI "application_uri", 24 | OSR_APPLICATION_TITLE "application_title", 25 | OSR_APPLICATION_DESCR "application_descr", 26 | OSR_CALLBACK_URI "callback_uri" 27 | FROM OAUTH_SERVER_TOKEN 28 | JOIN OAUTH_SERVER_REGISTRY 29 | ON OST_OSR_ID_REF = OSR_ID 30 | WHERE OST_TOKEN_TYPE = 'ACCESS' 31 | AND OST_TOKEN = P_TOKEN 32 | AND OST_USA_ID_REF = P_USER_ID 33 | AND OST_TOKEN_TTL >= SYSDATE; 34 | 35 | 36 | 37 | EXCEPTION 38 | WHEN OTHERS THEN 39 | -- CALL THE FUNCTION TO LOG ERRORS 40 | ROLLBACK; 41 | P_RESULT := 1; -- ERROR 42 | END; 43 | / 44 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_CONSUMER_REQUEST_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_CONSUMER_REQUEST_TOKEN 2 | ( 3 | P_TOKEN IN VARCHAR2, 4 | P_ROWS OUT TYPES.REF_CURSOR, 5 | P_RESULT OUT NUMBER 6 | ) 7 | AS 8 | 9 | -- PROCEDURE TO Fetch the consumer request token, by request token. 10 | BEGIN 11 | P_RESULT := 0; 12 | 13 | OPEN P_ROWS FOR 14 | 15 | SELECT OST_TOKEN "token", 16 | OST_TOKEN_SECRET "token_secret", 17 | OSR_CONSUMER_KEY "consumer_key", 18 | OSR_CONSUMER_SECRET "consumer_secret", 19 | OST_TOKEN_TYPE "token_type", 20 | OST_CALLBACK_URL "callback_url", 21 | OSR_APPLICATION_TITLE "application_title", 22 | OSR_APPLICATION_DESCR "application_descr", 23 | OSR_APPLICATION_URI "application_uri" 24 | FROM OAUTH_SERVER_TOKEN 25 | JOIN OAUTH_SERVER_REGISTRY 26 | ON OST_OSR_ID_REF = OSR_ID 27 | WHERE OST_TOKEN_TYPE = 'REQUEST' 28 | AND OST_TOKEN = P_TOKEN 29 | AND OST_TOKEN_TTL >= SYSDATE; 30 | 31 | 32 | 33 | 34 | 35 | EXCEPTION 36 | WHEN OTHERS THEN 37 | -- CALL THE FUNCTION TO LOG ERRORS 38 | ROLLBACK; 39 | P_RESULT := 1; -- ERROR 40 | END; 41 | / 42 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_CONSUMER_STATIC_SELECT.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_CONSUMER_STATIC_SELECT 2 | ( 3 | P_OSR_CONSUMER_KEY OUT VARCHAR2, 4 | P_RESULT OUT NUMBER 5 | ) 6 | AS 7 | 8 | -- PROCEDURE TO Fetch the static consumer key for this provider. 9 | BEGIN 10 | P_RESULT := 0; 11 | 12 | 13 | SELECT OSR_CONSUMER_KEY INTO P_OSR_CONSUMER_KEY 14 | FROM OAUTH_SERVER_REGISTRY 15 | WHERE OSR_CONSUMER_KEY LIKE 'sc-%%' 16 | AND OSR_USA_ID_REF IS NULL; 17 | 18 | 19 | EXCEPTION 20 | WHEN OTHERS THEN 21 | -- CALL THE FUNCTION TO LOG ERRORS 22 | ROLLBACK; 23 | P_RESULT := 1; -- ERROR 24 | END; 25 | / 26 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_SECRETS_FOR_SIGNATURE.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_SECRETS_FOR_SIGNATURE 2 | ( 3 | P_HOST IN VARCHAR2, 4 | P_PATH IN VARCHAR2, 5 | P_USER_ID IN NUMBER, 6 | P_NAME IN VARCHAR2, 7 | P_ROWS OUT TYPES.REF_CURSOR, 8 | P_RESULT OUT NUMBER 9 | ) 10 | AS 11 | 12 | -- PROCEDURE TO Find the server details for signing a request, always looks for an access token. 13 | -- The returned credentials depend on which local user is making the request. 14 | BEGIN 15 | P_RESULT := 0; 16 | 17 | OPEN P_ROWS FOR 18 | SELECT * FROM ( 19 | SELECT OCR_CONSUMER_KEY "consumer_key", 20 | OCR_CONSUMER_SECRET "consumer_secret", 21 | OCT_TOKEN "token", 22 | OCT_TOKEN_SECRET "token_secret", 23 | OCR_SIGNATURE_METHODS "signature_methods" 24 | FROM OAUTH_CONSUMER_REGISTRY 25 | JOIN OAUTH_CONSUMER_TOKEN ON OCT_OCR_ID_REF = OCR_ID 26 | WHERE OCR_SERVER_URI_HOST = P_HOST 27 | AND OCR_SERVER_URI_PATH = SUBSTR(P_PATH, 1, LENGTH(OCR_SERVER_URI_PATH)) 28 | AND (OCR_USA_ID_REF = P_USER_ID OR OCR_USA_ID_REF IS NULL) 29 | AND OCT_USA_ID_REF = P_USER_ID 30 | AND OCT_TOKEN_TYPE = 'ACCESS' 31 | AND OCT_NAME = P_NAME 32 | AND OCT_TOKEN_TTL >= SYSDATE 33 | ORDER BY OCR_USA_ID_REF DESC, OCR_CONSUMER_SECRET DESC, LENGTH(OCR_SERVER_URI_PATH) DESC 34 | ) WHERE ROWNUM<=1; 35 | 36 | 37 | EXCEPTION 38 | WHEN OTHERS THEN 39 | -- CALL THE FUNCTION TO LOG ERRORS 40 | ROLLBACK; 41 | P_RESULT := 1; -- ERROR 42 | END; 43 | / 44 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_SECRETS_FOR_VERIFY.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_SECRETS_FOR_VERIFY 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_TOKEN IN VARCHAR2, 5 | P_TOKEN_TYPE IN VARCHAR2, 6 | P_ROWS OUT TYPES.REF_CURSOR, 7 | P_RESULT OUT NUMBER 8 | ) 9 | AS 10 | 11 | -- PROCEDURE to Find stored credentials for the consumer key and token. Used by an OAuth server 12 | -- when verifying an OAuth request. 13 | 14 | BEGIN 15 | P_RESULT := 0; 16 | 17 | IF P_TOKEN_TYPE IS NULL THEN 18 | OPEN P_ROWS FOR 19 | SELECT OSR.OSR_ID "osr_id", 20 | OSR.OSR_CONSUMER_KEY "consumer_key", 21 | OSR.OSR_CONSUMER_SECRET "consumer_secret" 22 | FROM OAUTH_SERVER_REGISTRY OSR 23 | WHERE OSR.OSR_CONSUMER_KEY = P_CONSUMER_KEY 24 | AND OSR.OSR_ENABLED = 1; 25 | ELSE 26 | OPEN P_ROWS FOR 27 | SELECT OSR.OSR_ID "osr_id", 28 | OST.OST_ID "ost_id", 29 | OST.OST_USA_ID_REF "user_id", 30 | OSR.OSR_CONSUMER_KEY "consumer_key", 31 | OSR.OSR_CONSUMER_SECRET "consumer_secret", 32 | OST.OST_TOKEN "token", 33 | OST.OST_TOKEN_SECRET "token_secret" 34 | FROM OAUTH_SERVER_REGISTRY OSR, OAUTH_SERVER_TOKEN OST 35 | WHERE OST.OST_OSR_ID_REF = OSR.OSR_ID 36 | AND upper(OST.OST_TOKEN_TYPE) = upper(P_TOKEN_TYPE) 37 | AND OSR.OSR_CONSUMER_KEY = P_CONSUMER_KEY 38 | AND OST.OST_TOKEN = P_TOKEN 39 | AND OSR.OSR_ENABLED = 1 40 | AND OST.OST_TOKEN_TTL >= SYSDATE; 41 | 42 | END IF; 43 | 44 | 45 | 46 | EXCEPTION 47 | WHEN OTHERS THEN 48 | -- CALL THE FUNCTION TO LOG ERRORS 49 | ROLLBACK; 50 | P_RESULT := 1; -- ERROR 51 | END; 52 | / 53 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_SERVER.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_SERVER 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_USER_ID IN NUMBER, 5 | P_ROWS OUT TYPES.REF_CURSOR, 6 | P_RESULT OUT NUMBER 7 | ) 8 | AS 9 | 10 | -- PROCEDURE TO Get a server from the consumer registry using the consumer key 11 | BEGIN 12 | P_RESULT := 0; 13 | 14 | OPEN P_ROWS FOR 15 | SELECT OCR_ID "id", 16 | OCR_USA_ID_REF "user_id", 17 | OCR_CONSUMER_KEY "consumer_key", 18 | OCR_CONSUMER_SECRET "consumer_secret", 19 | OCR_SIGNATURE_METHODS "signature_methods", 20 | OCR_SERVER_URI "server_uri", 21 | OCR_REQUEST_TOKEN_URI "request_token_uri", 22 | OCR_AUTHORIZE_URI "authorize_uri", 23 | OCR_ACCESS_TOKEN_URI "access_token_uri" 24 | FROM OAUTH_CONSUMER_REGISTRY 25 | WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY 26 | AND (OCR_USA_ID_REF = P_USER_ID OR OCR_USA_ID_REF IS NULL); 27 | 28 | 29 | EXCEPTION 30 | WHEN OTHERS THEN 31 | -- CALL THE FUNCTION TO LOG ERRORS 32 | ROLLBACK; 33 | P_RESULT := 1; -- ERROR 34 | END; 35 | / 36 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_SERVER_FOR_URI.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_SERVER_FOR_URI 2 | ( 3 | P_HOST IN VARCHAR2, 4 | P_PATH IN VARCHAR2, 5 | P_USER_ID IN NUMBER, 6 | P_ROWS OUT TYPES.REF_CURSOR, 7 | P_RESULT OUT NUMBER 8 | ) 9 | AS 10 | 11 | -- PROCEDURE TO Find the server details that might be used for a request 12 | BEGIN 13 | P_RESULT := 0; 14 | 15 | OPEN P_ROWS FOR 16 | SELECT * FROM ( 17 | SELECT OCR_ID "id", 18 | OCR_USA_ID_REF "user_id", 19 | OCR_CONSUMER_KEY "consumer_key", 20 | OCR_CONSUMER_SECRET "consumer_secret", 21 | OCR_SIGNATURE_METHODS "signature_methods", 22 | OCR_SERVER_URI "server_uri", 23 | OCR_REQUEST_TOKEN_URI "request_token_uri", 24 | OCR_AUTHORIZE_URI "authorize_uri", 25 | OCR_ACCESS_TOKEN_URI "access_token_uri" 26 | FROM OAUTH_CONSUMER_REGISTRY 27 | WHERE OCR_SERVER_URI_HOST = P_HOST 28 | AND OCR_SERVER_URI_PATH = SUBSTR(P_PATH, 1, LENGTH(OCR_SERVER_URI_PATH)) 29 | AND (OCR_USA_ID_REF = P_USER_ID OR OCR_USA_ID_REF IS NULL) 30 | ORDER BY ocr_usa_id_ref DESC, OCR_CONSUMER_KEY DESC, LENGTH(ocr_server_uri_path) DESC 31 | ) WHERE ROWNUM<=1; 32 | 33 | 34 | 35 | EXCEPTION 36 | WHEN OTHERS THEN 37 | -- CALL THE FUNCTION TO LOG ERRORS 38 | ROLLBACK; 39 | P_RESULT := 1; -- ERROR 40 | END; 41 | / 42 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_SERVER_TOKEN.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_SERVER_TOKEN 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_USER_ID IN NUMBER, 5 | P_TOKEN IN VARCHAR2, 6 | P_ROWS OUT TYPES.REF_CURSOR, 7 | P_RESULT OUT NUMBER 8 | ) 9 | AS 10 | 11 | -- PROCEDURE TO Get a specific server token for the given user 12 | BEGIN 13 | P_RESULT := 0; 14 | 15 | OPEN P_ROWS FOR 16 | SELECT OCR_CONSUMER_KEY "consumer_key", 17 | OCR_CONSUMER_SECRET "consumer_secret", 18 | OCT_TOKEN "token", 19 | OCT_TOKEN_SECRET "token_secret", 20 | OCT_USA_ID_REF "usr_id", 21 | OCR_SIGNATURE_METHODS "signature_methods", 22 | OCR_SERVER_URI "server_uri", 23 | OCR_SERVER_URI_HOST "server_uri_host", 24 | OCR_SERVER_URI_PATH "server_uri_path", 25 | OCR_REQUEST_TOKEN_URI "request_token_uri", 26 | OCR_AUTHORIZE_URI "authorize_uri", 27 | OCR_ACCESS_TOKEN_URI "access_token_uri", 28 | OCT_TIMESTAMP "timestamp" 29 | FROM OAUTH_CONSUMER_REGISTRY 30 | JOIN OAUTH_CONSUMER_TOKEN 31 | ON OCT_OCR_ID_REF = OCR_ID 32 | WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY 33 | AND OCT_USA_ID_REF = P_USER_ID 34 | AND OCT_TOKEN_TYPE = 'ACCESS' 35 | AND OCT_TOKEN = P_TOKEN 36 | AND OCT_TOKEN_TTL >= SYSDATE; 37 | 38 | 39 | EXCEPTION 40 | WHEN OTHERS THEN 41 | -- CALL THE FUNCTION TO LOG ERRORS 42 | ROLLBACK; 43 | P_RESULT := 1; -- ERROR 44 | END; 45 | / 46 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_GET_SERVER_TOKEN_SECRETS.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_GET_SERVER_TOKEN_SECRETS 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_TOKEN IN VARCHAR2, 5 | P_TOKEN_TYPE IN VARCHAR2, 6 | P_USER_ID IN NUMBER, 7 | P_ROWS OUT TYPES.REF_CURSOR, 8 | P_RESULT OUT NUMBER 9 | ) 10 | AS 11 | 12 | -- Get the token and token secret we obtained from a server. 13 | 14 | BEGIN 15 | P_RESULT := 0; 16 | 17 | 18 | OPEN P_ROWS FOR 19 | SELECT OCR.OCR_CONSUMER_KEY "consumer_key", 20 | OCR.OCR_CONSUMER_SECRET "consumer_secret", 21 | OCT.OCT_TOKEN "token", 22 | OCT.OCT_TOKEN_SECRET "token_secret", 23 | OCT.OCT_NAME "token_name", 24 | OCR.OCR_SIGNATURE_METHODS "signature_methods", 25 | OCR.OCR_SERVER_URI "server_uri", 26 | OCR.OCR_REQUEST_TOKEN_URI "request_token_uri", 27 | OCR.OCR_AUTHORIZE_URI "authorize_uri", 28 | OCR.OCR_ACCESS_TOKEN_URI "access_token_uri", 29 | CASE WHEN OCT.OCT_TOKEN_TTL >= TO_DATE('9999.12.31', 'yyyy.mm.dd') THEN NULL 30 | ELSE OCT.OCT_TOKEN_TTL - SYSDATE 31 | END "token_ttl" 32 | FROM OAUTH_CONSUMER_REGISTRY OCR, OAUTH_CONSUMER_TOKEN OCT 33 | WHERE OCT.OCT_OCR_ID_REF = OCR_ID 34 | AND OCR.OCR_CONSUMER_KEY = P_CONSUMER_KEY 35 | AND upper(OCT.OCT_TOKEN_TYPE) = upper(P_TOKEN_TYPE) 36 | AND OCT.OCT_TOKEN = P_TOKEN 37 | AND OCT.OCT_USA_ID_REF = P_USER_ID 38 | AND OCT.OCT_TOKEN_TTL >= SYSDATE; 39 | 40 | 41 | EXCEPTION 42 | WHEN OTHERS THEN 43 | -- CALL THE FUNCTION TO LOG ERRORS 44 | ROLLBACK; 45 | P_RESULT := 1; -- ERROR 46 | END; 47 | / 48 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_LIST_CONSUMERS.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_LIST_CONSUMERS 2 | ( 3 | P_USER_ID IN NUMBER, 4 | P_ROWS OUT TYPES.REF_CURSOR, 5 | P_RESULT OUT NUMBER 6 | ) 7 | AS 8 | 9 | -- PROCEDURE TO Fetch a list of all consumer keys, secrets etc. 10 | -- Returns the public (user_id is null) and the keys owned by the user 11 | 12 | BEGIN 13 | 14 | P_RESULT := 0; 15 | 16 | OPEN P_ROWS FOR 17 | SELECT OSR_ID "id", 18 | OSR_USA_ID_REF "user_id", 19 | OSR_CONSUMER_KEY "consumer_key", 20 | OSR_CONSUMER_SECRET "consumer_secret", 21 | OSR_ENABLED "enabled", 22 | OSR_STATUS "status", 23 | OSR_ISSUE_DATE "issue_date", 24 | OSR_APPLICATION_URI "application_uri", 25 | OSR_APPLICATION_TITLE "application_title", 26 | OSR_APPLICATION_DESCR "application_descr", 27 | OSR_REQUESTER_NAME "requester_name", 28 | OSR_REQUESTER_EMAIL "requester_email", 29 | OSR_CALLBACK_URI "callback_uri" 30 | FROM OAUTH_SERVER_REGISTRY 31 | WHERE (OSR_USA_ID_REF = P_USER_ID OR OSR_USA_ID_REF IS NULL) 32 | ORDER BY OSR_APPLICATION_TITLE; 33 | 34 | 35 | EXCEPTION 36 | WHEN OTHERS THEN 37 | -- CALL THE FUNCTION TO LOG ERRORS 38 | ROLLBACK; 39 | P_RESULT := 1; -- ERROR 40 | END; 41 | / 42 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_LIST_CONSUMER_TOKENS.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_LIST_CONSUMER_TOKENS 2 | ( 3 | P_USER_ID IN NUMBER, 4 | P_ROWS OUT TYPES.REF_CURSOR, 5 | P_RESULT OUT NUMBER 6 | ) 7 | AS 8 | 9 | -- PROCEDURE TO Fetch a list of all consumer tokens accessing the account of the given user. 10 | 11 | BEGIN 12 | 13 | P_RESULT := 0; 14 | 15 | OPEN P_ROWS FOR 16 | SELECT OSR_CONSUMER_KEY "consumer_key", 17 | OSR_CONSUMER_SECRET "consumer_secret", 18 | OSR_ENABLED "enabled", 19 | OSR_STATUS "status", 20 | OSR_APPLICATION_URI "application_uri", 21 | OSR_APPLICATION_TITLE "application_title", 22 | OSR_APPLICATION_DESCR "application_descr", 23 | OST_TIMESTAMP "timestamp", 24 | OST_TOKEN "token", 25 | OST_TOKEN_SECRET "token_secret", 26 | OST_REFERRER_HOST "token_referrer_host", 27 | OSR_CALLBACK_URI "callback_uri" 28 | FROM OAUTH_SERVER_REGISTRY 29 | JOIN OAUTH_SERVER_TOKEN 30 | ON OST_OSR_ID_REF = OSR_ID 31 | WHERE OST_USA_ID_REF = P_USER_ID 32 | AND OST_TOKEN_TYPE = 'ACCESS' 33 | AND OST_TOKEN_TTL >= SYSDATE 34 | ORDER BY OSR_APPLICATION_TITLE; 35 | 36 | 37 | EXCEPTION 38 | WHEN OTHERS THEN 39 | -- CALL THE FUNCTION TO LOG ERRORS 40 | ROLLBACK; 41 | P_RESULT := 1; -- ERROR 42 | END; 43 | / 44 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_LIST_LOG.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_LIST_LOG 2 | ( 3 | P_OPTION_FLAG IN NUMBER, -- 0:NULL; 1:OTHERWISE 4 | P_USA_ID IN NUMBER, 5 | P_OSR_CONSUMER_KEY IN VARCHAR2, 6 | P_OCR_CONSUMER_KEY IN VARCHAR2, 7 | P_OST_TOKEN IN VARCHAR2, 8 | P_OCT_TOKEN IN VARCHAR2, 9 | P_ROWS OUT TYPES.REF_CURSOR, 10 | P_RESULT OUT NUMBER 11 | ) 12 | AS 13 | 14 | -- PROCEDURE TO Get a page of entries from the log. Returns the last 100 records 15 | -- matching the options given. 16 | 17 | BEGIN 18 | 19 | P_RESULT := 0; 20 | 21 | IF P_OPTION_FLAG IS NULL OR P_OPTION_FLAG = 0 THEN 22 | OPEN P_ROWS FOR 23 | SELECT * FROM ( 24 | SELECT OLG_ID "olg_id", 25 | OLG_OSR_CONSUMER_KEY "osr_consumer_key", 26 | OLG_OST_TOKEN "ost_token", 27 | OLG_OCR_CONSUMER_KEY "ocr_consumer_key", 28 | OLG_OCT_TOKEN "oct_token", 29 | OLG_USA_ID_REF "user_id", 30 | OLG_RECEIVED "received", 31 | OLG_SENT "sent", 32 | OLG_BASE_STRING "base_string", 33 | OLG_NOTES "notes", 34 | OLG_TIMESTAMP "timestamp", 35 | -- INET_NTOA(OLG_REMOTE_IP) "remote_ip" 36 | OLG_REMOTE_IP "remote_ip" 37 | FROM OAUTH_LOG 38 | WHERE OLG_USA_ID_REF = P_USA_ID 39 | ORDER BY OLG_ID DESC 40 | ) WHERE ROWNUM<=100; 41 | ELSE 42 | OPEN P_ROWS FOR 43 | SELECT * FROM ( 44 | SELECT OLG_ID "olg_id", 45 | OLG_OSR_CONSUMER_KEY "osr_consumer_key", 46 | OLG_OST_TOKEN "ost_token", 47 | OLG_OCR_CONSUMER_KEY "ocr_consumer_key", 48 | OLG_OCT_TOKEN "oct_token", 49 | OLG_USA_ID_REF "user_id", 50 | OLG_RECEIVED "received", 51 | OLG_SENT "sent", 52 | OLG_BASE_STRING "base_string", 53 | OLG_NOTES "notes", 54 | OLG_TIMESTAMP "timestamp", 55 | -- INET_NTOA(OLG_REMOTE_IP) "remote_ip" 56 | OLG_REMOTE_IP "remote_ip" 57 | FROM OAUTH_LOG 58 | WHERE OLG_OSR_CONSUMER_KEY = P_OSR_CONSUMER_KEY 59 | AND OLG_OCR_CONSUMER_KEY = P_OCR_CONSUMER_KEY 60 | AND OLG_OST_TOKEN = P_OST_TOKEN 61 | AND OLG_OCT_TOKEN = P_OCT_TOKEN 62 | AND (OLG_USA_ID_REF IS NULL OR OLG_USA_ID_REF = P_USA_ID) 63 | ORDER BY OLG_ID DESC 64 | ) WHERE ROWNUM<=100; 65 | 66 | END IF; 67 | 68 | 69 | EXCEPTION 70 | WHEN OTHERS THEN 71 | -- CALL THE FUNCTION TO LOG ERRORS 72 | ROLLBACK; 73 | P_RESULT := 1; -- ERROR 74 | END; 75 | / 76 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_LIST_SERVERS.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_LIST_SERVERS 2 | ( 3 | P_Q IN VARCHAR2, 4 | P_USER_ID IN NUMBER, 5 | P_ROWS OUT TYPES.REF_CURSOR, 6 | P_RESULT OUT NUMBER 7 | ) 8 | AS 9 | 10 | -- PROCEDURE TO Get a list of all consumers from the consumer registry. 11 | BEGIN 12 | P_RESULT := 0; 13 | 14 | IF P_Q IS NOT NULL THEN 15 | 16 | OPEN P_ROWS FOR 17 | SELECT OCR_ID "id", 18 | OCR_USA_ID_REF "user_id", 19 | OCR_CONSUMER_KEY "consumer_key", 20 | OCR_CONSUMER_SECRET "consumer_secret", 21 | OCR_SIGNATURE_METHODS "signature_methods", 22 | OCR_SERVER_URI "server_uri", 23 | OCR_SERVER_URI_HOST "server_uri_host", 24 | OCR_SERVER_URI_PATH "server_uri_path", 25 | OCR_REQUEST_TOKEN_URI "request_token_uri", 26 | OCR_AUTHORIZE_URI "authorize_uri", 27 | OCR_ACCESS_TOKEN_URI "access_token_uri" 28 | FROM OAUTH_CONSUMER_REGISTRY 29 | WHERE ( OCR_CONSUMER_KEY LIKE '%'|| P_Q ||'%' 30 | OR OCR_SERVER_URI LIKE '%'|| P_Q ||'%' 31 | OR OCR_SERVER_URI_HOST LIKE '%'|| P_Q ||'%' 32 | OR OCR_SERVER_URI_PATH LIKE '%'|| P_Q ||'%') 33 | AND (OCR_USA_ID_REF = P_USER_ID OR OCR_USA_ID_REF IS NULL) 34 | ORDER BY OCR_SERVER_URI_HOST, OCR_SERVER_URI_PATH; 35 | 36 | ELSE 37 | 38 | OPEN P_ROWS FOR 39 | SELECT OCR_ID "id", 40 | OCR_USA_ID_REF "user_id", 41 | OCR_CONSUMER_KEY "consumer_key", 42 | OCR_CONSUMER_SECRET "consumer_secret", 43 | OCR_SIGNATURE_METHODS "signature_methods", 44 | OCR_SERVER_URI "server_uri", 45 | OCR_SERVER_URI_HOST "server_uri_host", 46 | OCR_SERVER_URI_PATH "server_uri_path", 47 | OCR_REQUEST_TOKEN_URI "request_token_uri", 48 | OCR_AUTHORIZE_URI "authorize_uri", 49 | OCR_ACCESS_TOKEN_URI "access_token_uri" 50 | FROM OAUTH_CONSUMER_REGISTRY 51 | WHERE OCR_USA_ID_REF = P_USER_ID OR OCR_USA_ID_REF IS NULL 52 | ORDER BY OCR_SERVER_URI_HOST, OCR_SERVER_URI_PATH; 53 | 54 | END IF; 55 | 56 | 57 | 58 | 59 | 60 | EXCEPTION 61 | WHEN OTHERS THEN 62 | -- CALL THE FUNCTION TO LOG ERRORS 63 | ROLLBACK; 64 | P_RESULT := 1; -- ERROR 65 | END; 66 | / 67 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_LIST_SERVER_TOKENS.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_LIST_SERVER_TOKENS 2 | ( 3 | P_USER_ID IN NUMBER, 4 | P_ROWS OUT TYPES.REF_CURSOR, 5 | P_RESULT OUT NUMBER 6 | ) 7 | AS 8 | 9 | -- PROCEDURE TO Find the server details that might be used for a request 10 | BEGIN 11 | P_RESULT := 0; 12 | 13 | OPEN P_ROWS FOR 14 | SELECT OCR_CONSUMER_KEY "consumer_key", 15 | OCR_CONSUMER_SECRET "consumer_secret", 16 | OCT_ID "token_id", 17 | OCT_TOKEN "token", 18 | OCT_TOKEN_SECRET "token_secret", 19 | OCT_USA_ID_REF "user_id", 20 | OCR_SIGNATURE_METHODS "signature_methods", 21 | OCR_SERVER_URI "server_uri", 22 | OCR_SERVER_URI_HOST "server_uri_host", 23 | OCR_SERVER_URI_PATH "server_uri_path", 24 | OCR_REQUEST_TOKEN_URI "request_token_uri", 25 | OCR_AUTHORIZE_URI "authorize_uri", 26 | OCR_ACCESS_TOKEN_URI "access_token_uri", 27 | OCT_TIMESTAMP "timestamp" 28 | FROM OAUTH_CONSUMER_REGISTRY 29 | JOIN OAUTH_CONSUMER_TOKEN 30 | ON OCT_OCR_ID_REF = OCR_ID 31 | WHERE OCT_USA_ID_REF = P_USER_ID 32 | AND OCT_TOKEN_TYPE = 'ACCESS' 33 | AND OCT_TOKEN_TTL >= SYSDATE 34 | ORDER BY OCR_SERVER_URI_HOST, OCR_SERVER_URI_PATH; 35 | 36 | 37 | 38 | 39 | EXCEPTION 40 | WHEN OTHERS THEN 41 | -- CALL THE FUNCTION TO LOG ERRORS 42 | ROLLBACK; 43 | P_RESULT := 1; -- ERROR 44 | END; 45 | / 46 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_SET_CONSUMER_ACC_TOKEN_TTL.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_SET_CONSUMER_ACC_TOKEN_TTL 2 | ( 3 | P_TOKEN IN VARCHAR2, 4 | P_TOKEN_TTL IN NUMBER, 5 | P_RESULT OUT NUMBER 6 | ) 7 | AS 8 | 9 | -- PROCEDURE TO Set the ttl of a consumer access token. This is done when the 10 | -- server receives a valid request with a xoauth_token_ttl parameter in it. 11 | 12 | BEGIN 13 | 14 | P_RESULT := 0; 15 | 16 | UPDATE OAUTH_SERVER_TOKEN 17 | SET OST_TOKEN_TTL = SYSDATE + (P_TOKEN_TTL/(24*60*60)) 18 | WHERE OST_TOKEN = P_TOKEN 19 | AND OST_TOKEN_TYPE = 'ACCESS'; 20 | 21 | 22 | EXCEPTION 23 | WHEN OTHERS THEN 24 | -- CALL THE FUNCTION TO LOG ERRORS 25 | ROLLBACK; 26 | P_RESULT := 1; -- ERROR 27 | END; 28 | / 29 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_SET_SERVER_TOKEN_TTL.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_SET_SERVER_TOKEN_TTL 2 | ( 3 | P_TOKEN_TTL IN NUMBER, -- IN SECOND 4 | P_CONSUMER_KEY IN VARCHAR2, 5 | P_TOKEN IN VARCHAR2, 6 | P_RESULT OUT NUMBER 7 | ) 8 | AS 9 | 10 | -- PROCEDURE TO Set the ttl of a server access token. 11 | 12 | BEGIN 13 | 14 | P_RESULT := 0; 15 | 16 | 17 | UPDATE OAUTH_CONSUMER_TOKEN 18 | SET OCT_TOKEN_TTL = SYSDATE + (P_TOKEN_TTL/(24*60*60)) -- DATE_ADD(NOW(), INTERVAL %D SECOND) 19 | WHERE OCT_TOKEN = P_TOKEN 20 | AND OCT_OCR_ID_REF IN (SELECT OCR_ID FROM OAUTH_CONSUMER_REGISTRY WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY); 21 | 22 | 23 | EXCEPTION 24 | WHEN OTHERS THEN 25 | -- CALL THE FUNCTION TO LOG ERRORS 26 | ROLLBACK; 27 | P_RESULT := 1; -- ERROR 28 | END; 29 | / 30 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_UPDATE_CONSUMER.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_UPDATE_CONSUMER 2 | ( 3 | P_OSR_USA_ID_REF IN NUMBER, 4 | P_OSR_CONSUMER_KEY IN VARCHAR2, 5 | P_OSR_CONSUMER_SECRET IN VARCHAR2, 6 | P_OSR_REQUESTER_NAME IN VARCHAR2, 7 | P_OSR_REQUESTER_EMAIL IN VARCHAR2, 8 | P_OSR_CALLBACK_URI IN VARCHAR2, 9 | P_OSR_APPLICATION_URI IN VARCHAR2, 10 | P_OSR_APPLICATION_TITLE IN VARCHAR2, 11 | P_OSR_APPLICATION_DESCR IN VARCHAR2, 12 | P_OSR_APPLICATION_NOTES IN VARCHAR2, 13 | P_OSR_APPLICATION_TYPE IN VARCHAR2, 14 | P_OSR_APPLICATION_COMMERCIAL IN INTEGER, 15 | P_RESULT OUT NUMBER 16 | ) 17 | AS 18 | 19 | -- PROCEDURE TO Insert a new consumer with this server (we will be the server) 20 | BEGIN 21 | P_RESULT := 0; 22 | 23 | 24 | INSERT INTO OAUTH_SERVER_REGISTRY 25 | ( OSR_ID, OSR_ENABLED, OSR_STATUS,OSR_USA_ID_REF,OSR_CONSUMER_KEY, OSR_CONSUMER_SECRET,OSR_REQUESTER_NAME, 26 | OSR_REQUESTER_EMAIL, OSR_CALLBACK_URI, OSR_APPLICATION_URI, OSR_APPLICATION_TITLE, OSR_APPLICATION_DESCR, 27 | OSR_APPLICATION_NOTES, OSR_APPLICATION_TYPE, OSR_APPLICATION_COMMERCIAL, OSR_TIMESTAMP, OSR_ISSUE_DATE) 28 | VALUES 29 | ( SEQ_OSR_ID.NEXTVAL, 1, 'ACTIVE', P_OSR_USA_ID_REF, P_OSR_CONSUMER_KEY, P_OSR_CONSUMER_SECRET,P_OSR_REQUESTER_NAME, 30 | P_OSR_REQUESTER_EMAIL, P_OSR_CALLBACK_URI, P_OSR_APPLICATION_URI, P_OSR_APPLICATION_TITLE, P_OSR_APPLICATION_DESCR, 31 | P_OSR_APPLICATION_NOTES, P_OSR_APPLICATION_TYPE, P_OSR_APPLICATION_COMMERCIAL, SYSDATE, SYSDATE); 32 | 33 | 34 | EXCEPTION 35 | WHEN OTHERS THEN 36 | -- CALL THE FUNCTION TO LOG ERRORS 37 | ROLLBACK; 38 | P_RESULT := 1; -- ERROR 39 | END; 40 | / 41 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/OracleDB/3_Procedures/SP_UPDATE_SERVER.prc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SP_UPDATE_SERVER 2 | ( 3 | P_CONSUMER_KEY IN VARCHAR2, 4 | P_USER_ID IN NUMBER, 5 | P_OCR_ID IN NUMBER, 6 | P_USER_IS_ADMIN IN NUMBER, -- 0:NO; 1:YES; 7 | P_OCR_CONSUMER_SECRET IN VARCHAR2, 8 | P_OCR_SERVER_URI IN VARCHAR2, 9 | P_OCR_SERVER_URI_HOST IN VARCHAR2, 10 | P_OCR_SERVER_URI_PATH IN VARCHAR2, 11 | P_OCR_REQUEST_TOKEN_URI IN VARCHAR2, 12 | P_OCR_AUTHORIZE_URI IN VARCHAR2, 13 | P_OCR_ACCESS_TOKEN_URI IN VARCHAR2, 14 | P_OCR_SIGNATURE_METHODS IN VARCHAR2, 15 | P_OCR_USA_ID_REF IN NUMBER, 16 | P_UPDATE_P_OCR_USA_ID_REF_FLAG IN NUMBER, -- 1:TRUE; 0:FALSE 17 | P_RESULT OUT NUMBER 18 | ) 19 | AS 20 | 21 | -- Add a request token we obtained from a server. 22 | V_OCR_ID_EXIST NUMBER; 23 | V_OCR_USA_ID_REF NUMBER; 24 | 25 | V_EXC_DUPLICATE_CONSUMER_KEY EXCEPTION; 26 | V_EXC_UNAUTHORISED_USER_ID EXCEPTION; 27 | BEGIN 28 | P_RESULT := 0; 29 | 30 | V_OCR_USA_ID_REF := P_OCR_USA_ID_REF; 31 | 32 | IF P_OCR_ID IS NOT NULL THEN 33 | BEGIN 34 | SELECT 1 INTO V_OCR_ID_EXIST FROM DUAL WHERE EXISTS 35 | (SELECT OCR_ID FROM OAUTH_CONSUMER_REGISTRY 36 | WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY 37 | AND OCR_ID != P_OCR_ID 38 | AND (OCR_USA_ID_REF = P_USER_ID OR OCR_USA_ID_REF IS NULL)); 39 | 40 | EXCEPTION 41 | WHEN NO_DATA_FOUND THEN 42 | V_OCR_ID_EXIST :=0; 43 | END; 44 | ELSE 45 | BEGIN 46 | SELECT 1 INTO V_OCR_ID_EXIST FROM DUAL WHERE EXISTS 47 | (SELECT OCR_ID FROM OAUTH_CONSUMER_REGISTRY 48 | WHERE OCR_CONSUMER_KEY = P_CONSUMER_KEY 49 | AND (OCR_USA_ID_REF = P_USER_ID OR OCR_USA_ID_REF IS NULL)); 50 | 51 | EXCEPTION 52 | WHEN NO_DATA_FOUND THEN 53 | V_OCR_ID_EXIST :=0; 54 | END; 55 | END IF; 56 | 57 | IF V_OCR_ID_EXIST = 1 THEN 58 | RAISE V_EXC_DUPLICATE_CONSUMER_KEY; 59 | END IF; 60 | 61 | 62 | IF P_OCR_ID IS NOT NULL THEN 63 | IF P_USER_IS_ADMIN != 1 THEN 64 | BEGIN 65 | SELECT OCR_USA_ID_REF INTO V_OCR_USA_ID_REF 66 | FROM OAUTH_CONSUMER_REGISTRY 67 | WHERE OCR_ID = P_OCR_ID; 68 | 69 | EXCEPTION 70 | WHEN NO_DATA_FOUND THEN 71 | NULL; 72 | END; 73 | 74 | IF V_OCR_USA_ID_REF != P_USER_ID THEN 75 | RAISE V_EXC_UNAUTHORISED_USER_ID; 76 | END IF; 77 | END IF; 78 | 79 | IF P_UPDATE_P_OCR_USA_ID_REF_FLAG = 0 THEN 80 | 81 | UPDATE OAUTH_CONSUMER_REGISTRY 82 | SET OCR_CONSUMER_KEY = P_CONSUMER_KEY, 83 | OCR_CONSUMER_SECRET = P_OCR_CONSUMER_SECRET, 84 | OCR_SERVER_URI = P_OCR_SERVER_URI, 85 | OCR_SERVER_URI_HOST = P_OCR_SERVER_URI_HOST, 86 | OCR_SERVER_URI_PATH = P_OCR_SERVER_URI_PATH, 87 | OCR_TIMESTAMP = SYSDATE, 88 | OCR_REQUEST_TOKEN_URI = P_OCR_REQUEST_TOKEN_URI, 89 | OCR_AUTHORIZE_URI = P_OCR_AUTHORIZE_URI, 90 | OCR_ACCESS_TOKEN_URI = P_OCR_ACCESS_TOKEN_URI, 91 | OCR_SIGNATURE_METHODS = P_OCR_SIGNATURE_METHODS 92 | WHERE OCR_ID = P_OCR_ID; 93 | 94 | ELSIF P_UPDATE_P_OCR_USA_ID_REF_FLAG = 1 THEN 95 | UPDATE OAUTH_CONSUMER_REGISTRY 96 | SET OCR_CONSUMER_KEY = P_CONSUMER_KEY, 97 | OCR_CONSUMER_SECRET = P_OCR_CONSUMER_SECRET, 98 | OCR_SERVER_URI = P_OCR_SERVER_URI, 99 | OCR_SERVER_URI_HOST = P_OCR_SERVER_URI_HOST, 100 | OCR_SERVER_URI_PATH = P_OCR_SERVER_URI_PATH, 101 | OCR_TIMESTAMP = SYSDATE, 102 | OCR_REQUEST_TOKEN_URI = P_OCR_REQUEST_TOKEN_URI, 103 | OCR_AUTHORIZE_URI = P_OCR_AUTHORIZE_URI, 104 | OCR_ACCESS_TOKEN_URI = P_OCR_ACCESS_TOKEN_URI, 105 | OCR_SIGNATURE_METHODS = P_OCR_SIGNATURE_METHODS, 106 | OCR_USA_ID_REF = P_OCR_USA_ID_REF 107 | WHERE OCR_ID = P_OCR_ID; 108 | 109 | END IF; 110 | 111 | ELSE 112 | IF P_UPDATE_P_OCR_USA_ID_REF_FLAG = 0 THEN 113 | V_OCR_USA_ID_REF := P_USER_ID; 114 | END IF; 115 | 116 | INSERT INTO OAUTH_CONSUMER_REGISTRY 117 | (OCR_ID, OCR_CONSUMER_KEY ,OCR_CONSUMER_SECRET, OCR_SERVER_URI, OCR_SERVER_URI_HOST, OCR_SERVER_URI_PATH, 118 | OCR_TIMESTAMP, OCR_REQUEST_TOKEN_URI, OCR_AUTHORIZE_URI, OCR_ACCESS_TOKEN_URI, OCR_SIGNATURE_METHODS, 119 | OCR_USA_ID_REF) 120 | VALUES 121 | (SEQ_OCR_ID.NEXTVAL, P_CONSUMER_KEY, P_OCR_CONSUMER_SECRET, P_OCR_SERVER_URI, P_OCR_SERVER_URI_HOST, P_OCR_SERVER_URI_PATH, 122 | SYSDATE, P_OCR_REQUEST_TOKEN_URI, P_OCR_AUTHORIZE_URI, P_OCR_ACCESS_TOKEN_URI, P_OCR_SIGNATURE_METHODS, 123 | V_OCR_USA_ID_REF); 124 | 125 | END IF; 126 | 127 | 128 | EXCEPTION 129 | WHEN V_EXC_DUPLICATE_CONSUMER_KEY THEN 130 | P_RESULT := 2; -- DUPLICATE_CONSUMER_KEY 131 | WHEN V_EXC_UNAUTHORISED_USER_ID THEN 132 | P_RESULT := 3; -- UNAUTHORISED_USER_ID 133 | 134 | WHEN OTHERS THEN 135 | -- CALL THE FUNCTION TO LOG ERRORS 136 | ROLLBACK; 137 | P_RESULT := 1; -- ERROR 138 | END; 139 | / 140 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/oracle/install.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/oauth-php/library/store/postgresql/pgsql.sql: -------------------------------------------------------------------------------- 1 | # 2 | # Log table to hold all OAuth request when you enabled logging 3 | # 4 | 5 | CREATE TABLE oauth_log ( 6 | olg_id serial primary key, 7 | olg_osr_consumer_key varchar(64), 8 | olg_ost_token varchar(64), 9 | olg_ocr_consumer_key varchar(64), 10 | olg_oct_token varchar(64), 11 | olg_usa_id_ref text, 12 | olg_received text not null, 13 | olg_sent text not null, 14 | olg_base_string text not null, 15 | olg_notes text not null, 16 | olg_timestamp timestamp not null default current_timestamp, 17 | olg_remote_ip inet not null 18 | ); 19 | 20 | COMMENT ON TABLE oauth_log IS 'Log table to hold all OAuth request when you enabled logging'; 21 | 22 | 23 | # 24 | # /////////////////// CONSUMER SIDE /////////////////// 25 | # 26 | 27 | # This is a registry of all consumer codes we got from other servers 28 | # The consumer_key/secret is obtained from the server 29 | # We also register the server uri, so that we can find the consumer key and secret 30 | # for a certain server. From that server we can check if we have a token for a 31 | # particular user. 32 | 33 | CREATE TABLE oauth_consumer_registry ( 34 | ocr_id serial primary key, 35 | ocr_usa_id_ref text, 36 | ocr_consumer_key varchar(128) not null, 37 | ocr_consumer_secret varchar(128) not null, 38 | ocr_signature_methods varchar(255) not null default 'HMAC-SHA1,PLAINTEXT', 39 | ocr_server_uri varchar(255) not null, 40 | ocr_server_uri_host varchar(128) not null, 41 | ocr_server_uri_path varchar(128) not null, 42 | 43 | ocr_request_token_uri varchar(255) not null, 44 | ocr_authorize_uri varchar(255) not null, 45 | ocr_access_token_uri varchar(255) not null, 46 | ocr_timestamp timestamp not null default current_timestamp, 47 | 48 | unique (ocr_consumer_key, ocr_usa_id_ref, ocr_server_uri) 49 | ); 50 | 51 | COMMENT ON TABLE oauth_consumer_registry IS 'This is a registry of all consumer codes we got from other servers'; 52 | 53 | # Table used to sign requests for sending to a server by the consumer 54 | # The key is defined for a particular user. Only one single named 55 | # key is allowed per user/server combination 56 | 57 | -- Create enum type token_type 58 | CREATE TYPE consumer_token_type AS ENUM ( 59 | 'request', 60 | 'authorized', 61 | 'access' 62 | ); 63 | 64 | CREATE TABLE oauth_consumer_token ( 65 | oct_id serial primary key, 66 | oct_ocr_id_ref integer not null, 67 | oct_usa_id_ref text not null, 68 | oct_name varchar(64) not null default '', 69 | oct_token varchar(64) not null, 70 | oct_token_secret varchar(64) not null, 71 | oct_token_type consumer_token_type, 72 | oct_token_ttl timestamp not null default timestamp '9999-12-31', 73 | oct_timestamp timestamp not null default current_timestamp, 74 | 75 | unique (oct_ocr_id_ref, oct_token), 76 | unique (oct_usa_id_ref, oct_ocr_id_ref, oct_token_type, oct_name), 77 | 78 | foreign key (oct_ocr_id_ref) references oauth_consumer_registry (ocr_id) 79 | on update cascade 80 | on delete cascade 81 | ); 82 | 83 | 84 | COMMENT ON TABLE oauth_consumer_token IS 'Table used to sign requests for sending to a server by the consumer'; 85 | 86 | # 87 | # ////////////////// SERVER SIDE ///////////////// 88 | # 89 | 90 | # Table holding consumer key/secret combos an user issued to consumers. 91 | # Used for verification of incoming requests. 92 | 93 | CREATE TABLE oauth_server_registry ( 94 | osr_id serial primary key, 95 | osr_usa_id_ref text, 96 | osr_consumer_key varchar(64) not null, 97 | osr_consumer_secret varchar(64) not null, 98 | osr_enabled boolean not null default true, 99 | osr_status varchar(16) not null, 100 | osr_requester_name varchar(64) not null, 101 | osr_requester_email varchar(64) not null, 102 | osr_callback_uri varchar(255) not null, 103 | osr_application_uri varchar(255) not null, 104 | osr_application_title varchar(80) not null, 105 | osr_application_descr text not null, 106 | osr_application_notes text not null, 107 | osr_application_type varchar(20) not null, 108 | osr_application_commercial boolean not null default false, 109 | osr_issue_date timestamp not null, 110 | osr_timestamp timestamp not null default current_timestamp, 111 | 112 | unique (osr_consumer_key) 113 | ); 114 | 115 | 116 | COMMENT ON TABLE oauth_server_registry IS 'Table holding consumer key/secret combos an user issued to consumers'; 117 | 118 | # Nonce used by a certain consumer, every used nonce should be unique, this prevents 119 | # replaying attacks. We need to store all timestamp/nonce combinations for the 120 | # maximum timestamp received. 121 | 122 | CREATE TABLE oauth_server_nonce ( 123 | osn_id serial primary key, 124 | osn_consumer_key varchar(64) not null, 125 | osn_token varchar(64) not null, 126 | osn_timestamp bigint not null, 127 | osn_nonce varchar(80) not null, 128 | 129 | unique (osn_consumer_key, osn_token, osn_timestamp, osn_nonce) 130 | ); 131 | 132 | 133 | COMMENT ON TABLE oauth_server_nonce IS 'Nonce used by a certain consumer, every used nonce should be unique, this prevents replaying attacks'; 134 | 135 | # Table used to verify signed requests sent to a server by the consumer 136 | # When the verification is succesful then the associated user id is returned. 137 | 138 | -- Create enum type token_type 139 | CREATE TYPE server_token_type AS ENUM ( 140 | 'request', 141 | 'access' 142 | ); 143 | 144 | CREATE TABLE oauth_server_token ( 145 | ost_id serial primary key, 146 | ost_osr_id_ref integer not null, 147 | ost_usa_id_ref text not null, 148 | ost_token varchar(64) not null, 149 | ost_token_secret varchar(64) not null, 150 | ost_token_type server_token_type, 151 | ost_authorized boolean not null default false, 152 | ost_referrer_host varchar(128) not null default '', 153 | ost_token_ttl timestamp not null default timestamp '9999-12-31', 154 | ost_timestamp timestamp not null default current_timestamp, 155 | ost_verifier char(10), 156 | ost_callback_url varchar(512), 157 | 158 | unique (ost_token), 159 | 160 | foreign key (ost_osr_id_ref) references oauth_server_registry (osr_id) 161 | on update cascade 162 | on delete cascade 163 | ); 164 | 165 | 166 | COMMENT ON TABLE oauth_server_token IS 'Table used to verify signed requests sent to a server by the consumer'; 167 | -------------------------------------------------------------------------------- /lib/oauth-php/test/discovery/xrds-fireeagle.xrds: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | xri://$xrds*simple 8 | 2008-04-15T00:25:30-07:00 9 | 10 | 11 | 12 | http://oauth.net/core/1.0/endpoint/request 13 | 14 | http://oauth.net/core/1.0/parameters/auth-header 15 | http://oauth.net/core/1.0/parameters/post-body 16 | http://oauth.net/core/1.0/parameters/uri-query 17 | http://oauth.net/core/1.0/signature/HMAC-SHA1 18 | http://oauth.net/core/1.0/signature/PLAINTEXT 19 | 20 | https://fireeagle.yahooapis.com/oauth/request_token 21 | 22 | 23 | 24 | 25 | http://oauth.net/core/1.0/endpoint/authorize 26 | 27 | http://oauth.net/core/1.0/parameters/auth-header 28 | http://oauth.net/core/1.0/parameters/uri-query 29 | 30 | https://fireeagle.yahooapis.com/oauth/access_token 31 | 32 | 33 | 34 | 35 | http://oauth.net/core/1.0/endpoint/access 36 | 37 | http://oauth.net/core/1.0/parameters/auth-header 38 | http://oauth.net/core/1.0/parameters/post-body 39 | http://oauth.net/core/1.0/parameters/uri-query 40 | http://oauth.net/core/1.0/signature/HMAC-SHA1 41 | http://oauth.net/core/1.0/signature/PLAINTEXT 42 | 43 | http://fireeagle.yahoo.net/oauth/authorize 44 | 45 | 46 | 47 | 48 | http://oauth.net/core/1.0/endpoint/resource 49 | 50 | http://oauth.net/core/1.0/parameters/auth-header 51 | http://oauth.net/core/1.0/parameters/post-body 52 | http://oauth.net/core/1.0/parameters/uri-query 53 | http://oauth.net/core/1.0/signature/HMAC-SHA1 54 | http://oauth.net/core/1.0/signature/PLAINTEXT 55 | 56 | 57 | 58 | 59 | 60 | 61 | http://oauth.net/discovery/1.0/consumer-identity/oob 62 | https://fireeagle.yahoo.net/developer/create 63 | 64 | 65 | 66 | 67 | 68 | 69 | xri://$xrds*simple 70 | 71 | 72 | 73 | http://oauth.net/discovery/1.0 74 | #oauth 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /lib/oauth-php/test/discovery/xrds-getsatisfaction.xrds: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | xri://$xrds*simple 6 | 2008-04-30T23:59:59Z 7 | 8 | 9 | 10 | http://oauth.net/core/1.0/endpoint/request 11 | 12 | http://oauth.net/core/1.0/parameters/auth-header 13 | http://oauth.net/core/1.0/signature/HMAC-SHA1 14 | 15 | http://getsatisfaction.com/api/request_token 16 | 17 | 18 | 19 | http://oauth.net/core/1.0/endpoint/authorize 20 | 21 | http://oauth.net/core/1.0/parameters/uri-query 22 | 23 | http://getsatisfaction.com/api/authorize 24 | 25 | 26 | 27 | 28 | http://oauth.net/core/1.0/endpoint/access 29 | 30 | http://oauth.net/core/1.0/parameters/auth-header 31 | http://oauth.net/core/1.0/signature/HMAC-SHA1 32 | 33 | http://getsatisfaction.com/api/access_token 34 | 35 | 36 | 37 | 45 | 46 | http://oauth.net/core/1.0/endpoint/resource 47 | 48 | http://oauth.net/core/1.0/parameters/auth-header 49 | http://oauth.net/core/1.0/signature/HMAC-SHA1 50 | 51 | 52 | 53 | 54 | 55 | 56 | http://oauth.net/discovery/1.0/consumer-identity/oob 57 | http://getsatisfaction.com/me/extensions/new 58 | 59 | 60 | 61 | 62 | 63 | 64 | xri://$xrds*simple 65 | 66 | 67 | 68 | http://oauth.net/discovery/1.0 69 | #oauth 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /lib/oauth-php/test/discovery/xrds-magnolia.xrds: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | xri://$xrds*simple 8 | 2008-04-13T07:34:58Z 9 | 10 | 11 | 12 | http://oauth.net/core/1.0/endpoint/request 13 | 14 | http://oauth.net/core/1.0/parameters/auth-header 15 | http://oauth.net/core/1.0/parameters/post-body 16 | http://oauth.net/core/1.0/parameters/uri-query 17 | http://oauth.net/core/1.0/signature/HMAC-SHA1 18 | http://oauth.net/core/1.0/signature/RSA-SHA1 19 | http://oauth.net/core/1.0/signature/PLAINTEXT 20 | 21 | https://ma.gnolia.com/oauth/get_request_token 22 | 23 | 24 | 25 | 26 | http://oauth.net/core/1.0/endpoint/authorize 27 | 28 | http://oauth.net/core/1.0/parameters/auth-header 29 | http://oauth.net/core/1.0/parameters/uri-query 30 | 31 | https://ma.gnolia.com/oauth/authorize 32 | http://ma.gnolia.com/oauth/authorize 33 | 34 | 35 | 36 | 37 | http://oauth.net/core/1.0/endpoint/access 38 | 39 | http://oauth.net/core/1.0/parameters/auth-header 40 | http://oauth.net/core/1.0/parameters/post-body 41 | http://oauth.net/core/1.0/parameters/uri-query 42 | http://oauth.net/core/1.0/signature/HMAC-SHA1 43 | http://oauth.net/core/1.0/signature/RSA-SHA1 44 | http://oauth.net/core/1.0/signature/PLAINTEXT 45 | 46 | https://ma.gnolia.com/oauth/get_access_token 47 | 48 | 49 | 50 | 51 | http://oauth.net/core/1.0/endpoint/resource 52 | 53 | http://oauth.net/core/1.0/parameters/auth-header 54 | http://oauth.net/core/1.0/parameters/post-body 55 | http://oauth.net/core/1.0/parameters/uri-query 56 | http://oauth.net/core/1.0/signature/HMAC-SHA1 57 | http://oauth.net/core/1.0/signature/RSA-SHA1 58 | 59 | 60 | 61 | 62 | 63 | 64 | http://oauth.net/discovery/1.0/consumer-identity/oob 65 | http://ma.gnolia.com/applications/new 66 | 67 | 68 | 69 | 70 | 71 | 72 | xri://$xrds*simple 73 | 74 | 75 | 76 | http://oauth.net/discovery/1.0 77 | #oauth 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /lib/oauth-php/test/oauth_test.php: -------------------------------------------------------------------------------- 1 | 8 | * @date Nov 29, 2007 3:46:56 PM 9 | * @see http://wiki.oauth.net/TestCases 10 | * 11 | * The MIT License 12 | * 13 | * Copyright (c) 2007-2008 Mediamatic Lab 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | */ 33 | 34 | require_once dirname(__FILE__) . '/../library/OAuthRequest.php'; 35 | require_once dirname(__FILE__) . '/../library/OAuthRequester.php'; 36 | require_once dirname(__FILE__) . '/../library/OAuthRequestSigner.php'; 37 | require_once dirname(__FILE__) . '/../library/OAuthRequestVerifier.php'; 38 | 39 | if (!function_exists('getallheaders')) 40 | { 41 | function getallheaders() 42 | { 43 | return array(); 44 | } 45 | } 46 | 47 | 48 | oauth_test(); 49 | 50 | function oauth_test () 51 | { 52 | error_reporting(E_ALL); 53 | 54 | header('Content-Type: text/plain; charset=utf-8'); 55 | 56 | echo "Performing OAuth module tests.\n\n"; 57 | echo "See also: http://wiki.oauth.net/TestCases\n\n"; 58 | 59 | assert_options(ASSERT_CALLBACK, 'oauth_assert_handler'); 60 | assert_options(ASSERT_WARNING, 0); 61 | 62 | $req = new OAuthRequest('http://www.example.com', 'GET'); 63 | 64 | echo "***** Parameter Encoding *****\n\n"; 65 | 66 | assert('$req->urlencode(\'abcABC123\') == \'abcABC123\''); 67 | assert('$req->urlencode(\'-._~\') == \'-._~\''); 68 | assert('$req->urlencode(\'%\') == \'%25\''); 69 | assert('$req->urlencode(\'&=*\') == \'%26%3D%2A\''); 70 | assert('$req->urlencode(\'&=*\') == \'%26%3D%2A\''); 71 | assert('$req->urlencode("\n") == \'%0A\''); 72 | assert('$req->urlencode(" ") == \'%20\''); 73 | assert('$req->urlencode("\x7f") == \'%7F\''); 74 | 75 | 76 | echo "***** Normalize Request Parameters *****\n\n"; 77 | 78 | $req = new OAuthRequest('http://example.com/?name', 'GET'); 79 | assert('$req->getNormalizedParams() == \'name=\''); 80 | 81 | $req = new OAuthRequest('http://example.com/?a=b', 'GET'); 82 | assert('$req->getNormalizedParams() == \'a=b\''); 83 | 84 | $req = new OAuthRequest('http://example.com/?a=b&c=d', 'GET'); 85 | assert('$req->getNormalizedParams() == \'a=b&c=d\''); 86 | 87 | // At this moment we don't support two parameters with the same name 88 | // so I changed this test case to "a=" and "b=" and not "a=" and "a=" 89 | $req = new OAuthRequest('http://example.com/?b=x!y&a=x+y', 'GET'); 90 | assert('$req->getNormalizedParams() == \'a=x%2By&b=x%21y\''); 91 | 92 | $req = new OAuthRequest('http://example.com/?x!y=a&x=a', 'GET'); 93 | assert('$req->getNormalizedParams() == \'x=a&x%21y=a\''); 94 | 95 | 96 | echo "***** Base String *****\n\n"; 97 | 98 | $req = new OAuthRequest('http://example.com/?n=v', 'GET'); 99 | assert('$req->signatureBaseString() == \'GET&http%3A%2F%2Fexample.com%2F&n%3Dv\''); 100 | 101 | $req = new OAuthRequest( 102 | 'https://photos.example.net/request_token', 103 | 'POST', 104 | 'oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_timestamp=1191242090&oauth_nonce=hsu94j3884jdopsl&oauth_signature_method=PLAINTEXT&oauth_signature=ignored', 105 | array('X-OAuth-Test' => true)); 106 | assert('$req->signatureBaseString() == \'POST&https%3A%2F%2Fphotos.example.net%2Frequest_token&oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dhsu94j3884jdopsl%26oauth_signature_method%3DPLAINTEXT%26oauth_timestamp%3D1191242090%26oauth_version%3D1.0\''); 107 | 108 | $req = new OAuthRequest( 109 | 'http://photos.example.net/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature=ignored&oauth_signature_method=HMAC-SHA1', 110 | 'GET'); 111 | assert('$req->signatureBaseString() == \'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal\''); 112 | 113 | 114 | echo "***** HMAC-SHA1 *****\nRequest signing\n"; 115 | 116 | OAuthStore::instance('MySQL', array('conn'=>false)); 117 | $req = new OAuthRequestSigner('http://photos.example.net/photos?file=vacation.jpg&size=original', 'GET'); 118 | 119 | assert('$req->urldecode($req->calculateDataSignature(\'bs\', \'cs\', \'\', \'HMAC-SHA1\')) == \'egQqG5AJep5sJ7anhXju1unge2I=\''); 120 | assert('$req->urldecode($req->calculateDataSignature(\'bs\', \'cs\', \'ts\', \'HMAC-SHA1\')) == \'VZVjXceV7JgPq/dOTnNmEfO0Fv8=\''); 121 | 122 | $secrets = array( 123 | 'consumer_key' => 'dpf43f3p2l4k3l03', 124 | 'consumer_secret' => 'kd94hf93k423kf44', 125 | 'token' => 'nnch734d00sl2jdk', 126 | 'token_secret' => 'pfkkdhi9sl3r4s00', 127 | 'signature_methods' => array('HMAC-SHA1'), 128 | 'nonce' => 'kllo9940pd9333jh', 129 | 'timestamp' => '1191242096' 130 | ); 131 | $req->sign(0, $secrets); 132 | assert('$req->getParam(\'oauth_signature\', true) == \'tR3+Ty81lMeYAr/Fid0kMTYa/WM=\''); 133 | 134 | echo "***** HMAC-SHA1 *****\nRequest verification\n"; 135 | 136 | $req = new OAuthRequestVerifier( 137 | 'http://photos.example.net/photos?file=vacation.jpg&size=original' 138 | .'&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk' 139 | .'&oauth_signature_method=HMAC-SHA1&oauth_nonce=kllo9940pd9333jh' 140 | .'&oauth_timestamp=1191242096&oauth_version=1.0' 141 | .'&oauth_signature='.rawurlencode('tR3+Ty81lMeYAr/Fid0kMTYa/WM=') 142 | , 'GET'); 143 | 144 | $req->verifySignature('kd94hf93k423kf44', 'pfkkdhi9sl3r4s00'); 145 | 146 | echo "\n"; 147 | echo "***** Yahoo! test case ******\n\n"; 148 | 149 | OAuthStore::instance('MySQL', array('conn'=>false)); 150 | $req = new OAuthRequestSigner('http://example.com:80/photo', 'GET'); 151 | 152 | $req->setParam('title', 'taken with a 30% orange filter'); 153 | $req->setParam('file', 'mountain & water view'); 154 | $req->setParam('format', 'jpeg'); 155 | $req->setParam('include', array('date','aperture')); 156 | 157 | $secrets = array( 158 | 'consumer_key' => '1234=asdf=4567', 159 | 'consumer_secret' => 'erks823*43=asd&123ls%23', 160 | 'token' => 'asdf-4354=asew-5698', 161 | 'token_secret' => 'dis9$#$Js009%==', 162 | 'signature_methods' => array('HMAC-SHA1'), 163 | 'nonce' => '3jd834jd9', 164 | 'timestamp' => '12303202302' 165 | ); 166 | $req->sign(0, $secrets); 167 | 168 | // echo "Basestring:\n",$req->signatureBaseString(), "\n\n"; 169 | 170 | //echo "queryString:\n",$req->getQueryString(), "\n\n"; 171 | assert('$req->getQueryString() == \'title=taken%20with%20a%2030%25%20orange%20filter&file=mountain%20%26%20water%20view&format=jpeg&include=date&include=aperture\''); 172 | 173 | //echo "oauth_signature:\n",$req->getParam('oauth_signature', true),"\n\n"; 174 | assert('$req->getParam(\'oauth_signature\', true) == \'jMdUSR1vOr3SzNv3gZ5DDDuGirA=\''); 175 | 176 | echo "\n\nFinished.\n"; 177 | } 178 | 179 | 180 | function oauth_assert_handler ( $file, $line, $code ) 181 | { 182 | echo "\nAssertion failed in $file:$line 183 | $code\n\n"; 184 | } 185 | 186 | /* vi:set ts=4 sts=4 sw=4 binary noeol: */ 187 | 188 | ?> -------------------------------------------------------------------------------- /test.php: -------------------------------------------------------------------------------- 1 | products_field("cat_id", 4992); 17 | $requestor->products_field("brand", "Toshiba"); 18 | $requestor->products_field("name", "Portege"); 19 | 20 | $requestor->products_field("sitedetails", "name", "amazon.com"); 21 | $requestor->sitedetails("latestoffers", "price", "gte", 100); 22 | $requestor->sitedetails("latestoffers", "currency", "USD"); 23 | 24 | $requestor->products_field("weight", "gte", 1000000); 25 | $requestor->products_field("weight", "lt", 1500000); 26 | 27 | $requestor->products_field("sort", "name", "desc"); 28 | 29 | echo $requestor->get_products()."\n"; 30 | $requestor->clear_query(); 31 | 32 | /** 33 | * Sem3_ID Array Query 34 | * 35 | */ 36 | $requestor->products_field("sem3_id", array("2NnNAztqoGeoQGeSya0y4K", "0xzFQX9Ss8ecMwkMy0C8Ui", "1XgtmTtMgWswmYaGS6Kgyc") ); 37 | 38 | echo $requestor->get_products()."\n"; 39 | $requestor->clear_query(); 40 | 41 | /** 42 | * Category Query 43 | * 44 | */ 45 | $requestor->categories_field("name", "hard drives"); 46 | 47 | echo $requestor->get_categories()."\n"; 48 | $requestor->clear_query(); 49 | 50 | 51 | 52 | echo "OK!\n"; --------------------------------------------------------------------------------