Enhancement of Oauth module

This commit is contained in:
Laurent Destailleur 2016-10-07 17:53:41 +02:00
parent 44eb133a3f
commit ba52eb870c
13 changed files with 647 additions and 261 deletions

View File

@ -35,6 +35,8 @@ check you make a fetch on object before calling the delete.
- The javascript "datatables" library was used to be provided into Dolibarr sources, but it was not used by application.
So there is no reason to maintain its compatibility with other dolibarr components. If an external module need this
library, this external module must embed hte library in his own sources/packages.
- Trigger name SUPPLIER_PROPOSAL_CREATE has been renamed into PROPOSAL_SUPPLIER_CREATE
***** ChangeLog for 4.0.1 compared to 4.0.0 *****

View File

@ -24,9 +24,8 @@
*/
require '../main.inc.php';
// required Class
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php';
// Define $urlwithroot
@ -44,224 +43,6 @@ if (!$user->admin)
$action = GETPOST('action', 'alpha');
// Supported OAUTH (a provider is supported when a file xxx_oauthcallback.php is available into htdocs/core/modules/oauth)
$supportedoauth2array=array('OAUTH_GOOGLE_NAME'=>'google');
// API access parameters OAUTH
$list = array (
array(
'OAUTH_AMAZON_NAME',
'OAUTH_AMAZON_ID',
'OAUTH_AMAZON_SECRET',
),
array(
'OAUTH_BITBUCKET_NAME',
'OAUTH_BITBUCKET_ID',
'OAUTH_BITBUCKET_SECRET',
),
array(
'OAUTH_BITLY_NAME',
'OAUTH_BITLY_ID',
'OAUTH_BITLY_SECRET',
),
array(
'OAUTH_BITRIX24_NAME',
'OAUTH_BITRIX24_ID',
'OAUTH_BITRIX24_SECRET',
),
array(
'OAUTH_BOX_NAME',
'OAUTH_BOX_ID',
'OAUTH_BOX_SECRET',
),
array(
'OAUTH_BUFFER_NAME',
'OAUTH_BUFFER_ID',
'OAUTH_BUFFER_SECRET',
),
array(
'OAUTH_DAILYMOTION_NAME',
'OAUTH_DAILYMOTION_ID',
'OAUTH_DAILYMOTION_SECRET',
),
array(
'OAUTH_DEVIANTART_NAME',
'OAUTH_DEVIANTART_ID',
'OAUTH_DEVIANTART_SECRET',
),
array(
'OAUTH_DROPBOX_NAME',
'OAUTH_DROPBOX_ID',
'OAUTH_DROPBOX_SECRET',
),
array(
'OAUTH_ETSY_NAME',
'OAUTH_ETSY_ID',
'OAUTH_ETSY_SECRET',
),
array(
'OAUTH_EVEONLINE_NAME',
'OAUTH_EVEONLINE_ID',
'OAUTH_EVEONLINE_SECRET',
),
array(
'OAUTH_FACEBOOK_NAME',
'OAUTH_FACEBOOK_ID',
'OAUTH_FACEBOOK_SECRET',
),
array(
'OAUTH_FITBIT_NAME',
'OAUTH_FITBIT_ID',
'OAUTH_FITBIT_SECRET',
),
array(
'OAUTH_FIVEHUNDREDPX_NAME',
'OAUTH_FIVEHUNDREDPX_ID',
'OAUTH_FIVEHUNDREDPX_SECRET',
),
array(
'OAUTH_FLICKR_NAME',
'OAUTH_FLICKR_ID',
'OAUTH_FLICKR_SECRET',
),
array(
'OAUTH_FOURSQUARE_NAME',
'OAUTH_FOURSQUARE_ID',
'OAUTH_FOURSQUARE_SECRET',
),
array(
'OAUTH_GITHUB_NAME',
'OAUTH_GITHUB_ID',
'OAUTH_GITHUB_SECRET',
),
array(
'OAUTH_GOOGLE_NAME',
'OAUTH_GOOGLE_ID',
'OAUTH_GOOGLE_SECRET',
'OAUTH_GOOGLE_DESC',
),
array(
'OAUTH_HUBIC_NAME',
'OAUTH_HUBIC_ID',
'OAUTH_HUBIC_SECRET',
),
array(
'OAUTH_INSTAGRAM_NAME',
'OAUTH_INSTAGRAM_ID',
'OAUTH_INSTAGRAM_SECRET',
),
array(
'OAUTH_LINKEDIN_NAME',
'OAUTH_LINKEDIN_ID',
'OAUTH_LINKEDIN_SECRET',
),
array(
'OAUTH_MAILCHIMP_NAME',
'OAUTH_MAILCHIMP_ID',
'OAUTH_MAILCHIMP_SECRET',
),
array(
'OAUTH_MICROSOFT_NAME',
'OAUTH_MICROSOFT_ID',
'OAUTH_MICROSOFT_SECRET',
),
array(
'OAUTH_NEST_NAME',
'OAUTH_NEST_ID',
'OAUTH_NEST_SECRET',
),
array(
'OAUTH_NETATMO_NAME',
'OAUTH_NETATMO_ID',
'OAUTH_NETATMO_SECRET',
),
array(
'OAUTH_PARROTFLOWERPOWER_NAME',
'OAUTH_PARROTFLOWERPOWER_ID',
'OAUTH_PARROTFLOWERPOWER_SECRET',
),
array(
'OAUTH_PAYPAL_NAME',
'OAUTH_PAYPAL_ID',
'OAUTH_PAYPAL_SECRET',
),
array(
'OAUTH_POCKET_NAME',
'OAUTH_POCKET_ID',
'OAUTH_POCKET_SECRET',
),
array(
'OAUTH_QUICKBOOKS_NAME',
'OAUTH_QUICKBOOKS_ID',
'OAUTH_QUICKBOOKS_SECRET',
),
array(
'OAUTH_REDDIT_NAME',
'OAUTH_REDDIT_ID',
'OAUTH_REDDIT_SECRET',
),
array(
'OAUTH_REDMINE_NAME',
'OAUTH_REDMINE_ID',
'OAUTH_REDMINE_SECRET',
),
array(
'OAUTH_RUNKEEPER_NAME',
'OAUTH_RUNKEEPER_ID',
'OAUTH_RUNKEEPER_SECRET',
),
array(
'OAUTH_SCOOPIT_NAME',
'OAUTH_SCOOPIT_ID',
'OAUTH_SCOOPIT_SECRET',
),
array(
'OAUTH_SOUNDCLOUD_NAME',
'OAUTH_SOUNDCLOUD_ID',
'OAUTH_SOUNDCLOUD_SECRET',
),
array(
'OAUTH_SPOTIFY_NAME',
'OAUTH_SPOTIFY_ID',
'OAUTH_SPOTIFY_SECRET',
),
array(
'OAUTH_STRAVA_NAME',
'OAUTH_STRAVA_ID',
'OAUTH_STRAVA_SECRET',
),
array(
'OAUTH_TUMBLR_NAME',
'OAUTH_TUMBLR_ID',
'OAUTH_TUMBLR_SECRET',
),
array(
'OAUTH_TWITTER_NAME',
'OAUTH_TWITTER_ID',
'OAUTH_TWITTER_SECRET',
),
array(
'OAUTH_USTREAM_NAME',
'OAUTH_USTREAM_ID',
'OAUTH_USTREAM_SECRET',
),
array(
'OAUTH_VIMEO_NAME',
'OAUTH_VIMEO_ID',
'OAUTH_VIMEO_SECRET',
),
array(
'OAUTH_YAHOO_NAME',
'OAUTH_YAHOO_ID',
'OAUTH_YAHOO_SECRET',
),
array(
'OAUTH_YAMMER_NAME',
'OAUTH_YAMMER_ID',
'OAUTH_YAMMER_SECRET',
),
);
/*
* Actions
@ -303,10 +84,9 @@ print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
/*
* Parameters
*/
dol_fiche_head(array(), '', '', 0, 'technic');
$head = oauthadmin_prepare_head();
dol_fiche_head($head, 'services', '', 0, 'technic');
print $langs->trans("ListOfSupportedOauthProviders").'<br><br>';
@ -314,14 +94,17 @@ print $langs->trans("ListOfSupportedOauthProviders").'<br><br>';
print '<table class="noborder" width="100%">';
$var = true;
$i=0;
foreach ($list as $key)
{
$supported=0;
if (in_array($key[0], array_keys($supportedoauth2array))) $supported=1;
if (! $supported) continue; // show only supported
print '<tr class="liste_titre">';
$i++;
print '<tr class="liste_titre'.($i > 1 ?' liste_titre_add':'').'">';
// Api Name
$label = $langs->trans($key[0]);
print '<td>'.$label.'</td>';

View File

@ -0,0 +1,275 @@
<?php
/* Copyright (C) 2013-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014-2015 Frederic France <frederic.france@free.fr>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/admin/oauthlogintoken.php
* \ingroup oauth
* \brief Setup page to configure oauth access to login information
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
use OAuth\Common\Storage\DoliStorage;
$langs->load("admin");
$langs->load("printing");
$langs->load("oauth");
if (! $user->admin) accessforbidden();
$action = GETPOST('action','alpha');
$mode = GETPOST('mode','alpha');
$value = GETPOST('value','alpha');
$varname = GETPOST('varname', 'alpha');
$driver = GETPOST('driver', 'alpha');
if (! empty($driver)) $langs->load($driver);
if (!$mode) $mode='setup';
/*
* Action
*/
/*if (($mode == 'test' || $mode == 'setup') && empty($driver))
{
setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null);
header("Location: ".$_SERVER['PHP_SELF'].'?mode=config');
exit;
}*/
if ($action == 'setconst' && $user->admin)
{
$error=0;
$db->begin();
foreach ($_POST['setupdriver'] as $setupconst) {
//print '<pre>'.print_r($setupconst, true).'</pre>';
$result=dolibarr_set_const($db, $setupconst['varname'],$setupconst['value'],'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
}
if (! $error)
{
$db->commit();
setEventMessages($langs->trans("SetupSaved"), null);
}
else
{
$db->rollback();
dol_print_error($db);
}
$action='';
}
if ($action == 'setvalue' && $user->admin)
{
$db->begin();
$result=dolibarr_set_const($db, $varname, $value,'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
if (! $error)
{
$db->commit();
setEventMessages($langs->trans("SetupSaved"), null);
}
else
{
$db->rollback();
dol_print_error($db);
}
$action = '';
}
/*
* View
*/
$form = new Form($db);
llxHeader('',$langs->trans("PrintingSetup"));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans('ConfigOAuth'),$linkback,'title_setup');
$head=oauthadmin_prepare_head($mode);
dol_fiche_head($head, 'tokengeneration', '', 0, 'technic');
if ($mode == 'setup' && $user->admin)
{
print $langs->trans("OAuthSetupForLogin")."<br><br>\n";
foreach($list as $key)
{
$supported=0;
if (in_array($key[0], array_keys($supportedoauth2array))) $supported=1;
if (! $supported) continue; // show only supported
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setconst">';
print '<table class="noborder" width="100%">'."\n";
$var=true;
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Parameters").'</th>';
print '<th>'.$langs->trans("Value").'</th>';
print '<th>&nbsp;</th>';
print "</tr>\n";
$submit_enabled=0;
print '<tr '.$bc[$var].'>';
print '<td'.($key['required']?' class=required':'').'>'.$langs->trans($key['varname']).'</td>';
print '<td>'.$langs->trans($key['info']).'</td>';
print '<td>';
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
{
// Delete remote tokens
if (! empty($key['delete'])) print '<a class="button" href="'.$key['delete'].'">'.$langs->trans('DeleteAccess').'</a><br><br>';
// Request remote token
print '<a class="button" href="'.$key['renew'].'">'.$langs->trans('RequestAccess').'</a><br><br>';
// Check remote access
print $langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME_GOOGLE).': <a href="https://security.google.com/settings/security/permissions" target="_google">https://security.google.com/settings/security/permissions</a>';
}
print '</td>';
print '</tr>'."\n";
// Show value of token
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
{
// Token
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("Token").'</td>';
print '<td>';
// Dolibarr storage
$storage = new DoliStorage($db, $conf);
try
{
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE);
}
catch(Exception $e)
{
// Return an error if token not found
}
if (is_object($tokenobj))
{
//var_dump($tokenobj);
print $tokenobj->getAccessToken().'<br>';
//print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
//print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
//var_dump($tokenobj->getExtraParams());
/*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
print ''.join(',',$tokenobj->getExtraParams());
print '</textarea>';*/
}
print '</td>';
print '<td>';
print '</td>';
print '</tr>'."\n";
}
print '</table>';
if (! empty($driver))
{
if ($submit_enabled) {
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'"></div>';
}
}
print '</form>';
}
}
if ($mode == 'test' && $user->admin)
{
print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
print '<table class="noborder" width="100%">';
if (! empty($driver))
{
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
$classname = 'printing_'.$driver;
$langs->load($driver);
$printer = new $classname($db);
//print '<pre>'.print_r($printer, true).'</pre>';
if (count($printer->getlist_available_printers())) {
if ($printer->listAvailablePrinters()==0) {
print $printer->resprint;
} else {
setEventMessages($printer->error, $printer->errors, 'errors');
}
}
else {
print $langs->trans('PleaseConfigureDriverfromList');
}
}
print '</table>';
}
if ($mode == 'userconf' && $user->admin)
{
print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
print '<table class="noborder" width="100%">';
$var=true;
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("User").'</th>';
print '<th>'.$langs->trans("PrintModule").'</th>';
print '<th>'.$langs->trans("PrintDriver").'</th>';
print '<th>'.$langs->trans("Printer").'</th>';
print '<th>'.$langs->trans("PrinterLocation").'</th>';
print '<th>'.$langs->trans("PrinterId").'</th>';
print '<th>'.$langs->trans("NumberOfCopy").'</th>';
print '<th class="center">'.$langs->trans("Delete").'</th>';
print "</tr>\n";
$sql = 'SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login FROM '.MAIN_DB_PREFIX.'printing as p, '.MAIN_DB_PREFIX.'user as u WHERE p.userid=u.rowid';
$resql = $db->query($sql);
while ($row=$db->fetch_array($resql)) {
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$row['login'].'</td>';
print '<td>'.$row['module'].'</td>';
print '<td>'.$row['driver'].'</td>';
print '<td>'.$row['printer_name'].'</td>';
print '<td>'.$row['printer_location'].'</td>';
print '<td>'.$row['printer_id'].'</td>';
print '<td>'.$row['copy'].'</td>';
print '<td class="center">'.img_picto($langs->trans("Delete"), 'delete').'</td>';
print "</tr>\n";
}
print '</table>';
}
dol_fiche_end();
llxFooter();
$db->close();

View File

@ -713,7 +713,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='
/**
* Show tab header of a card
*
* @param array $links Array of tabs
* @param array $links Array of tabs. Currently initialized by calling a function xxx_admin_prepare_head
* @param string $active Active tab name (document', 'info', 'ldap', ....)
* @param string $title Title
* @param int $notab 0=Add tab header, 1=no tab header. If you set this to 1, using dol_fiche_end() to close tab is not required.

View File

@ -0,0 +1,277 @@
<?php
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
* Copyright (C) 2013 Florian Henry <florian.henry@opn-concept.pro>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file core/lib/oauth.lib.php
* \brief Function for module Oauth
* \ingroup oauth
*/
// Supported OAUTH (a provider is supported when a file xxx_oauthcallback.php is available into htdocs/core/modules/oauth)
$supportedoauth2array=array(
'OAUTH_GOOGLE_NAME'=>'google',
'OAUTH_GITHUB_NAME'=>'github'
);
// API access parameters OAUTH
$list = array (
array(
'OAUTH_AMAZON_NAME',
'OAUTH_AMAZON_ID',
'OAUTH_AMAZON_SECRET',
),
array(
'OAUTH_BITBUCKET_NAME',
'OAUTH_BITBUCKET_ID',
'OAUTH_BITBUCKET_SECRET',
),
array(
'OAUTH_BITLY_NAME',
'OAUTH_BITLY_ID',
'OAUTH_BITLY_SECRET',
),
array(
'OAUTH_BITRIX24_NAME',
'OAUTH_BITRIX24_ID',
'OAUTH_BITRIX24_SECRET',
),
array(
'OAUTH_BOX_NAME',
'OAUTH_BOX_ID',
'OAUTH_BOX_SECRET',
),
array(
'OAUTH_BUFFER_NAME',
'OAUTH_BUFFER_ID',
'OAUTH_BUFFER_SECRET',
),
array(
'OAUTH_DAILYMOTION_NAME',
'OAUTH_DAILYMOTION_ID',
'OAUTH_DAILYMOTION_SECRET',
),
array(
'OAUTH_DEVIANTART_NAME',
'OAUTH_DEVIANTART_ID',
'OAUTH_DEVIANTART_SECRET',
),
array(
'OAUTH_DROPBOX_NAME',
'OAUTH_DROPBOX_ID',
'OAUTH_DROPBOX_SECRET',
),
array(
'OAUTH_ETSY_NAME',
'OAUTH_ETSY_ID',
'OAUTH_ETSY_SECRET',
),
array(
'OAUTH_EVEONLINE_NAME',
'OAUTH_EVEONLINE_ID',
'OAUTH_EVEONLINE_SECRET',
),
array(
'OAUTH_FACEBOOK_NAME',
'OAUTH_FACEBOOK_ID',
'OAUTH_FACEBOOK_SECRET',
),
array(
'OAUTH_FITBIT_NAME',
'OAUTH_FITBIT_ID',
'OAUTH_FITBIT_SECRET',
),
array(
'OAUTH_FIVEHUNDREDPX_NAME',
'OAUTH_FIVEHUNDREDPX_ID',
'OAUTH_FIVEHUNDREDPX_SECRET',
),
array(
'OAUTH_FLICKR_NAME',
'OAUTH_FLICKR_ID',
'OAUTH_FLICKR_SECRET',
),
array(
'OAUTH_FOURSQUARE_NAME',
'OAUTH_FOURSQUARE_ID',
'OAUTH_FOURSQUARE_SECRET',
),
array(
'OAUTH_GITHUB_NAME',
'OAUTH_GITHUB_ID',
'OAUTH_GITHUB_SECRET',
'OAUTH_GITHUB_DESC',
),
array(
'OAUTH_GOOGLE_NAME',
'OAUTH_GOOGLE_ID',
'OAUTH_GOOGLE_SECRET',
'OAUTH_GOOGLE_DESC',
),
array(
'OAUTH_HUBIC_NAME',
'OAUTH_HUBIC_ID',
'OAUTH_HUBIC_SECRET',
),
array(
'OAUTH_INSTAGRAM_NAME',
'OAUTH_INSTAGRAM_ID',
'OAUTH_INSTAGRAM_SECRET',
),
array(
'OAUTH_LINKEDIN_NAME',
'OAUTH_LINKEDIN_ID',
'OAUTH_LINKEDIN_SECRET',
),
array(
'OAUTH_MAILCHIMP_NAME',
'OAUTH_MAILCHIMP_ID',
'OAUTH_MAILCHIMP_SECRET',
),
array(
'OAUTH_MICROSOFT_NAME',
'OAUTH_MICROSOFT_ID',
'OAUTH_MICROSOFT_SECRET',
),
array(
'OAUTH_NEST_NAME',
'OAUTH_NEST_ID',
'OAUTH_NEST_SECRET',
),
array(
'OAUTH_NETATMO_NAME',
'OAUTH_NETATMO_ID',
'OAUTH_NETATMO_SECRET',
),
array(
'OAUTH_PARROTFLOWERPOWER_NAME',
'OAUTH_PARROTFLOWERPOWER_ID',
'OAUTH_PARROTFLOWERPOWER_SECRET',
),
array(
'OAUTH_PAYPAL_NAME',
'OAUTH_PAYPAL_ID',
'OAUTH_PAYPAL_SECRET',
),
array(
'OAUTH_POCKET_NAME',
'OAUTH_POCKET_ID',
'OAUTH_POCKET_SECRET',
),
array(
'OAUTH_QUICKBOOKS_NAME',
'OAUTH_QUICKBOOKS_ID',
'OAUTH_QUICKBOOKS_SECRET',
),
array(
'OAUTH_REDDIT_NAME',
'OAUTH_REDDIT_ID',
'OAUTH_REDDIT_SECRET',
),
array(
'OAUTH_REDMINE_NAME',
'OAUTH_REDMINE_ID',
'OAUTH_REDMINE_SECRET',
),
array(
'OAUTH_RUNKEEPER_NAME',
'OAUTH_RUNKEEPER_ID',
'OAUTH_RUNKEEPER_SECRET',
),
array(
'OAUTH_SCOOPIT_NAME',
'OAUTH_SCOOPIT_ID',
'OAUTH_SCOOPIT_SECRET',
),
array(
'OAUTH_SOUNDCLOUD_NAME',
'OAUTH_SOUNDCLOUD_ID',
'OAUTH_SOUNDCLOUD_SECRET',
),
array(
'OAUTH_SPOTIFY_NAME',
'OAUTH_SPOTIFY_ID',
'OAUTH_SPOTIFY_SECRET',
),
array(
'OAUTH_STRAVA_NAME',
'OAUTH_STRAVA_ID',
'OAUTH_STRAVA_SECRET',
),
array(
'OAUTH_TUMBLR_NAME',
'OAUTH_TUMBLR_ID',
'OAUTH_TUMBLR_SECRET',
),
array(
'OAUTH_TWITTER_NAME',
'OAUTH_TWITTER_ID',
'OAUTH_TWITTER_SECRET',
),
array(
'OAUTH_USTREAM_NAME',
'OAUTH_USTREAM_ID',
'OAUTH_USTREAM_SECRET',
),
array(
'OAUTH_VIMEO_NAME',
'OAUTH_VIMEO_ID',
'OAUTH_VIMEO_SECRET',
),
array(
'OAUTH_YAHOO_NAME',
'OAUTH_YAHOO_ID',
'OAUTH_YAHOO_SECRET',
),
array(
'OAUTH_YAMMER_NAME',
'OAUTH_YAMMER_ID',
'OAUTH_YAMMER_SECRET',
),
);
/**
* Return array of tabs to used on pages to setup cron module.
*
* @return array Array of tabs
*/
function oauthadmin_prepare_head()
{
global $langs, $conf, $user;
$h = 0;
$head = array();
$head[$h][0] = dol_buildpath('/admin/oauth.php', 1);
$head[$h][1] = $langs->trans("OAuthServices");
$head[$h][2] = 'services';
$h++;
$head[$h][0] = dol_buildpath('/admin/oauthlogintokens.php', 1);
$head[$h][1] = $langs->trans("ManualTokenGeneration");
$head[$h][2] = 'tokengeneration';
$h++;
complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin');
complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin', 'remove');
return $head;
}

View File

@ -452,7 +452,7 @@ class pdf_sepamandate extends ModeleBankAccountDoc
$pdf->SetXY($this->marge_gauche, $posy);
$pdf->SetFont('','', $default_font_size);
$pdf->MultiCell(100, 3, $outputlangs->trans("PleaseReturnMandate").':', 0, 'L', 0);
$pdf->MultiCell(100, 3, $outputlangs->trans("PleaseReturnMandate", $mysoc->email).':', 0, 'L', 0);
$posy=$pdf->GetY()+2;
$pdf->SetXY($this->marge_gauche, $posy);

View File

@ -123,7 +123,7 @@ if (! empty($_GET['code'])) // We are coming from Google oauth page
//var_dump($apiService); // OAuth\OAuth2\Service\Google
$token = $apiService->requestAccessToken($_GET['code'], $state);
setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs');
setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token
} catch (Exception $e) {
print $e->getMessage();
}

View File

@ -46,6 +46,8 @@ class printing_printgcp extends PrintingDriver
var $errors = array();
var $db;
private $OAUTH_SERVICENAME_GOOGLE = 'Google';
const LOGIN_URL = 'https://accounts.google.com/o/oauth2/token';
const PRINTERS_SEARCH_URL = 'https://www.google.com/cloudprint/search';
const PRINTERS_GET_JOBS = 'https://www.google.com/cloudprint/jobs';
@ -74,19 +76,19 @@ class printing_printgcp extends PrintingDriver
$this->google_secret = $conf->global->OAUTH_GOOGLE_SECRET;
// Token storage
$storage = new DoliStorage($this->db, $this->conf);
//$storage->clearToken('Google');
//$storage->clearToken($this->OAUTH_SERVICENAME_GOOGLE);
// Setup the credentials for the requests
$credentials = new Credentials(
$this->google_id,
$this->google_secret,
$urlwithroot.'/core/modules/oauth/google_oauthcallback.php'
);
$access = ($storage->hasAccessToken('Google')?'HasAccessToken':'NoAccessToken');
$access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?'HasAccessToken':'NoAccessToken');
$serviceFactory = new \OAuth\ServiceFactory();
$apiService = $serviceFactory->createService('Google', $credentials, $storage, array());
$apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array());
$token_ok=true;
try {
$token = $storage->retrieveAccessToken('Google');
$token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$token_ok = false;
@ -106,24 +108,24 @@ class printing_printgcp extends PrintingDriver
$refreshtoken = $token->getRefreshToken();
$token = $apiService->refreshAccessToken($token);
$token->setRefreshToken($refreshtoken);
$storage->storeAccessToken('Google', $token);
$storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
}
if ($this->google_id != '' && $this->google_secret != '') {
$this->conf[] = array('varname'=>'PRINTGCP_INFO', 'info'=>'GoogleAuthConfigured', 'type'=>'info');
$this->conf[] = array('varname'=>'PRINTGCP_TOKEN_ACCESS', 'info'=>$access, 'type'=>'info', 'renew'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?state=userinfo_email,userinfo_profile,cloud_print&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'delete'=>($storage->hasAccessToken('Google')?$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'):''));
$this->conf[] = array('varname'=>'PRINTGCP_TOKEN_ACCESS', 'info'=>$access, 'type'=>'info', 'renew'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?state=userinfo_email,userinfo_profile,cloud_print&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'delete'=>($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'):''));
if ($token_ok) {
$refreshtoken = $token->getRefreshToken();
$this->conf[] = array('varname'=>'PRINTGCP_TOKEN_REFRESH', 'info'=>((! empty($refreshtoken))?'Yes':'No'), 'type'=>'info');
$this->conf[] = array('varname'=>'PRINTGCP_TOKEN_EXPIRED', 'info'=>($expire?'Yes':'No'), 'type'=>'info');
$this->conf[] = array('varname'=>'PRINTGCP_TOKEN_EXPIRE_AT', 'info'=>(dol_print_date($token->getEndOfLife(), "dayhour")), 'type'=>'info');
$this->conf[] = array('varname'=>'TOKEN_REFRESH', 'info'=>((! empty($refreshtoken))?'Yes':'No'), 'type'=>'info');
$this->conf[] = array('varname'=>'TOKEN_EXPIRED', 'info'=>($expire?'Yes':'No'), 'type'=>'info');
$this->conf[] = array('varname'=>'TOKEN_EXPIRE_AT', 'info'=>(dol_print_date($token->getEndOfLife(), "dayhour")), 'type'=>'info');
}
/*
if ($storage->hasAccessToken('Google')) {
if ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)) {
$this->conf[] = array('varname'=>'PRINTGCP_AUTHLINK', 'link'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'type'=>'authlink');
$this->conf[] = array('varname'=>'PRINTGCP_DELETE_TOKEN', 'link'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'type'=>'delete');
$this->conf[] = array('varname'=>'DELETE_TOKEN', 'link'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'type'=>'delete');
} else {
$this->conf[] = array('varname'=>'PRINTGCP_AUTHLINK', 'link'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'type'=>'authlink');
}*/
@ -203,11 +205,11 @@ class printing_printgcp extends PrintingDriver
DOL_MAIN_URL_ROOT.'/core/modules/oauth/google_oauthcallback.php'
);
$serviceFactory = new \OAuth\ServiceFactory();
$apiService = $serviceFactory->createService('Google', $credentials, $storage, array());
$apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array());
// Check if we have auth token
$token_ok=true;
try {
$token = $storage->retrieveAccessToken('Google');
$token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$token_ok = false;
@ -225,7 +227,7 @@ class printing_printgcp extends PrintingDriver
$refreshtoken = $token->getRefreshToken();
$token = $apiService->refreshAccessToken($token);
$token->setRefreshToken($refreshtoken);
$storage->storeAccessToken('Google', $token);
$storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
@ -341,12 +343,12 @@ class printing_printgcp extends PrintingDriver
DOL_MAIN_URL_ROOT.'/core/modules/oauth/google_oauthcallback.php?service=google'
);
$serviceFactory = new \OAuth\ServiceFactory();
$apiService = $serviceFactory->createService('Google', $credentials, $storage, array());
$apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array());
// Check if we have auth token and refresh it
$token_ok=true;
try {
$token = $storage->retrieveAccessToken('Google');
$token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$token_ok = false;
@ -357,7 +359,7 @@ class printing_printgcp extends PrintingDriver
$refreshtoken = $token->getRefreshToken();
$token = $apiService->refreshAccessToken($token);
$token->setRefreshToken($refreshtoken);
$storage->storeAccessToken('Google', $token);
$storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
@ -390,11 +392,11 @@ class printing_printgcp extends PrintingDriver
DOL_MAIN_URL_ROOT.'/core/modules/oauth/google_oauthcallback.php'
);
$serviceFactory = new \OAuth\ServiceFactory();
$apiService = $serviceFactory->createService('Google', $credentials, $storage, array());
$apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array());
// Check if we have auth token
$token_ok=true;
try {
$token = $storage->retrieveAccessToken('Google');
$token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$token_ok = false;
@ -413,7 +415,7 @@ class printing_printgcp extends PrintingDriver
$refreshtoken = $token->getRefreshToken();
$token = $apiService->refreshAccessToken($token);
$token->setRefreshToken($refreshtoken);
$storage->storeAccessToken('Google', $token);
$storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$error++;

View File

@ -128,6 +128,7 @@ class DoliStorage implements TokenStorageInterface
public function hasAccessToken($service)
{
// get from db
dol_syslog("hasAccessToken service=".$service);
$sql = "SELECT token FROM ".MAIN_DB_PREFIX."oauth_token";
$sql.= " WHERE service='".$service."'";
$resql = $this->db->query($sql);

View File

@ -1,5 +1,7 @@
# Dolibarr language file - Source file is en_US - oauth
ConfigOAuth=Oauth Configuration
OAuthServices=OAuth services
ManualTokenGeneration=Manual token generation
NoAccessToken=No access token saved into local database
HasAccessToken=A token was generated and saved into local database
NewTokenStored=Token received ans saved
@ -9,7 +11,16 @@ RequestAccess=Click here to request/renew access and receive a new token to save
DeleteAccess=Click here to delete token
UseTheFollowingUrlAsRedirectURI=Use the following URL as the Redirect URI when creating your credential on your OAuth provider:
ListOfSupportedOauthProviders=Enter here credential provided by your OAuth2 provider. Only supported OAuth2 providers are visible here. This setup may be used by other modules that need OAuth2 authentication.
OAUTH_GOOGLE_NAME=Api Google
OAUTH_GOOGLE_ID=Api Google Id
OAUTH_GOOGLE_SECRET=Api Google Secret
OAUTH_GOOGLE_DESC=Go on <a href="https://console.developers.google.com/" target="_blank">this page</a> then Credentials to create Oauth credentials
TOKEN_ACCESS=
TOKEN_REFRESH=Token Refresh Present
TOKEN_EXPIRED=Token expired
TOKEN_EXPIRE_AT=Token expire at
TOKEN_DELETE=Delete saved token
OAUTH_GOOGLE_NAME=Oauth Google service
OAUTH_GOOGLE_ID=Oauth Google Id
OAUTH_GOOGLE_SECRET=Oauth Google Secret
OAUTH_GOOGLE_DESC=Go on <a class="notasortlink" href="https://console.developers.google.com/" target="_blank">this page</a> then "Credentials" to create Oauth credentials
OAUTH_GITHUB_NAME=Oauth GitHub service
OAUTH_GITHUB_ID=Oauth GitHub Id
OAUTH_GITHUB_SECRET=Oauth GitHub Secret
OAUTH_GITHUB_DESC=Go on <a class="notasortlink" href="https://github.com/settings/developers" target="_blank">this page</a> then "Register a new application" to create Oauth credentials

View File

@ -18,10 +18,6 @@ UserConf=Setup per user
PRINTGCP_INFO=Google OAuth API setup
PRINTGCP_AUTHLINK=Authentication
PRINTGCP_TOKEN_ACCESS=Google Cloud Print OAuth Token
PRINTGCP_TOKEN_REFRESH=Token Refresh Present
PRINTGCP_TOKEN_EXPIRED=Token Expired
PRINTGCP_TOKEN_EXPIRE_AT=Token expire at
PRINTGCP_DELETE_TOKEN=Delete saved token
PrintGCPDesc=This driver allow to send documents directly to a printer with Google Cloud Print.
GCP_Name=Name
GCP_displayName=Display Name

View File

@ -80,7 +80,7 @@ WithdrawRequestAmount=Withdraw request amount:
WithdrawRequestErrorNilAmount=Unable to create withdraw request for nil amount.
SepaMandate=SEPA Direct Debit Mandate
SepaMandateShort=SEPA Mandate
PleaseReturnMandate=Please return this mandate form to
PleaseReturnMandate=Please return this mandate form by email to %s or by mail to
SEPALegalText=By signing this mandate form, you authorize (A) %s to send instructions to your bank to debit your account and (B) your bank to debit your account in accordance with the instructions from %s. As part of your rights, you are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited. Your rights regarding the above mandate are explained in a statement that you can obtain from your bank.
CreditorIdentifier=Creditor Identifier
CreditorName=Creditors Name

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2013-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014-2015 Frederic France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -28,6 +28,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
require_once DOL_DOCUMENT_ROOT.'/printing/lib/printing.lib.php';
use OAuth\Common\Storage\DoliStorage;
$langs->load("admin");
$langs->load("printing");
@ -45,6 +46,8 @@ if (! empty($driver)) $langs->load($driver);
if (!$mode) $mode='config';
$OAUTH_SERVICENAME_GOOGLE = 'Google';
/*
* Action
@ -100,6 +103,7 @@ if ($action == 'setvalue' && $user->admin)
$action = '';
}
/*
* View
*/
@ -138,7 +142,6 @@ if ($mode == 'setup' && $user->admin)
$classname = 'printing_'.$driver;
$langs->load($driver);
$printer = new $classname($db);
//var_dump($printer);
$i=0;
$submit_enabled=0;
@ -163,9 +166,12 @@ if ($mode == 'setup' && $user->admin)
print '<td>';
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
{
// Delete remote tokens
if (! empty($key['delete'])) print '<a class="button" href="'.$key['delete'].'">'.$langs->trans('DeleteAccess').'</a><br><br>';
// Request remote token
print '<a class="button" href="'.$key['renew'].'">'.$langs->trans('RequestAccess').'</a><br><br>';
print $langs->trans("ToCheckDeleteTokenOnProvider", 'Google').': <a href="https://security.google.com/settings/security/permissions" target="_google">https://security.google.com/settings/security/permissions</a>';
// Check remote access
print $langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME_GOOGLE).': <a href="https://security.google.com/settings/security/permissions" target="_google">https://security.google.com/settings/security/permissions</a>';
}
print '</td>';
print '</tr>'."\n";
@ -175,6 +181,39 @@ if ($mode == 'setup' && $user->admin)
break;
}
$i++;
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
{
// Token
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("Token").'</td>';
print '<td>';
// Dolibarr storage
$storage = new DoliStorage($db, $conf);
try
{
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE);
}
catch(Exception $e)
{
// Return an error if token not found
}
if (is_object($tokenobj))
{
//var_dump($tokenobj);
print $tokenobj->getAccessToken().'<br>';
//print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
//print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
//var_dump($tokenobj->getExtraParams());
/*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
print ''.join(',',$tokenobj->getExtraParams());
print '</textarea>';*/
}
print '</td>';
print '<td>';
print '</td>';
print '</tr>'."\n";
}
}
} else {
print $langs->trans('PleaseSelectaDriverfromList');