src/plugins/oauthconsumer/include/fusionforge_oauth_datastore.php -text
src/plugins/oauthconsumer/include/oauthconsumerPlugin.class.php -text
src/plugins/oauthconsumer/include/provider_api.php -text
+src/plugins/oauthconsumer/include/resource_api.php -text
src/plugins/oauthconsumer/packaging/control/222plugin-oauthconsumer -text
src/plugins/oauthconsumer/packaging/control/222plugin-oauthconsumer.shortdesc -text
src/plugins/oauthconsumer/packaging/dirs/plugin-oauthconsumer -text
src/plugins/oauthconsumer/www/provider_edit.php -text
src/plugins/oauthconsumer/www/provider_update.php -text
src/plugins/oauthconsumer/www/providers.php -text
+src/plugins/oauthconsumer/www/response.php -text
src/plugins/oauthprovider/3rd-party/README -text
src/plugins/oauthprovider/3rd-party/oauth-php/CHANGELOG.txt -text
src/plugins/oauthprovider/3rd-party/oauth-php/LICENSE.txt -text
require_once $gfplugins.'oauthconsumer/include/fusionforge_oauth_datastore.php';
require_once $gfplugins.'oauthconsumer/include/provider_api.php';
require_once $gfplugins.'oauthconsumer/include/access_token_api.php';
+require_once $gfplugins.'oauthconsumer/include/resource_api.php';
$oauthconsumerPluginObject = new oauthconsumerPlugin ;
return $access_tokens;
}
+ static function get_all_access_tokens_by_provider($provider_id, $user_id) {
+ $conn = FFOAuthDataStore::singleton();
+ $rows = $conn->find_access_tokens_by_provider($provider_id, $user_id);
+ $access_tokens = array();
+ foreach ($rows as $row) {
+ $access_token = OAuthAccessToken::convert_row_to_object($row);
+ $access_tokens[] = $access_token;
+ }
+ return $access_tokens;
+ }
+
function write_to_db() {
if ( strlen(trim( $this->get_provider_id() ))==0 || strlen(trim( $this->get_user_id() ))==0 || strlen(trim( $this->get_token_key() ))==0 || strlen(trim( $this->get_token_secret() ))==0 ) {
exit_error( "Error trying to add the access token. Some required parameters are not set.", 'oauthconsumer' );
db_commit();
return true;
}
+
+ /**
+ * Saves an OAuthResource to the DB
+ *
+ * @param OAuthResource $resource
+ * @return int the resource ID in the DB
+ */
+ public function save_oauth_resource($resource) {
+
+ $t_resource_table = "plugin_oauthconsumer_resource";
+ $id = $resource->get_id();
+ if ( 0 == $id ) { # create
+
+ db_begin();
+ $result = db_query_params ("INSERT INTO $t_resource_table".' ( url, provider_id, http_method) VALUES ($1,$2,$3)',
+ array ( $resource->get_url(), $resource->get_provider_id(), $resource->get_http_method())) ;
+ if (!$result) {
+ db_rollback();
+ return false;
+ }
+ $resource_id = db_insertid($result, $t_resource_table, 'id' );
+
+ db_commit();
+
+ } else { # update
+ $t_query = "UPDATE $t_resource_table SET url=$1, provider_id=$2, http_method=$3 WHERE id=$4";
+ db_query_params( $t_query, array ($resource->get_url(), $resource->get_provider_id(), $resource->get_http_method(), $resource->get_id()) );
+ }
+ return $provider_id;
+
+ }
}
--- /dev/null
+<?php
+
+require_once('OAuth.php');
+
+class OAuthResource {
+
+ protected $id;
+ protected $url;
+ protected $provider_id;
+ protected $http_method;
+
+ function __construct($url, $provider_id, $http_method, $id=0) {
+ $this->url = $url;
+ $this->provider_id = $provider_id;
+ $this->http_method = $http_method;
+ $this->id = $id;
+ }
+
+ public function get_id() {
+ return $this->id;
+ }
+
+ function set_id($id) {
+ $this->id = $id;
+ }
+
+ public function get_url() {
+ return $this->url;
+ }
+
+ public function get_provider_id() {
+ return $this->provider_id;
+ }
+
+ public function get_http_method() {
+ return $this->http_method;
+ }
+
+ function write_to_db() {
+ if ( strlen(trim( $this->url ))==0 || strlen(trim( $this->provider_id ))==0 || strlen(trim( $this->http_method ))==0 ) {
+ exit_error( "Error trying to add the oauth resource. Please try again.", 'oauthconsumer' );
+ }
+ $conn = FFOAuthDataStore::singleton();
+ $id = $conn->save_oauth_resource($this);
+ if(!$id) {
+ exit_error("Error trying to add new oauth resource to DB", 'oauthconsumer');
+ }else {
+ $this->set_id($id);
+ }
+ }
+}
+
+class OAuthTransaction {
+
+ protected $consumer; //an OAuthConsumer object
+ protected $token; //an OAuthToken object
+ protected $resource; //an OAuthResource object
+ protected $request; //an OAuthRequest object
+
+ /**
+ * Constructor
+ *
+ * @param OAuthProvider $provider
+ * @param OAuthAccessToken $access_token
+ * @param OAuthResource $resource
+ * @param array $post_data (should be in the form of an array)
+ * @param boolean $json
+ *
+ */
+ function __construct($provider, $access_token, $resource, $post_data=NULL) {
+ $this->consumer = new OAuthConsumer($provider->get_consumer_key(), $provider->get_consumer_secret());
+ $this->token = new OAuthToken($access_token->get_token_key(), $access_token->get_token_secret());
+ $this->resource = $resource;
+ $this->request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $resource->get_http_method(), $resource->get_url(), $post_data);
+ }
+
+ function send_request($not_verify_ssl=FALSE) {
+ $hmac = new OAuthSignatureMethod_HMAC_SHA1();
+ $this->request->sign_request($hmac, $this->consumer, $this->token);
+ if(strcasecmp($this->resource->get_http_method(), "get")==0) {
+ return $this->send_http_get($not_verify_ssl);
+ }elseif(strcasecmp($this->resource->get_http_method(), "post")==0) {
+ return $this->send_http_post($not_verify_ssl);
+ }
+ }
+
+ function send_http_get($not_verify_ssl) {
+ $separator = "?";
+ if (strpos($this->request->get_normalized_http_url(),"?")!=false) $separator = "&";
+
+ $curl = curl_init();
+
+ $url = $this->request->get_normalized_http_url().$separator.$this->request->to_postdata();
+ curl_setopt($curl, CURLOPT_URL, $url);
+
+ if($not_verify_ssl) {
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ }
+
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+
+ $response = curl_exec ($curl);
+ curl_close ($curl);
+
+ return $response;
+ }
+
+ function send_http_post($not_verify_ssl) {
+ $curl = curl_init();
+
+ curl_setopt($curl, CURLOPT_POST, TRUE);
+
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $this->request->to_postdata());
+ curl_setopt($curl, CURLOPT_URL, $this->request->get_normalized_http_url());
+
+ if($not_verify_ssl) {
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ }
+
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+
+ $response = curl_exec ($curl);
+ curl_close ($curl);
+
+ return $response;
+ }
+
+}
\ No newline at end of file
if(count($access_tokens)>0) {
echo $HTML->boxTop(_('OAuth Access Tokens'));
- echo $HTML->listTableTop(array(_('Provider'), _('Consumer Key'), _('Consumer Secret'), '', ''));
+ echo $HTML->listTableTop(array(_('Provider'), _('Token Key'), _('Token Secret'), '', ''));
$i = 0;
foreach( $access_tokens as $token ) { ?>
<tr <?php echo $HTML->boxGetAltRowStyle($i++) ?>>
<?php
}
echo $HTML->listTableBottom();
- echo $HTML->boxBottom();
- echo util_make_link('/plugins/'.$pluginname.'/get_access_token.php', _('Get more access tokens')).'<br /> ';
+ echo $HTML->boxBottom();
}
else {
echo '<p>'. _('You have no OAuth Access Tokens registered in the database currently').'</p>';
}
+echo'<br><br>';
+
+echo util_make_link('/plugins/'.$pluginname.'/providers.php', _('OAuth Providers')). ' <br />';
+echo util_make_link('/plugins/'.$pluginname.'/get_access_token.php', _('Get more Access tokens')).'<br /> ';
site_user_footer(array());
\ No newline at end of file
$token = $_GET['oauth_token']?$_GET['oauth_token']:getStringFromPost('oauth_token');
if(!$verifier || !$token) {
- exit_error("OAuth parameters not found.");
+ echo $HTML->error_msg(htmlspecialchars("OAuth parameters not found."));
}
?>
<form action="callback.php" method="post">
echo '<input type="hidden" name="provider_id" value="'.$_COOKIE['PROVIDER'].'"/>';
echo _('<b>Step 3: </b>Exchange the authorized request token for an access token');?>
<br>
- <input type="submit" value="<?php echo _('Go') ?>"
+ <input type="submit" value="<?php echo _('Go') ?>" />
</form>
<?php
$f_provider_id = getStringFromPost('provider_id');
$ff_consumer = new OAuthConsumer($consumer_key, $consumer_secret);
$oauth_request_token = new OAuthToken($_COOKIE['OAUTH_TOKEN'], $_COOKIE['OAUTH_TOKEN_SECRET']);
+ setcookie('OAUTH_TOKEN', '', time()-3600);
+ setcookie('OAUTH_TOKEN_SECRET', '', time()-3600);
$ff_request2 = OAuthRequest::from_consumer_and_token($ff_consumer, false, "GET", $access_token_url, $parameters);
$hmac = new OAuthSignatureMethod_HMAC_SHA1();
curl_setopt($curl, CURLOPT_URL, $ff_request2->to_url());
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ //temporary workaround for untrusted security certificates
+ $not_verify_ssl = $_COOKIE['NOT_VERIFY_SSL']?$_COOKIE['NOT_VERIFY_SSL']:0;
+ if($not_verify_ssl) {
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ }
+ setcookie('NOT_VERIFY_SSL', '', time()-3600);
+
$access_token_string = curl_exec ($curl);
curl_close ($curl);
parse_str($access_token_string, $access_token_array);
$userid = session_get_user()->getID();
if(!$access_token_array['oauth_token'] || !$access_token_array['oauth_token_secret']) {
- exit_error("Access Token not received.");
+ echo $HTML->error_msg(htmlspecialchars("Access Token not received."));
}
$new_access_token = new OAuthAccessToken($f_provider_id, $access_token_array['oauth_token'], $access_token_array['oauth_token_secret'], $userid);
$new_access_token->write_to_db();
echo _("Access Token Key : ".$access_token_array['oauth_token']."<br>");
echo _("Access Token Secret : ".$access_token_array['oauth_token_secret']."<br>");
-}
\ No newline at end of file
+}
+
+echo'<br><br>';
+
+echo util_make_link('/plugins/'.$pluginname.'/providers.php', _('OAuth Providers')). ' <br />';
+echo util_make_link('/plugins/'.$pluginname.'/get_access_token.php', _('Get Access tokens')).'<br /> ';
+echo util_make_link('/plugins/'.$pluginname.'/access_tokens.php', _('Access tokens')).'<br /> ';
+
+site_user_footer(array());
\ No newline at end of file
</tr>
</table><br>
-
<?php
+ if((strcasecmp(substr($f_request_token_url, 0, 5),"https")==0) ||
+ (strcasecmp(substr($f_authorization_url, 0, 5),"https")==0) ||
+ (strcasecmp(substr($f_access_token_url, 0, 5),"https")==0)) {?>
+ <input type="checkbox" name="not_verify_ssl">Do not verify SSL Certificate</input> <br><br>
+ <?php
+ }
$url_string = $f_request_token_url?"(from ".$f_request_token_url.")":"";
echo _('<b>Step 1: </b>Get Request Token '.$url_string) ?>
<br>
- <input type="submit" value="<?php echo _('Go') ?>"
+ <input type="submit" value="<?php echo _('Go') ?>" />
</form>
<?php
$form_key = getStringFromPost('plugin_oauthconsumer_get_request_token');
$f_provider_id = getStringFromPost('providers');
+ $f_not_verify_ssl = getStringFromPost('not_verify_ssl');
if($form_key && $f_provider_id && form_key_is_valid($form_key)) {
form_release_key($form_key);
curl_setopt($curl, CURLOPT_URL, $ff_request1->to_url());
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ //workaround for untrusted security certificates
+ if($f_not_verify_ssl) {
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ session_set_cookie('NOT_VERIFY_SSL', 1, 0, '', '', false, true);
+ }
+
$request_token_string = curl_exec ($curl);
+
+ if($request_token_string === false)
+ {
+ trigger_error('Error in curl : '.curl_error($curl), E_USER_WARNING);
+ }
curl_close ($curl);
-
+ //print_r($request_token_string);
parse_str($request_token_string, $request_token);
- echo _("New request token received!<br>");
- echo _("Request Token Key : ".$request_token['oauth_token']."<br>");
- echo _("Request Token Secret : ".$request_token['oauth_token_secret']."<br><br>");
- //print_r($request_token);
- session_set_cookie('PROVIDER', $f_provider_id, '', 10*60);
- session_set_cookie('OAUTH_TOKEN', $request_token['oauth_token'], '', 10*60);
- session_set_cookie('OAUTH_TOKEN_SECRET', $request_token['oauth_token_secret'], '', 10*60);
- $oauth_request_token = new OAuthToken($request_token['oauth_token'], $request_token['oauth_token_secret']);
-
- $separator = "?";
- if (strpos($f_authorize_url,"?")!=false) $separator = "&";
-
- $new_user_authorization_url = $f_authorize_url . $separator . "oauth_token=".$request_token['oauth_token']."&oauth_callback=".$callback_url;
- //print_r($new_user_authorization_url);
+
+ if(array_key_exists('oauth_token', $request_token)&&array_key_exists('oauth_token_secret', $request_token)) {
+ echo _("New request token received!<br>");
+ echo _("Request Token Key : ".$request_token['oauth_token']."<br>");
+ echo _("Request Token Secret : ".$request_token['oauth_token_secret']."<br><br>");
+ //print_r($request_token);
+ setcookie('PROVIDER', $f_provider_id, 0, '', '', false, true);
+ setcookie('OAUTH_TOKEN', $request_token['oauth_token'], 0, '', '', false, true);
+ setcookie('OAUTH_TOKEN_SECRET', $request_token['oauth_token_secret'], 0, '', '', false, true);
+ $oauth_request_token = new OAuthToken($request_token['oauth_token'], $request_token['oauth_token_secret']);
+
+ $separator = "?";
+ if (strpos($f_authorize_url,"?")!=false) $separator = "&";
+
+ $new_user_authorization_url = $f_authorize_url . $separator . "oauth_token=".$request_token['oauth_token']."&oauth_callback=".$callback_url;
+ //print_r($new_user_authorization_url);
+
?>
<form action="get_access_token.php" method="post">
<?php
echo _('<b>Step 2: </b>Authorize the Request Token (from '.$f_authorize_url.")") ?>
<br>
- <input type="submit" value="<?php echo _('Go') ?>"
+ <input type="submit" value="<?php echo _('Go') ?>" />
</form>
<?php
//header("Location:".$new_user_authorization_url);
+ }else {
+ echo $HTML->error_msg(htmlspecialchars("Error in retrieving request token"));
+
+ }
}
$f_authorization_url = getStringFromPost('authorization_url');
echo '<p>'. _('There are no OAuth Providers registered in the database currently. Please ask your forge administer to create one.').'</p>';
}
+echo'<br><br>';
+
+echo util_make_link('/plugins/'.$pluginname.'/providers.php', _('OAuth Providers')). ' <br />';
+echo util_make_link('/plugins/'.$pluginname.'/access_tokens.php', _('Access tokens')).'<br /> ';
+
site_user_footer(array());
\ No newline at end of file
oauthconsumer_CheckUser();
+$userid = session_get_user()->getID();
+$providers = OAuthProvider::get_all_oauthproviders();
+if(count($providers)>0) {
+ echo '<p>'. _('This OAuth Consumer plugin allows a user to connect to different oauth enabled services.').'</p>';
+ echo '<h4>'._('Accessing resources with OAuth').'</h4>';
+ ?>
+ <form action="index.php" method="post">
+ <?php echo _('<b>Providers</b>');
+ $f_provider_id = getStringFromPost('providers');?>
+ <select name=providers>
+ <?php foreach ($providers as $provider) {
+ echo '<option value="'.$provider->get_id().'" ';
+ if($provider->get_id()==$f_provider_id) {
+ echo 'SELECTED';
+ }
+ echo '>'.$provider->get_name().'</option>';
+ }?>
+ </select>
+ <input type="submit" value="<?php echo _('Select') ?>"/>
+ </form>
+ <?php
+
+ if($f_provider_id) {
+ $access_tokens = OAuthAccessToken::get_all_access_tokens_by_provider($f_provider_id, $userid);
+ if(count($access_tokens)>0) {
+ ?>
+ <form action="response.php" method="post">
+ <table class="width50" align="center" cellspacing="1">
+
+ <tr>
+ <td class="category"><?php echo _('Access Tokens');?></td>
+ <td><select name=tokens>
+ <?php foreach ($access_tokens as $token) {
+ echo '<option value="'.$token->get_id().'">'.$token->get_token_key().'</option>';
+ }?>
+ </select></td>
+ </tr>
+
+ <tr>
+ <td class="category"><?php echo _('Resource URL') ?></td>
+ <td><input name="resource_url" maxlength="250" size="60" value=""/></td>
+ </tr>
+
+ <tr>
+ <td class="category"><?php echo _('HTTP Request');?></td>
+ <td><select name=http>
+ <option value="get">GET</option>
+ <option value="post">POST</option>
+ </select></td>
+ </tr>
+
+ <tr>
+ <td class="category"><?php echo _('POST data') ?></td>
+ <td><input name="post_data" maxlength="250" size="60" value=""/></td>
+ </tr>
+
+ <tr>
+ <td class="center" colspan="2"><input type="submit" value="<?php echo _('Go') ?>"/></td>
+ </tr>
+
+ </table>
+ </form>
+
+ <br><br>
+ <?php
+
+ }else {
+ echo '<p>'. _('No access tokens have been created for this provider').'</p>';
+ }
+ }
+}else {
+ echo '<p>'. _('There are no OAuth Providers registered in the database currently. Please ask your forge administer to create one.').'</p>';
+}
+
+echo'<br><br><p>'._("If no OAuth Providers or Access Tokens have been created yet, follow the links below to get started").'</p>';
+
echo util_make_link('/plugins/'.$pluginname.'/providers.php', _('OAuth Providers')). ' <br />';
echo util_make_link('/plugins/'.$pluginname.'/get_access_token.php', _('Get Access tokens')).'<br /> ';
echo util_make_link('/plugins/'.$pluginname.'/access_tokens.php', _('Access tokens')).'<br /> ';
-
site_user_footer(array());
\ No newline at end of file
</form>
<?php
-site_users_footer(array());
\ No newline at end of file
+
+echo'<br><br>';
+
+echo util_make_link('/plugins/'.$pluginname.'/providers.php', _('OAuth Providers')). ' <br />';
+echo util_make_link('/plugins/'.$pluginname.'/get_access_token.php', _('Get Access tokens')).'<br /> ';
+echo util_make_link('/plugins/'.$pluginname.'/access_tokens.php', _('Access tokens')).'<br /> ';
+
+site_user_footer(array());
\ No newline at end of file
<?php
}
+echo'<br><br>';
+
+echo util_make_link('/plugins/'.$pluginname.'/get_access_token.php', _('Get Access tokens')).'<br /> ';
+echo util_make_link('/plugins/'.$pluginname.'/access_tokens.php', _('Access tokens')).'<br /> ';
+
+
site_user_footer(array());
\ No newline at end of file
--- /dev/null
+<?php
+
+require_once('../../env.inc.php');
+require_once 'checks.php';
+
+oauthconsumer_CheckUser();
+
+$f_token_id = getStringFromPost('tokens');
+$f_resource_url = getStringFromPost('resource_url');
+$f_http_method = getStringFromPost('http');
+$f_post_data = getStringFromPost('post_data');
+
+if(!$f_post_data) $f_post_data = NULL;
+
+$access_token = OAuthAccessToken::get_access_token($f_token_id);
+$resource = new OAuthResource($f_resource_url, $access_token->get_provider_id(), $f_http_method);
+$provider = OAuthProvider::get_provider($access_token->get_provider_id());
+
+if(substr($f_resource_url, -5, 5)==".json") $f_post_data = json_decode($f_post_data, TRUE);
+
+$transaction = new OAuthTransaction($provider, $access_token, $resource, $f_post_data);
+$response = $transaction->send_request();
+
+//twitter, identi.ca rest api endpoints
+$timeline_resources = array("public_timeline",
+ "home_timeline",
+ "friends_timeline",
+ "mentions",
+ "replies",
+ "user_timeline",
+ "retweeted_to_me",
+ "retweeted_by_me",
+ "retweets_of_me");
+$url_prefix = array("http://api.twitter.com/1/statuses/",
+ "http://identi.ca/api/statuses/");
+
+if(substr($f_resource_url, -5, 5)==".json") {
+ $response_array = json_decode($response, TRUE);
+ foreach ($url_prefix as $prefix) {
+ foreach($timeline_resources as $suffix) {
+ if($f_resource_url==$prefix.$suffix.".json") {
+ $timeline = true;
+ $title = str_replace("_", " ", $suffix);
+ echo "<p>".$title."</p><ol>";
+ foreach($response_array as $tweet) {
+ if(array_key_exists("text", $tweet)) {
+ echo "<li>".$tweet["text"]."</li>";
+ }else {
+ print_r($response_array);
+ break;
+ }
+ }
+ echo "</ol>";
+ }
+ }
+ }
+ if(!$timeline) {
+ if(($f_resource_url=="http://api.twitter.com/1/statuses/update.json")||($f_resource_url=="http://identi.ca/api/statuses/update.json")) {
+ if(array_key_exists("text", $response_array)) {
+ echo $HTML->feedback("Tweet: '".$response_array["text"]." posted successfully");
+ }else {
+ print_r($response_array);
+ }
+ }else {
+ print_r($response_array);
+ }
+ }
+}else {
+ var_dump($response);
+}
+
+echo'<br><br>';
+
+echo util_make_link('/plugins/'.$pluginname.'/providers.php', _('OAuth Providers')). ' <br />';
+echo util_make_link('/plugins/'.$pluginname.'/get_access_token.php', _('Get Access tokens')).'<br /> ';
+echo util_make_link('/plugins/'.$pluginname.'/access_tokens.php', _('Access tokens')).'<br /> ';
+
+site_user_footer(array());
\ No newline at end of file
global $gfplugins;
require_once $gfplugins.'twitter/include/twitterPlugin.class.php' ;
+//oauthconsumer dependencies
+require_once $gfplugins.'oauthconsumer/include/fusionforge_oauth_datastore.php';
+require_once $gfplugins.'oauthconsumer/include/provider_api.php';
+require_once $gfplugins.'oauthconsumer/include/access_token_api.php';
+require_once $gfplugins.'oauthconsumer/include/resource_api.php';
+
$twitterPluginObject = new twitterPlugin ;
register_plugin ($twitterPluginObject) ;