本文整理汇总了PHP中OAuthStore类的典型用法代码示例。如果您正苦于以下问题:PHP OAuthStore类的具体用法?PHP OAuthStore怎么用?PHP OAuthStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OAuthStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResponseAPI
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) {
}
}
示例2: TPSession
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();
}
}
示例3: authenticate
/**
* 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;
}
示例4: __construct
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));
}
示例5: instance
/**
* 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;
}
示例6: authorize_action
/**
*
**/
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;
}
示例7: run_query
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";
}
}
示例8: __construct
/**
* 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());
}
}
示例9: grant_access_token_to_consumer
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;
}
示例10: setinstance
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']));
}
示例11: listapiserversAction
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);
}
示例12: oauth_init
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);
}
示例13: __construct
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();
}
示例14: __construct
/**
* 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'));
}
示例15: SignUrl
/**
* 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;
}