function getResponseAPI($userIdZyncro, $sessionid, $serviceAPI) { // Init the OAuthStore $options = array('consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET, 'server_uri' => OAUTH_HOST, 'request_token_uri' => REQUEST_TOKEN_URL, 'signature_methods' => array('HMAC-SHA1'), 'authorize_uri' => AUTHORIZE_URL, 'access_token_uri' => ACCESS_TOKEN_URL); // Note: do not use "Session" storage in production. Prefer a database // storage, such as MySQL. OAuthStore::instance("Session", $options); try { // get a request token $getRequestTokenParams = array(); $tokenResultParams = OAuthRequester::requestRequestToken(CONSUMER_KEY, 0, $getRequestTokenParams, 'GET'); // get an access token $oauthToken = $tokenResultParams['token']; $getAccessTokenParams = array('oauth_verifier' => $sessionid); OAuthRequester::requestAccessToken(CONSUMER_KEY, $oauthToken, 0, 'POST', $getAccessTokenParams); // make the request. $urlRequest = OAUTH_HOST . $serviceAPI; $request = new OAuthRequester($urlRequest, 'GET'); $result = $request->doRequest(0); if ($result['code'] == 200) { return $result['body']; } } catch (OAuthException2 $e) { } }
function TPSession() { // define the DB store. if (!$this->store) { $this->store = OAuthStore::instance('MySQL', get_db_options()); } // determine who this user is (from this site's cookie alone) $this->user_id = get_user_id(COOKIE_NAME); debug("[TPSession::TPSesssion], user_id = " . $this->user_id); // If there's no user_id in the cookie, then there's no session -- not logged in. if (!$this->user_id) { return 0; } // This method look up the OAuth token in one of two ways: // 1. the _GET parameters -- if this is the last step of the OAuth dance. // 2. the Database -- if the user already completed the OAuth dance. $this->oauth_token = get_oauth_token(COOKIE_NAME, $_GET, $this->store); // debug ("OAUTH TOKEN = " . $this->oauth_token); // Somebody wanted to log out! You should let them. if (array_key_exists('logout', $_GET)) { $this->log_out(); } else { if (array_key_exists('oauth_verifier', $_GET)) { $this->verify_access_token(); } } // Also update the local author record if all goes well... if (!$this->author and $this->is_logged_in()) { $this->update_author_record(); } }
/** * Authenticate - Asks permission to a user to authorize the application * * @param string $consumerKey Access key * @param string $secretKey Secret key * @param integer $userId A user identificator * @param string $callbackUri This url will be called to finish authorization * @return void */ public function authenticate($consumerKey, $consumerSecret, $userId, $callbackUri) { // Save the server in the the OAuthStore $store = OAuthStore::instance(); try { // Create the server $server = array('consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret, 'server_uri' => $this->serverUrl . '/a1/', 'signature_methods' => array('HMAC-SHA1', 'PLAINTEXT'), 'request_token_uri' => $this->serverUrl . '/oauth/request_token', 'authorize_uri' => $this->serverUrl . '/oauth/authorize', 'access_token_uri' => $this->serverUrl . '/oauth/access_token'); $consumer_key = $store->updateServer($server, $userId); } catch (Exception $e) { //throw new BadRequestException($e->getMessage()); } $token = OAuthRequester::requestRequestToken($consumerKey, $userId); // Callback to our (consumer) site, will be called when the user finished the authorization at the server $callback_uri = "{$callbackUri}?consumer_key=" . rawurlencode($consumerKey) . '&usr_id=' . intval($userId); // Now redirect to the autorization uri and get us authorized if (!empty($token['authorize_uri'])) { // Redirect to the server, add a callback to our server if (strpos($token['authorize_uri'], '?')) { $uri = $token['authorize_uri'] . '&'; } else { $uri = $token['authorize_uri'] . '?'; } $uri .= 'oauth_token=' . rawurlencode($token['token']) . '&oauth_callback=' . rawurlencode($callback_uri); } else { // No authorization uri, assume we are authorized, exchange request token for access token $uri = $callback_uri . '&oauth_token=' . rawurlencode($token['token']); } Header("Location: {$uri}"); die; }
public function __construct($serviceName, $oAuthAPIRootURL, $oAuthConsumerKey, $oAuthConsumerSecret, $oAuthRequestTokenURL, $oAuthAccessTokenURL, $oAuthAuthorizeURL, $oAuthSignatureMethods, $oAuthScope, $signUpButtonURL = null, $logInButtonURL = null, $connectButtonURL = null, $activities = null) { parent::__construct(); $this->serviceName = $serviceName; $this->oAuthAPIRootURL = $oAuthAPIRootURL; $this->oAuthConsumerKey = $oAuthConsumerKey; $this->oAuthConsumerSecret = $oAuthConsumerSecret; $this->oAuthRequestTokenURL = $oAuthRequestTokenURL; $this->oAuthAccessTokenURL = $oAuthAccessTokenURL; $this->oAuthAuthorizeURL = $oAuthAuthorizeURL; $this->oAuthSignatureMethods = $oAuthSignatureMethods; $this->oAuthScope = $oAuthScope; $this->signUpButtonURL = $signUpButtonURL; $this->logInButtonURL = $logInButtonURL; $this->connectButtonURL = $connectButtonURL; if (!is_null($activities)) { $this->USERBASE_ACTIVITY_OAUTH_MODULE_LOGIN = $activities[0][0]; $this->USERBASE_ACTIVITY_OAUTH_MODULE_ADDED = $activities[1][0]; $this->USERBASE_ACTIVITY_OAUTH_MODULE_REMOVED = $activities[2][0]; $this->USERBASE_ACTIVITY_OAUTH_MODULE_REGISTER = $activities[3][0]; UserConfig::$activities[$activities[0][0]] = array($activities[0][1], $activities[0][2]); UserConfig::$activities[$activities[1][0]] = array($activities[1][1], $activities[1][2]); UserConfig::$activities[$activities[2][0]] = array($activities[2][1], $activities[2][2]); UserConfig::$activities[$activities[3][0]] = array($activities[3][1], $activities[3][2]); } $this->oAuthStore = OAuthStore::instance('MySQLi', array('conn' => UserConfig::getDB(), 'table_prefix' => UserConfig::$mysql_prefix)); }
/** * Request an instance of the OAuthStore */ public static function instance($store = 'MySQL', $options = array()) { if (!OAuthStore::$instance) { // Select the store you want to use if (strpos($store, '/') === false) { $class = 'OAuthStore' . $store; $file = dirname(__FILE__) . '/store/' . $class . '.php'; } else { $file = $store; $store = basename($file, '.php'); $class = $store; } if (is_file($file)) { require_once $file; if (class_exists($class)) { OAuthStore::$instance = new $class($options); } else { throw new OAuthException2('Could not find class ' . $class . ' in file ' . $file); } } else { throw new OAuthException2('No OAuthStore for ' . $store . ' (file ' . $file . ')'); } } return OAuthStore::$instance; }
/** * **/ public function authorize_action() { global $user, $auth; $auth->login_if($user->id == 'nobody'); $user_id = OAuthUser::getMappedId($user->id); // Fetch the oauth store and the oauth server. $store = OAuthStore::instance(); $server = new OAuthServer(); try { // Check if there is a valid request token in the current request // Returns an array with the consumer key, consumer secret, token, token secret and token type. $rs = $server->authorizeVerify(); if (isset($_POST['allow'])) { // See if the user clicked the 'allow' submit button (or whatever you choose) $authorized = array_key_exists('allow', $_POST); // Set the request token to be authorized or not authorized // When there was a oauth_callback then this will redirect to the consumer $server->authorizeFinish($authorized, $user_id); // No oauth_callback, show the user the result of the authorization // ** your code here ** PageLayout::postMessage(Messagebox::success(_('Sie haben der Applikation Zugriff auf Ihre Daten gewährt.'))); $this->redirect('user#' . $rs['consumer_key']); } } catch (OAuthException $e) { // No token to be verified in the request, show a page where the user can enter the token to be verified // **your code here** die('invalid'); } PageLayout::disableHeader(); $this->set_layout($GLOBALS['template_factory']->open('layouts/base_without_infobox')); $this->rs = $rs; }
public function run_query($endpoint, $params, $method = "GET") { if (!$this->apiKey) { throw new Semantics3_AuthenticationError('No API key provided.'); } if (!$this->apiSecret) { throw new Semantics3_AuthenticationError('No API secret provided.'); } $options = array('consumer_key' => $this->apiKey, 'consumer_secret' => $this->apiSecret); OAuthStore::instance("2Leg", $options); $url = $this->apiBase . $endpoint; if ($method == "GET") { $url = $url . "?q=" . urlencode(json_encode($params)); $params = null; } else { $params = json_encode($params); } if (!$this->catchExceptions) { return $this->getOAuthRequester($method, $url, $params); } try { return $this->getOAuthRequester($method, $url, $params); } catch (OAuthException2 $e) { print "\n"; $error = $e->getMessage(); print $error . "\n"; } }
/** * Creates a new instance of OsmOAuth. * * @param string $key The consumer key. * @param string $secret The consumer secret. * @param boolean $unitTest Determines wheter this call is made from a unit test or not. */ public function __construct($key, $secret, $unitTest = false) { $this->key = $key; $this->secret = $secret; if (!$unitTest) { \OAuthStore::instance("Session", $this->getOauthOptions()); } }
function grant_access_token_to_consumer($consumer_key, $user_id) { $store = OAuthStore::instance(); $token_info = $store->addConsumerRequestToken($consumer_key); $store->authorizeConsumerRequestToken($token_info['token'], $user_id); $token_and_secret = $store->exchangeConsumerRequestForAccessToken($token_info['token']); return $token_and_secret; }
public function setinstance() { $registry = Zend_Registry::getInstance(); $config = $registry->get("config"); $db = $config['resources']['db']['params']; require_once EXTERNAL_LIBRARY_PATH . '/oauth-php/library/OAuthStore.php'; OAuthStore::instance("MySQL", array("server" => $db['host'], "database" => $db['dbname'], "username" => $db['username'], "password" => $db['password'])); }
public function listapiserversAction() { $service = new Ml_Model_Service(); $userId = $service->getInput("User ID"); $this->_helper->loadOauthstore->setinstance(); $store = OAuthStore::instance(); $servers = $store->listServers(null, $userId); print_r($servers); }
public function oauth_init() { Yii::import('application.modules.api.vendors.*'); require_once "oauth-php/library/OAuthServer.php"; require_once "oauth-php/library/OAuthStore.php"; #require_once("oauth-php/init.php"); $options = array('dsn' => $this->connectionString, 'username' => $this->username, 'password' => $this->password); OAuthStore::instance('PDO', $options); }
function __construct() { require_once APPPATH . 'libraries/oauth/OAuthStore.php'; require_once APPPATH . 'libraries/oauth/OAuthServer.php'; require_once APPPATH . 'libraries/oauth/OAuthRequester.php'; $this->_CI =& get_instance(); $this->_CI->config->load('oauth'); $db_options = array('server' => $this->_CI->config->item('db_server'), 'username' => $this->_CI->config->item('db_username'), 'password' => $this->_CI->config->item('db_password'), 'database' => $this->_CI->config->item('db_name')); $this->oauth_store = OAuthStore::instance('MySQL', $db_options); $this->oauth_server = new OAuthServer(); }
/** * Constructor. Creates authenticated access to Factual. * @param string key your oauth key. * @param string secret your oauth secret. */ public function __construct($key, $secret) { //load configuration $this->loadConfig(); $this->factHome = $this->config['factual']['endpoint']; //assign endpoint //create authentication object $options = array('consumer_key' => $key, 'consumer_secret' => $secret); $this->signer = OAuthStore::instance("2Leg", $options); //register autoloader spl_autoload_register(array(get_class(), 'factualAutoload')); }
/** * Given a URL return an OAuth signed URL. This will handle creating a timestamp and nonce * * @param string $url the unsigned url * @param string $method request method GET, POST, PUT, DELETE * @param string $key oauth key * @param string $secret oauth secret * @param array $params querystring or post parameters * @param string $body the body contents of the request * @param string $signature_method method used for signature (default = 'HMAC_SHA1') */ public static function SignUrl($url, $method, $key, $secret, $params = null, $body = null, $signature_method = 'HMAC_SHA1') { $options = array('consumer_key' => $key, 'consumer_secret' => $secret); $params = $params ? $params : array(); OAuthStore::instance("2Leg", $options); // Obtain a request object for the request we want to make $request = new OAuthRequester($url, $method, $params, $body); $sig = $request->sign($key, null, ''); $data = $request->signatureBaseString(); $url = substr(urldecode($data . '&oauth_signature=' . $request->calculateDataSignature($data, $secret, '', $signature_method)), strlen($method) + 1); $url = VerySimpleStringUtil::ReplaceFirst('&', '?', $url); return $url; }
function douban_oauth() { include 'lib/oauth/OAuthStore.php'; include 'lib/oauth/OAuthRequester.php'; define('DOUBAN_KEY', '0df3d98366dc5c4829db8c8a349514d8'); define('DOUBAN_SECRET', 'e6265a67126d5895'); define('DOUBAN_REQUEST_TOKEN_URL', 'http://www.douban.com/service/auth/request_token'); define('DOUBAN_AUTHORIZE_URL', 'http://www.douban.com/service/auth/authorize'); define('DOUBAN_ACCESS_TOKEN_URL', 'http://www.douban.com/service/auth/access_token'); define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV['TMP'])); $options = array('consumer_key' => DOUBAN_KEY, 'consumer_secret' => DOUBAN_SECRET, 'server_uri' => 'http://api.douban.com/', 'request_token_uri' => DOUBAN_REQUEST_TOKEN_URL, 'authorize_uri' => DOUBAN_AUTHORIZE_URL, 'access_token_uri' => DOUBAN_ACCESS_TOKEN_URL); OAuthStore::instance('Session', $options); }
/** * Retrieve an OAuthAccessor that is ready to sign OAuthMessages. * * @param tokenKey information about the gadget retrieving the accessor. * * @return an OAuthAccessorInfo containing an OAuthAccessor (whic can be * passed to an OAuthMessage.sign method), as well as httpMethod and * signatureType fields. */ public function getOAuthAccessor(TokenKey $tokenKey, $ignoreCache) { $gadgetUri = $tokenKey->getGadgetUri(); if (empty($gadgetUri)) { throw new OAuthStoreException("found empty gadget URI in TokenKey"); } $getUserId = $tokenKey->getUserId(); if (empty($getUserId)) { throw new OAuthStoreException("found empty userId in TokenKey"); } $gadgetSpec = $this->specFactory->getGadgetSpecUri($gadgetUri, $ignoreCache); $provInfo = $this->getProviderInfo($gadgetSpec, $tokenKey->getServiceName()); return $this->store->getOAuthAccessorTokenKey($tokenKey, $provInfo); }
public static function storeInstance() { $dbConf = Propel::getConfiguration(); $dsn = $dbConf['datasources']['propel']['connection']['dsn']; if (preg_match("/dbname=(.*);host=(.*)\$/", $dsn, $matches)) { $db = $matches[1]; $host = $matches[2]; } $store = OAuthStore::instance('MySQL', array('server' => $host, 'username' => $dbConf['datasources']['propel']['connection']['user'], 'password' => $dbConf['datasources']['propel']['connection']['password'], 'database' => $db)); if (!$store) { sfContext::getInstance()->getLogger()->err("Cannot connect to database."); throw new OAuthException("Cannot connect to database."); } return $store; }
/** * Construct the request to be verified * * @param string request * @param string method * @param array params The request parameters */ function __construct($uri = null, $method = null, $params = null) { if ($params) { $encodedParams = array(); foreach ($params as $key => $value) { if (preg_match("/^oauth_/", $key)) { continue; } $encodedParams[rawurlencode($key)] = rawurlencode($value); } $this->param = array_merge($this->param, $encodedParams); } $this->store = OAuthStore::instance(); parent::__construct($uri, $method); LingotekOAuthRequestLogger::start($this); }
public function run_query($endpoint, $params, $method="GET") { if (!$this->apiKey) throw new Semantics3_AuthenticationError('No API key provided.'); if (!$this->apiSecret) throw new Semantics3_AuthenticationError('No API secret provided.'); $options = array( 'consumer_key' => $this->apiKey, 'consumer_secret' => $this->apiSecret ); OAuthStore::instance("2Leg", $options ); $url = $this->apiBase.$endpoint; if ($method == "GET") { $url = $url."?q=".urlencode(json_encode($params)); $params = null; } else { $params = json_encode($params); } try { switch ($method) { case "GET": $request = new OAuthRequester($url, $method, $params); break; case "POST": $request = new OAuthRequester($url, $method, '', $params); break; case "DELETE": $request = new OAuthRequester($url, $method); break; default: $request = new OAuthRequester($url, $method); } $result = $request->doRequest(); return $result['body']; } catch(OAuthException2 $e) { print "\n"; $error = $e->getMessage(); print $error."\n"; } }
/** * Construct the request to be signed. Parses or appends the parameters in the params url. * When you supply an params array, then the params should not be urlencoded. * When you supply a string, then it is assumed it is of the type application/x-www-form-urlencoded * * @param string request url * @param string method PUT, GET, POST etc. * @param mixed params string (for urlencoded data, or array with name/value pairs) * @param string body optional body for PUT and/or POST requests */ function __construct($request, $method = 'GET', $params = null, $body = null) { $this->store = OAuthStore::instance(); if (is_string($params)) { parent::__construct($request, $method, $params); } else { parent::__construct($request, $method); if (is_array($params)) { foreach ($params as $name => $value) { $this->setParam($name, $value); } } } // With put/ post we might have a body (not for application/x-www-form-urlencoded requests) if ($method == 'PUT' || $method == 'POST') { $this->setBody($body); } }
function fGetTweets($user, $limit) { $options = array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET); OAuthStore::instance("2Leg", $options); try { // Obtain a request object for the request we want to make $request = new OAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST"); $result = $request->doRequest(0); parse_str($result['body'], $params); // now make the request. $request = new OAuthRequester(TWITTER_PUBLIC_TIMELINE_API, 'GET', $params); $result = $request->doRequest(); $response = $result['body']; } catch (OAuthException2 $e) { $response = "Exception" . $e->getMessage(); } return $response; }
function fGetTweets($user = '', $count = 3) { $file = dirname('.') . $user . '.json'; $options = array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET); OAuthStore::instance("2Leg", $options); $json = new Services_JSON(); $last = getCacheLastModified($file); $now = time(); if (!$last || $now - $last > REFRESH_INTERVAL) { $response = readTimeline($user, $count); saveCache($file, $response); } else { $response = readCache($file); } $response = $json->decode($response); $response = wrapTweets($response); return $response; }
function webservice_oauth_server_submit(Pieform $form, $values) { global $USER, $SESSION; $store = OAuthStore::instance(); $dbserver = get_record('oauth_server_registry', 'id', $values['id']); if ($dbserver) { $app = array('application_title' => $values['application_title'], 'application_uri' => $values['application_uri'], 'requester_name' => $dbserver->requester_name, 'requester_email' => $dbserver->requester_email, 'callback_uri' => $values['callback_uri'], 'institution' => $values['institution'], 'externalserviceid' => $values['service'], 'consumer_key' => $dbserver->consumer_key, 'consumer_secret' => $dbserver->consumer_secret, 'id' => $values['id']); $key = $store->updateConsumer($app, $USER->get('id'), true); $c = (object) $store->getConsumer($key, $USER->get('id'), true); if (empty($c)) { $SESSION->add_error_msg(get_string('errorregister', 'auth.webservice')); redirect('/webservice/admin/oauthv1sregister.php'); } else { redirect('/webservice/admin/oauthv1sregister.php?edit=' . $c->id); } } $SESSION->add_error_msg(get_string('errorupdate', 'auth.webservice')); redirect('/webservice/admin/oauthv1sregister.php'); }
function index() { $options = array('consumer_key' => $this->key, 'consumer_secret' => $this->secret); OAuthStore::instance("2Leg", $options); $url = "http://api.twitter.com/1/statuses/home_timeline.format?include_entities=true"; // this is the URL of the request $method = "GET"; // you can also use POST instead $params = null; try { // Obtain a request object for the request we want to make $request = new OAuthRequester($url, $method, $params); // Sign the request, perform a curl request and return the results, // throws OAuthException2 exception on an error // $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string) $result = $request->doRequest(); $response = $result['body']; echo $response; } catch (OAuthException2 $e) { } }
/** * send an api call to yotpo to authenticate and get an access token * @return access token */ public function oauthAuthentication() { if ($this->app_key == null or $this->secret == null) { Mage::log('Missing app key or secret'); return null; } $yotpo_options = array('consumer_key' => $this->app_key, 'consumer_secret' => $this->secret, 'client_id' => $this->app_key, 'client_secret' => $this->secret, 'grant_type' => 'client_credentials'); OAuthStore::instance("2Leg", $yotpo_options); try { $request = new OAuthRequester(self::YOTPO_OAUTH_TOKEN_URL, "POST", $yotpo_options); if (!$request) { Mage::log('Failed to get token access from yotpo api'); return null; } $result = $request->doRequest(0); $tokenParams = json_decode($result['body'], true); return $tokenParams['access_token']; } catch (OAuthException2 $e) { Mage::log('error: ' . $e); return null; } }
public function run_query($endpoint, $query_arr) { if (!$this->apiKey) { throw new Semantics3_AuthenticationError('No API key provided.'); } if (!$this->apiSecret) { throw new Semantics3_AuthenticationError('No API secret provided.'); } $options = array('consumer_key' => $this->apiKey, 'consumer_secret' => $this->apiSecret); OAuthStore::instance("2Leg", $options); $url = "https://api.semantics3.com/v1/{$endpoint}?q=" . $query_arr; $method = "GET"; $params = null; try { $request = new OAuthRequester($url, $method, $params); $result = $request->doRequest(); return $result['body']; } catch (OAuthException2 $e) { print "\n"; $error = $e->getMessage(); print $error . "\n"; } }
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ include_once "../../library/OAuthStore.php"; include_once "../../library/LingotekOAuthRequester.php"; // register at http://twitter.com/oauth_clients and fill these two define("TWITTER_CONSUMER_KEY", "FILL THIS"); define("TWITTER_CONSUMER_SECRET", "FILL THIS"); define("TWITTER_OAUTH_HOST", "https://twitter.com"); define("TWITTER_REQUEST_TOKEN_URL", TWITTER_OAUTH_HOST . "/oauth/request_token"); define("TWITTER_AUTHORIZE_URL", TWITTER_OAUTH_HOST . "/oauth/authorize"); define("TWITTER_ACCESS_TOKEN_URL", TWITTER_OAUTH_HOST . "/oauth/access_token"); define("TWITTER_PUBLIC_TIMELINE_API", TWITTER_OAUTH_HOST . "/statuses/public_timeline.json"); define("TWITTER_UPDATE_STATUS_API", TWITTER_OAUTH_HOST . "/statuses/update.json"); define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"])); // Twitter test $options = array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET); OAuthStore::instance("2Leg", $options); try { // Obtain a request object for the request we want to make $request = new LingotekOAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST"); $result = $request->doRequest(0); parse_str($result['body'], $params); echo "aa"; // now make the request. $request = new LingotekOAuthRequester(TWITTER_PUBLIC_TIMELINE_API, 'GET', $params); $result = $request->doRequest(); } catch (OAuthException2 $e) { echo "Exception" . $e->getMessage(); }
* Always announce XRDS OAuth discovery */ header('X-XRDS-Location: http://' . $_SERVER['SERVER_NAME'] . '/services.xrds'); /* * Initialize the database connection */ $info = parse_url(getenv('DB_DSN')); ($GLOBALS['db_conn'] = mysql_connect($info['host'], $info['user'], $info['pass'])) || die(mysql_error()); mysql_select_db(basename($info['path']), $GLOBALS['db_conn']) || die(mysql_error()); unset($info); require_once '../../../library/OAuthServer.php'; /* * Initialize OAuth store */ require_once '../../../library/OAuthStore.php'; OAuthStore::instance('MySQL', array('conn' => $GLOBALS['db_conn'])); /* * Session */ session_start(); /* * Template handling */ require_once 'smarty/libs/Smarty.class.php'; function session_smarty() { if (!isset($GLOBALS['smarty'])) { $GLOBALS['smarty'] = new Smarty(); $GLOBALS['smarty']->template_dir = dirname(__FILE__) . '/templates/'; $GLOBALS['smarty']->compile_dir = dirname(__FILE__) . '/../cache/templates_c'; }
} // you must use HTTPS as token based auth is a hazzard without it if (!is_https()) { header("HTTP/1.0 403 Forbidden - HTTPS must be used"); die; } /* * Always announce XRDS OAuth discovery */ header('X-XRDS-Location: ' . get_config('wwwroot') . 'webservice/oauthv1/services.xrds'); /* * Initialize OAuth store */ require_once get_config('docroot') . 'webservice/libs/oauth-php/OAuthServer.php'; require_once get_config('docroot') . 'webservice/libs/oauth-php/OAuthStore.php'; OAuthStore::instance('Mahara'); global $server; $server = new OAuthServer(); !isset($_SERVER['PATH_INFO']) && ($_SERVER['PATH_INFO'] = null); // Now - what kind of OAuth interaction are we handling? if ($_SERVER['PATH_INFO'] == '/request_token') { $server->requestToken(); exit; } else { if ($_SERVER['PATH_INFO'] == '/access_token') { $server->accessToken(); exit; } else { if ($_SERVER['PATH_INFO'] == '/authorize') { # logon require_once 'pieforms/pieform.php';