diff --git a/htdocs/admin/oauth.php b/htdocs/admin/oauth.php
index aab05bd4c56..66878753b46 100644
--- a/htdocs/admin/oauth.php
+++ b/htdocs/admin/oauth.php
@@ -27,6 +27,13 @@ require '../main.inc.php';
// required Class
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
+
+// Define $urlwithroot
+$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
+$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
+//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
+
+
$langs->load("admin");
$langs->load("oauth");
@@ -36,6 +43,8 @@ if (!$user->admin)
$action = GETPOST('action', 'alpha');
+// Supported OAUTH
+$supportedoauth2array=array('OAUTH_GOOGLE_NAME');
// API access parameters OAUTH
$list = array (
array(
@@ -297,11 +306,7 @@ print '';
dol_fiche_head(array(), '', '', 0, 'technic');
-// Define $urlwithroot
-$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
-$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
-//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
-
+print $langs->trans("ListOfSupportedOauthProviders").'
';
print '
';
@@ -309,12 +314,16 @@ $var = true;
foreach ($list as $key)
{
+ $supported=0;
+ if (in_array($key[0], $supportedoauth2array)) $supported=1;
+ if (! $supported) continue; // show only supported
+
print '
';
// Api Name
$label = $langs->trans($key[0]);
print '
'.$label.'
';
- if (in_array($key[0], array('OAUTH_GOOGLE_NAME')))
+ if ($supported)
{
$redirect_uri=$urlwithroot.'/core/modules/oauth/getgoogleoauthcallback.php';
$var = !$var;
diff --git a/htdocs/core/lib/geturl.lib.php b/htdocs/core/lib/geturl.lib.php
index 682ddb1b1d1..83c67509dcc 100644
--- a/htdocs/core/lib/geturl.lib.php
+++ b/htdocs/core/lib/geturl.lib.php
@@ -101,7 +101,7 @@ function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addhea
curl_setopt($ch, CURLOPT_POST, 0); // GET
}
- //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
+ //if USE_PROXY constant set at begin of this method.
if ($USE_PROXY)
{
dol_syslog("getURLContent set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
diff --git a/htdocs/core/modules/modOauth.class.php b/htdocs/core/modules/modOauth.class.php
index c77ab6de68e..35be63a5c59 100644
--- a/htdocs/core/modules/modOauth.class.php
+++ b/htdocs/core/modules/modOauth.class.php
@@ -51,7 +51,7 @@ class modOauth extends DolibarrModules
$this->name = preg_replace('/^mod/i','',get_class($this));
// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
$this->description = "Enable OAuth authentication";
- $this->version = 'development'; // 'development' or 'experimental' or 'dolibarr' or version
+ $this->version = 'dolibarr'; // 'development' or 'experimental' or 'dolibarr' or version
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
// Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
$this->special = 1;
diff --git a/htdocs/core/modules/oauth/getgoogleoauthcallback.php b/htdocs/core/modules/oauth/getgoogleoauthcallback.php
index f1e0ddd03f3..e159198314c 100644
--- a/htdocs/core/modules/oauth/getgoogleoauthcallback.php
+++ b/htdocs/core/modules/oauth/getgoogleoauthcallback.php
@@ -30,14 +30,25 @@ use OAuth\Common\Consumer\Credentials;
use OAuth\Common\Token\TokenInterface;
use OAuth\OAuth2\Service\Google;
+// Define $urlwithroot
+$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
+$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
+//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
+
+
+
$action = GETPOST('action', 'alpha');
+$backtourl = GETPOST('backtourl', 'alpha');
+
/**
* Create a new instance of the URI class with the current URI, stripping the query string
*/
$uriFactory = new \OAuth\Common\Http\Uri\UriFactory();
-$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
-$currentUri->setQuery('');
+//$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
+//$currentUri->setQuery('');
+$currentUri = $uriFactory->createFromAbsolute($urlwithroot.'/core/modules/oauth/getgoogleoauthcallback.php');
+
/**
* Load the credential for the service
@@ -45,8 +56,15 @@ $currentUri->setQuery('');
/** @var $serviceFactory \OAuth\ServiceFactory An OAuth service factory. */
$serviceFactory = new \OAuth\ServiceFactory();
+$httpClient = new \OAuth\Common\Http\Client\CurlClient();
+// TODO Set options for proxy and timeout
+// $params=array('CURLXXX'=>value, ...)
+//$httpClient->setCurlParameters($params);
+$serviceFactory->setHttpClient($httpClient);
+
// Dolibarr storage
$storage = new DoliStorage($db, $conf);
+
// Setup the credentials for the requests
$credentials = new Credentials(
$conf->global->OAUTH_GOOGLE_ID,
@@ -54,6 +72,7 @@ $credentials = new Credentials(
$currentUri->getAbsoluteUri()
);
+
// Instantiate the Api service using the credentials, http client and storage mechanism for the token
/** @var $apiService Service */
// TODO remove hardcoded array
@@ -61,80 +80,71 @@ $apiService = $serviceFactory->createService('Google', $credentials, $storage, a
// access type needed for google refresh token
$apiService->setAccessType('offline');
-if ($action == 'delete') {
- // delete token
- llxHeader('',$langs->trans("OAuthSetup"));
- $linkback=''.$langs->trans("BackToModuleList").'';
- print load_fiche_titre($langs->trans("OAuthSetup"),$linkback,'title_setup');
- dol_fiche_head();
+$langs->load("oauth");
+
+
+/*
+ * Actions
+ */
+
+
+if ($action == 'delete')
+{
$storage->clearToken('Google');
- dol_fiche_end();
+
+ setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs');
+
+ header('Location: ' . $backtourl);
+ exit();
+}
+if (! empty($_GET['code'])) // We are coming from Google oauth page
+{
+ //llxHeader('',$langs->trans("OAuthSetup"));
-} elseif (! empty($_GET['code'])) {
- llxHeader('',$langs->trans("OAuthSetup"));
+ //$linkback=''.$langs->trans("BackToModuleList").'';
+ //print load_fiche_titre($langs->trans("OAuthSetup"),$linkback,'title_setup');
- $linkback=''.$langs->trans("BackToModuleList").'';
- print load_fiche_titre($langs->trans("OAuthSetup"),$linkback,'title_setup');
-
- dol_fiche_head();
+ //dol_fiche_head();
// retrieve the CSRF state parameter
$state = isset($_GET['state']) ? $_GET['state'] : null;
- print '