[Fusionforge-commits] r14299 - in trunk/src/plugins/oauthconsumer: . common db include
Madhumita Dhar
mdhar at fusionforge.org
Thu Sep 1 17:50:10 CEST 2011
Author: mdhar
Date: 2011-09-01 17:50:10 +0200 (Thu, 01 Sep 2011)
New Revision: 14299
Added:
trunk/src/plugins/oauthconsumer/include/
trunk/src/plugins/oauthconsumer/include/fusionforge_oauth_datastore.php
trunk/src/plugins/oauthconsumer/include/oauthconsumerPlugin.class.php
Modified:
trunk/src/plugins/oauthconsumer/common/oauthconsumer-init.php
trunk/src/plugins/oauthconsumer/db/oauthconsumer-init.sql
Log:
initial commits for oauthconsumer plugin
Modified: trunk/src/plugins/oauthconsumer/common/oauthconsumer-init.php
===================================================================
--- trunk/src/plugins/oauthconsumer/common/oauthconsumer-init.php 2011-09-01 15:50:06 UTC (rev 14298)
+++ trunk/src/plugins/oauthconsumer/common/oauthconsumer-init.php 2011-09-01 15:50:10 UTC (rev 14299)
@@ -21,6 +21,8 @@
global $gfplugins;
require_once $gfplugins.'oauthconsumer/include/oauthconsumerPlugin.class.php' ;
+require_once $gfplugins.'oauthconsumer/include/fusionforge_oauth_datastore.php';
+require_once $gfplugins.'oauthconsumer/include/provider_api.php';
$oauthconsumerPluginObject = new oauthconsumerPlugin ;
Modified: trunk/src/plugins/oauthconsumer/db/oauthconsumer-init.sql
===================================================================
--- trunk/src/plugins/oauthconsumer/db/oauthconsumer-init.sql 2011-09-01 15:50:06 UTC (rev 14298)
+++ trunk/src/plugins/oauthconsumer/db/oauthconsumer-init.sql 2011-09-01 15:50:10 UTC (rev 14299)
@@ -4,9 +4,9 @@
description VARCHAR(500) NOT NULL,
consumer_key VARCHAR(250) NOT NULL,
consumer_secret VARCHAR(250) NOT NULL,
- request_token_url VARCHAR(250) NOT NULL,
- authorize_url VARCHAR(250) NOT NULL,
- access_token_url VARCHAR(250) NOT NULL
+ request_token_url VARCHAR(250),
+ authorize_url VARCHAR(250),
+ access_token_url VARCHAR(250)
);
CREATE UNIQUE INDEX idx_oauthconsumer_provider_name on plugin_oauthconsumer_provider(name);
CREATE UNIQUE INDEX idx_oauthconsumer_provider_consumer_key on plugin_oauthconsumer_provider(consumer_key);
@@ -19,7 +19,7 @@
user_id INTEGER NOT NULL,
time_stamp INTEGER NOT NULL,
CHECK (user_id>=0),
- CHECK (consumer_id>=0),
+ CHECK (provider_id>=0),
CHECK (time_stamp>=0)
);
CREATE UNIQUE INDEX idx_oauthconsumer_access_token_key on plugin_oauthconsumer_access_token(token_key);
Added: trunk/src/plugins/oauthconsumer/include/fusionforge_oauth_datastore.php
===================================================================
--- trunk/src/plugins/oauthconsumer/include/fusionforge_oauth_datastore.php (rev 0)
+++ trunk/src/plugins/oauthconsumer/include/fusionforge_oauth_datastore.php 2011-09-01 15:50:10 UTC (rev 14299)
@@ -0,0 +1,184 @@
+<?php
+
+/**
+ * This file is (c) Copyright 2010 by Olivier BERGER, Madhumita DHAR, Institut TELECOM
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * This program has been developed in the frame of the COCLICO
+ * project with financial support of its funders.
+ *
+ */
+
+
+// Inspired from examples described in "Creating a OAuth Service
+// Provider in PHP" by Morten Fangel
+// (http://sevengoslings.net/~fangel/oauthprovider-sp-guide.html)
+
+require_once('OAuth.php');
+
+/**
+ * OAuthDataStore singleton class to manage tokens, consumers and providers in FusionForge DB
+ *
+ * Everything specific to the DB model is handled in this class : no other SQL request should exist outside it
+ * It should be reimplemented for other apps, the rest of the classes being untouched
+ *
+ * It will assume that OAuthProvider, OauthAuthzConsumer, OauthAuthzToken and its sub-classes are used
+ *
+ * @author Olivier Berger
+ *
+ */
+
+class FFOAuthDataStore extends OAuthDataStore {
+
+ // Hold an instance of the class
+ private static $instance;
+
+ /**
+ * Singleton pattern's method to retrieve the instance
+ */
+ public static function singleton()
+ {
+ if (!isset(self::$instance)) {
+ $c = __CLASS__;
+ self::$instance = new $c;
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Prevent users to clone the instance
+ */
+ public function __clone()
+ {
+ exit_error('Clone is not allowed.', 'oauthconsumer');
+ }
+
+ /**
+ * Retrieve values of columns for a provider in the DB provided its id
+ *
+ * @param int $p_id ID in the DB
+ * @return array of column values
+ */
+ function find_provider_from_id( $p_id ) {
+ $t_provider_table = "plugin_oauthconsumer_provider";
+
+ $t_result = db_query_params ("SELECT * FROM $t_provider_table WHERE id=$1",
+ array ( (int) $p_id )) ;
+ if (!$t_result || ( db_numrows( $t_result ) < 1 )) {
+ exit_error( "provider not found!", 'oauthconsumer' );
+ }
+
+ $t_row = db_fetch_array( $t_result );
+
+ return $t_row;
+ }
+
+ /**
+ * Retrieve a table of columns values for all providers
+ *
+ * @return array of arrays of column values
+ */
+ function find_all_providers() {
+ $t_provider_table = "plugin_oauthconsumer_provider";
+ $t_result = db_query_params("SELECT * FROM $t_provider_table ORDER BY name ASC", array());
+
+ $t_rows = array();
+
+ while ( $t_row = db_fetch_array( $t_result ) ) {
+ $t_rows[] = $t_row;
+ }
+
+ return $t_rows;
+ }
+
+ /**
+ * Retrieve values of columns for a provider in the DB provided its name
+ *
+ * @param string $p_provider_name
+ * @return array of column values
+ */
+ function find_provider_from_name( $p_provider_name ) {
+ $t_provider_table = "plugin_oauthconsumer_provider";
+
+ $t_query = "SELECT * FROM $t_provider_table WHERE name = $1";
+ $t_result = db_query_params( $t_query, array( $p_provider_name ) );
+
+ if ( db_numrows( $t_result ) < 1 ) {
+ return null;
+ }
+
+ $t_row = db_fetch_array( $t_result );
+
+ return $t_row;
+ }
+
+ /**
+ * Saves an OauthAuthzprovider to the DB
+ *
+ * @param OauthAuthzprovider $provider
+ * @return int the provider ID in the DB
+ */
+ public function save_provider($provider) {
+ $t_provider_table = "plugin_oauthconsumer_provider";
+
+ $provider_id = $provider->get_id();
+ if ( 0 == $provider_id ) { # create
+
+ db_begin();
+ $result = db_query_params ("INSERT INTO $t_provider_table".' ( name, description, consumer_key, consumer_secret, request_token_url, authorize_url, access_token_url) VALUES ($1,$2,$3,$4,$5,$6,$7)',
+ array ( $provider->get_name(), $provider->get_description(), $provider->get_consumer_key(), $provider->get_consumer_secret(), $provider->get_request_token_url(), $provider->get_authorize_url(), $provider->get_access_token_url())) ;
+ if (!$result) {
+ //$this->setError('Error Adding provider: '.db_error());
+ db_rollback();
+ return false;
+ }
+ $provider_id = db_insertid($result, $t_provider_table, 'id' );
+
+ db_commit();
+
+ } else { # update
+ $t_query = "UPDATE $t_provider_table SET name=$1, description=$2, consumer_key=$3, consumer_secret=$4, request_token_url=$5, authorize_url=$6, access_token_url=$7 WHERE id=$8";
+ db_query_params( $t_query, array ( $provider->get_name(), $provider->get_description(), $provider->get_consumer_key(), $provider->get_consumer_secret(), $provider->get_request_token_url(), $provider->get_authorize_url(), $provider->get_access_token_url(), $provider->get_id()) );
+ }
+ return $provider_id;
+ }
+
+
+ /**
+ * Deletes a provider from the DB
+ *
+ * @param int $provider_id
+ */
+ public function delete_provider( $provider_id ) {
+
+ $t_provider_table = "plugin_oauthconsumer_provider";
+
+ $t_query = "DELETE FROM $t_provider_table WHERE id=$1";
+ $t_result = db_query_params( $t_query, array( (int) $provider_id ) );
+
+ if (!$t_result) {
+ db_rollback();
+ return false;
+ }
+
+ db_commit();
+ return true;
+ }
+
+
+
+}
Added: trunk/src/plugins/oauthconsumer/include/oauthconsumerPlugin.class.php
===================================================================
--- trunk/src/plugins/oauthconsumer/include/oauthconsumerPlugin.class.php (rev 0)
+++ trunk/src/plugins/oauthconsumer/include/oauthconsumerPlugin.class.php 2011-09-01 15:50:10 UTC (rev 14299)
@@ -0,0 +1,26 @@
+<?php
+
+class oauthconsumerPlugin extends ForgeAuthPlugin {
+
+ public function __construct() {
+
+ $this->ForgeAuthPlugin() ;
+
+ $this->name = 'oauthconsumer';
+ $this->text = 'OAuth Consumer'; // To show in the tabs, use...
+ $this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
+ $this->_addHook("usermenu");
+ $this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
+ $this->_addHook("userisactivecheckboxpost"); //
+
+ }
+
+ function usermenu() {
+ global $G_SESSION,$HTML;
+ $text = $this->text; // this is what shows in the tab
+ if ($G_SESSION->usesPlugin($this->name)) {
+ echo $HTML->PrintSubMenu (array ($text), array ('/plugins/oauthconsumer/index.php') );
+ }
+ }
+
+}
More information about the Fusionforge-commits
mailing list