本文整理汇总了PHP中OAuthRequester::requestRequestToken方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthRequester::requestRequestToken方法的具体用法?PHP OAuthRequester::requestRequestToken怎么用?PHP OAuthRequester::requestRequestToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuthRequester
的用法示例。
在下文中一共展示了OAuthRequester::requestRequestToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: requestapiauthAction
public function requestapiauthAction()
{
$service = new Ml_Model_Service();
$userId = $service->getInput("User ID");
$consumerKey = $service->getInput("Consumer key");
$this->_helper->loadOauthstore->setinstance();
require EXTERNAL_LIBRARY_PATH . '/oauth-php/library/OAuthRequester.php';
$token = OAuthRequester::requestRequestToken($consumerKey, $userId);
// Callback to our (consumer) site
//it's called when the user finished the authorization at the server
$callbackUri = 'http://example.com/callback?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($callbackUri);
} else {
// No authorization uri
//assume we are authorized
//exchange request token for access token
$uri = $callbackUri . '&oauth_token=' . rawurlencode($token['token']);
}
echo $uri;
//exit();
}
示例3: 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) {
}
}
示例4: douban_login
function douban_login()
{
define('BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/');
$options = array('oauth_as_header' => false);
$tokenResultParams = OAuthRequester::requestRequestToken(DOUBAN_KEY, 0, array(), 'POST', $options);
$_SESSION['oauth_token'] = $tokenResultParams['token'];
context('redirect', DOUBAN_AUTHORIZE_URL . '?oauth_token=' . $tokenResultParams['token'] . '&oauth_callback=' . BASEURL . 'index.php?q=douban_oauth_callback');
}
示例5: getAuthURL
public static function getAuthURL($consumer_key, $consumer_secret, $store = "MySQL", $user_id = 1, $callback = null, $extra_options = array())
{
// Return the authorization URL. Redirect the header to this location.
OAuthClient::storeInstance(OAuthClient::merge_options($consumer_key, $consumer_secret, $extra_options), $store);
$getAuthTokenParams = array('scope' => SCOPE, 'oauth_callback' => $callback);
$tokenResultParams = OAuthRequester::requestRequestToken($consumer_key, $user_id, $getAuthTokenParams);
return "Location: " . GOOGLE_OAUTH_AUTHORIZE_API . "?oauth_token=" . $tokenResultParams['token'] . "&scope=" . $getAuthTokenParams['scope'] . "&domain=" . $consumer_key;
}
示例6: setupRequestToken
/**
* Get and setup request token
*
* @access public
* @return array
*/
public function setupRequestToken()
{
ApiDebug::p('query request token from server');
$oauth = $this->_getOAuthInstance();
$requestTokenInfo = \OAuthRequester::requestRequestToken(self::$_apiKey, 0, array(), 'POST', array(), self::_getCurlOptions());
// add token_secret to response
$requestTokenInfo['token_secret'] = $_SESSION['oauth_' . self::$_apiKey]['token_secret'];
ApiDebug::p('got request token info', $requestTokenInfo);
self::$_requestToken = $requestTokenInfo['token'];
self::$_requestSecret = $requestTokenInfo['token_secret'];
return array('oauth_token' => $requestTokenInfo['token'], 'oauth_token_secret' => $requestTokenInfo['token_secret']);
}
示例7: print_r
if (isset($_GET['error']) && !isset($_POST['email'])) {
echo '<pre>';
print_r($_GET['error']);
echo '</pre>';
exit;
}
//in case of submit login form
if (!empty($_POST['email']) && !empty($_POST['password'])) {
// $email = 'quocbao1087@gmail.com';
// $password = '123123';
$email = trim($_POST['email']);
$password = trim($_POST['password']);
$signature = SFSignature::genSignature($email, $password);
$getAuthTokenParams = array('xoauth_displayname' => 'Oauth test', 'oauth_callback' => SITE_URL . '/login.php');
// get a request token
$tokenResultParams = OAuthRequester::requestRequestToken(SFDOCTOR_CONSUMER_KEY, 0, $getAuthTokenParams);
// redirect to the 65doctor authorization page, they will redirect back
header("Location: " . SFDOCTOR_AUTHORIZE_URL . "?oauth_token=" . $tokenResultParams['token'] . $signature);
} else {
echo '<pre>';
print_r('Missing username or password.');
echo '</pre>';
exit;
}
} else {
// STEP 2: Get an access token
$oauthToken = $_GET["oauth_token"];
// echo "oauth_verifier = '" . $oauthVerifier . "'<br/>";
$tokenResultParams = $_GET;
try {
OAuthRequester::requestAccessToken(SFDOCTOR_CONSUMER_KEY, $oauthToken, 0, 'POST', $_GET);
示例8: define
define("GOOGLE_OAUTH_HOST", "https://www.google.com");
define("GOOGLE_REQUEST_TOKEN_URL", GOOGLE_OAUTH_HOST . "/accounts/OAuthGetRequestToken");
define("GOOGLE_AUTHORIZE_URL", GOOGLE_OAUTH_HOST . "/accounts/OAuthAuthorizeToken");
define("GOOGLE_ACCESS_TOKEN_URL", GOOGLE_OAUTH_HOST . "/accounts/OAuthGetAccessToken");
define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"]));
// Init the OAuthStore
$options = array('consumer_key' => GOOGLE_CONSUMER_KEY, 'consumer_secret' => GOOGLE_CONSUMER_SECRET, 'server_uri' => GOOGLE_OAUTH_HOST, 'request_token_uri' => GOOGLE_REQUEST_TOKEN_URL, 'authorize_uri' => GOOGLE_AUTHORIZE_URL, 'access_token_uri' => GOOGLE_ACCESS_TOKEN_URL);
// Note: do not use "Session" storage in production. Prefer a database
// storage, such as MySQL.
OAuthStore::instance("Session", $options);
try {
// STEP 1: If we do not have an OAuth token yet, go get one
if (empty($_GET["oauth_token"])) {
$getAuthTokenParams = array('scope' => 'http://docs.google.com/feeds/', 'xoauth_displayname' => 'Oauth test', 'oauth_callback' => 'XXXXXXXXXXX');
// get a request token
$tokenResultParams = OAuthRequester::requestRequestToken(GOOGLE_CONSUMER_KEY, 0, $getAuthTokenParams);
// redirect to the google authorization page, they will redirect back
header("Location: " . GOOGLE_AUTHORIZE_URL . "?btmpl=mobile&oauth_token=" . $tokenResultParams['token']);
} else {
// STEP 2: Get an access token
$oauthToken = $_GET["oauth_token"];
// echo "oauth_verifier = '" . $oauthVerifier . "'<br/>";
$tokenResultParams = $_GET;
try {
OAuthRequester::requestAccessToken(GOOGLE_CONSUMER_KEY, $oauthToken, 0, 'POST', $_GET);
} catch (OAuthException2 $e) {
var_dump($e);
// Something wrong with the oauth_token.
// Could be:
// 1. Was already ok
// 2. We were not authorized
示例9: startOAuthFlow
protected function startOAuthFlow()
{
// generate new user id since we're logging in and have no idea who the user is
$oauth_user_id = $this->getNewOAuthUserID();
$storage = new MrClay_CookieStorage(array('secret' => UserConfig::$SESSION_SECRET, 'mode' => MrClay_CookieStorage::MODE_ENCRYPT, 'path' => UserConfig::$SITEROOTURL, 'httponly' => true));
if (!$storage->store(UserConfig::$oauth_user_id_key, $oauth_user_id)) {
throw new Exception(implode('; ', $storage->errors));
}
try {
$callback = UserConfig::$USERSROOTFULLURL . '/oauth_callback.php?module=' . $this->getID();
// TODO add a way to skip this step if server was initialized
$this->initOAuthServer();
$params = array('scope' => $this->oAuthScope, 'oauth_callback' => $callback);
if (!is_null(UserConfig::$OAuthAppName)) {
$params['xoauth_displayname'] = UserConfig::$OAuthAppName;
}
// STEP 1: get a request token
$tokenResultParams = OAuthRequester::requestRequestToken($this->oAuthConsumerKey, $oauth_user_id, $params);
// redirect to the authorization page, they will redirect back
header("Location: " . $this->oAuthAuthorizeURL . "?oauth_token=" . $tokenResultParams['token']);
exit;
} catch (OAuthException2 $e) {
error_log(var_export($e, true));
return null;
}
}
示例10: define
define("OPERA_ACCESS_TOKEN_URL", "https://auth.opera.com/service/oauth/access_token");
define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"]));
// Start the session
session_start();
// Init the OAuthStore
$options = array('consumer_key' => OPERA_CONSUMER_KEY, 'consumer_secret' => OPERA_CONSUMER_SECRET, 'server_uri' => 'http://my.opera.com/community/api/', 'request_token_uri' => OPERA_REQUEST_TOKEN_URL, 'authorize_uri' => OPERA_AUTHORIZE_URL, 'access_token_uri' => OPERA_ACCESS_TOKEN_URL);
// Note: do not use "Session" storage in production. Prefer a database
// storage, such as MySQL.
OAuthStore::instance("Session", $options);
try {
// STEP 1: If we do not have an OAuth token yet, go get one
if (empty($_GET["oauth_verifier"])) {
$getAuthTokenParams = array('oauth_callback' => 'oob');
$options = array('oauth_as_header' => false);
// get a request token
$tokenResultParams = OAuthRequester::requestRequestToken(OPERA_CONSUMER_KEY, 0, $getAuthTokenParams, 'POST', $options);
$_SESSION['oauth_token'] = $tokenResultParams['token'];
// redirect to the opera authorization page, they will redirect back
header("Location: " . OPERA_AUTHORIZE_URL . "?oauth_token=" . $tokenResultParams['token']);
} else {
// STEP 2: Get an access token
try {
OAuthRequester::requestAccessToken(OPERA_CONSUMER_KEY, $_SESSION['oauth_token'], 0, 'POST', $options = array('oauth_verifier' => $_GET['oauth_verifier']));
} catch (OAuthException2 $e) {
var_dump($e);
// Something wrong with the oauth_token.
// Could be:
// 1. Was already ok
// 2. We were not authorized
return;
}
示例11: dirname
<?php
require dirname(__FILE__) . '/fx.php';
// Obtain a request token from the server
$token = OAuthRequester::requestRequestToken($server['consumer_key'], $user_id);
// 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']);
} else {
// No authorization uri, assume we are authorized, exchange request token for access token
$uri = '/follows/manage/oacb?oauth_token=' . rawurlencode($token['token']);
}
header('Location: ' . $uri);
示例12: array
<?php
/*
* We will now request a token from splitwise
* this is when we will be sending the client to splitwise to authenticate the application you registered.
*
*/
require "oauth/OAuthStore.php";
require "oauth/OAuthRequester.php";
require "config.php";
// Obtain a request token from splitwises' servers
try {
$token = OAuthRequester::requestRequestToken($key, $user_id, array('oauth_callback' => $callback_URL));
$uri = $token['authorize_uri'] . '?oauth_token=' . rawurlencode($token['token']);
header('Location: ' . $uri);
} catch (OAuthException2 $e) {
echo $e->getMessage();
}
示例13: kaixin001
/**
* 绑定开心网.
* @param string $username
* @param string $password
* @param boolean $follow
*/
private function kaixin001($username, $password, $follow)
{
set_time_limit(120);
require_once Kohana::find_file('vendor', 'oauth/OAuthRequester');
$okey = Kohana::config('uap.oauth');
define("MOMO_CONSUMER_KEY", $okey['kaixin001.com']['WB_AKEY']);
define("MOMO_CONSUMER_SECRET", $okey['kaixin001.com']['WB_SKEY']);
define("MOMO_OAUTH_HOST", "http://api.kaixin001.com");
define("MOMO_REQUEST_TOKEN_URL", MOMO_OAUTH_HOST . "/oauth/request_token");
define("MOMO_AUTHORIZE_URL", MOMO_OAUTH_HOST . "/oauth/authorize");
define("MOMO_ACCESS_TOKEN_URL", MOMO_OAUTH_HOST . "/oauth/access_token");
define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"]));
$store = OAuthStore::instance('MySQL');
$usr_id = $this->user_id;
try {
try {
$store->getServer(MOMO_CONSUMER_KEY, $usr_id);
} catch (OAuthException2 $e) {
//初始化
$server = array('consumer_key' => MOMO_CONSUMER_KEY, 'consumer_secret' => MOMO_CONSUMER_SECRET, 'server_uri' => MOMO_OAUTH_HOST, 'signature_methods' => array('HMAC-SHA1', 'PLAINTEXT'), 'request_token_uri' => MOMO_REQUEST_TOKEN_URL, 'authorize_uri' => MOMO_AUTHORIZE_URL, 'access_token_uri' => MOMO_ACCESS_TOKEN_URL);
//$store->deleteServer(MOMO_CONSUMER_KEY, $usr_id);
$consumer_key = $store->updateServer($server, $usr_id);
}
$tokenResultParams = OAuthRequester::requestRequestToken(MOMO_CONSUMER_KEY, $usr_id, array("scope" => "basic create_records"), "GET");
usleep(5);
//STEP 1: If we do not have an OAuth token yet, go get one
$Params = array("email" => $username, "password" => $password, "callback" => urlencode('http://api.kaixin001.com/oauth/authorize?oauth_token=' . $tokenResultParams['token'] . '&oauth_callback=' . urlencode(url::site("bind/confirm")) . '&from=&oauth_client=1'), "appkey" => MOMO_CONSUMER_KEY, "fromclient" => "", "return" => "", "login" => "登陆");
$query = '';
foreach ($Params as $key => $value) {
$query .= $key . '=' . $value . '&';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$cip = $_SERVER["HTTP_CLIENT_IP"];
} else {
if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
if (!empty($_SERVER["REMOTE_ADDR"])) {
$cip = $_SERVER["REMOTE_ADDR"];
} else {
//找不到默認為momo服務器ip
$cip = "58.22.103.199";
}
}
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', "CLIENT-IP: {$cip}", "X-FORWARDED-FOR: {$cip}"));
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.2.23) Gecko/20110921 Ubuntu/10.10 (maverick) Firefox/3');
curl_setopt($ch, CURLOPT_URL, "http://wap.kaixin001.com/auth/login.php?isoauth=1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); //是否抓取302跳转后的
$txt = curl_exec($ch);
curl_close($ch);
preg_match('@Location:(.*)@i', $txt, $matches);
if (!isset($matches[1]) || stripos($matches[1], '/oauth/authorize') === FALSE) {
$this->send_response(407, null, "用户名或密码错误");
return null;
}
$Params = array("loginnewsfeed" => 1, "oauth_token" => $tokenResultParams['token'], "oauth_callback" => "", "appid" => $okey['kaixin001.com']['APP_ID'], "oauth_client" => 1, "accept" => "允许");
$query = '';
foreach ($Params as $key => $value) {
$query .= $key . '=' . $value . '&';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', "CLIENT-IP: {$cip}", "X-FORWARDED-FOR: {$cip}"));
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.2.23) Gecko/20110921 Ubuntu/10.10 (maverick) Firefox/3');
curl_setopt($ch, CURLOPT_URL, trim($matches[1]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$txt = curl_exec($ch);
curl_close($ch);
preg_match('@你获取到的授权码是:<b>(\\w+)</b>@i', $txt, $matches);
if (!isset($matches[1])) {
$this->send_response(500, null, "oauth_verifier未取到");
return null;
}
$oauth_verifier = $matches[1];
usleep(5);
//STEP 2: Get an access token
try {
$access_token = OAuthRequester::requestAccessToken(MOMO_CONSUMER_KEY, $tokenResultParams['token'], $usr_id, 'POST', array("oauth_verifier" => $oauth_verifier));
try {
//取得个人信息
usleep(5);
$request = new OAuthRequester("http://api.kaixin001.com/users/me.json", 'GET');
$result = $request->doRequest($this->user_id);
if ($result['code'] != 200) {
//.........这里部分代码省略.........
示例14: array
AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
UNINTERRUPTED OR ERROR FREE.
*/
include_once "vendor/oauth/OAuthStore.php";
include_once "vendor/oauth/OAuthRequester.php";
//- Prepare the PHP OAuth for consuming our Oxygen service
$options = array('consumer_key' => ConsumerKey, 'consumer_secret' => ConsumerSecret, 'server_uri' => BaseUrl, 'request_token_uri' => BaseUrl . 'OAuth/RequestToken', 'authorize_uri' => BaseUrl . 'OAuth/Authorize', 'access_token_uri' => BaseUrl . 'OAuth/AccessToken');
OAuthStore::instance('Session', $options);
//- To disable the SSL check to avoid an exception with invalidate certificate on the server,
//- use the cURL CURLOPT_SSL_VERIFYPEER option and set it to false.
//- 1st leg: Get the 'request token'
$token = '';
try {
$token_ = OAuthRequester::requestRequestToken(ConsumerKey, 0, array(), 'POST', $options, array(CURLOPT_SSL_VERIFYPEER => 0));
$tmpRes = OAuthStore::instance()->getSecretsForSignature('', 0);
$token_secret = $tmpRes['token_secret'];
$token = array('oauth_token' => $token_['token'], 'oauth_token_secret' => $token_secret);
//- The following line is for reference only, the call to OAuthRequester::requestRequestToken() includes that step
//OAuthStore::instance ()->addServerToken (ConsumerKey, 'request', $token ['oauth_token'], $token ['oauth_token_secret'], 0, array ()) ;
$fname = realpath(dirname(__FILE__)) . '/token.txt';
file_put_contents($fname, serialize($token));
} catch (Exception $e) {
echo "OAuth/RequestToken\n", 'Caught exception: ', $e->getMessage(), "\n";
exit;
}
//- 2nd leg: Authorize the token
//- Currently, Autodesk Oxygen service requires you to manually log into the system, so we are using your default browser
try {
//$url =BaseUrl . "OAuth/Authorize" . "?oauth_token=" . urlencode (stripslashes ($token ['oauth_token'])) ;
示例15: array
return array();
}
}
$req_token_link = $CFG->wwwroot . '/blocks/gmail/oauth3/service/request_token.php';
$store = OAuthStore::instance('Google');
$user_id = $USER->id;
// most often the current user
// We must check if this user has a authorized token
// if they do not we need a link that says "grant access to my gmail"
// TODO:invalid old token link
// NOTE: if they need to revoke token or if current token doesn't work this link should
// show up.
$consumer_key = get_config('blocks/gmail', 'consumer_key');
// the google apps domain
try {
$token = OAuthRequester::requestRequestToken($consumer_key, $user_id);
} catch (OAuthException $e) {
if ($e->message == 'User not in token table.') {
// return the grant access link since user doesn't even have an entry in the tokens table
print 'User has no token.';
}
// If Server Returns a 400 or something is the token useless?
}
// Call back location after getting the first token
$callback_uri = $CFG->wwwroot . '/blocks/gmail/oauth3/service/obtain_auth.php?consumer_key=' . rawurlencode($consumer_key) . '&usr_id=' . intval($user_id);
// 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 {