26require
'../../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
28use OAuth\Common\Storage\DoliStorage;
29use OAuth\Common\Consumer\Credentials;
32$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
33$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
37$action =
GETPOST(
'action',
'aZ09');
38$backtourl =
GETPOST(
'backtourl',
'alpha');
39$keyforprovider =
GETPOST(
'keyforprovider',
'aZ09');
40if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
41 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
43$genericstring =
'GENERIC';
52$currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/generic_oauthcallback.php');
60$serviceFactory = new \OAuth\ServiceFactory();
61$httpClient = new \OAuth\Common\Http\Client\CurlClient();
65$serviceFactory->setHttpClient($httpClient);
68$storage =
new DoliStorage($db, $conf, $keyforprovider);
71$keyforparamid =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
72$keyforparamsecret =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
73$credentials =
new Credentials(
76 $currentUri->getAbsoluteUri()
81$requestedpermissionsarray = array();
83 $requestedpermissionsarray = explode(
',', $state);
85if ($action !=
'delete' && empty($requestedpermissionsarray)) {
86 print
'Error, parameter state is not defined';
93$apiService = $serviceFactory->createService(ucfirst(strtolower($genericstring)), $credentials, $storage, $requestedpermissionsarray);
102if (empty($apiService)) {
103 print
'Error, failed to create serviceFactory';
110$langs->load(
"oauth");
113 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
116 accessforbidden(
'Setup of service is not complete. Secret key is missing');
124if ($action ==
'delete') {
125 $storage->clearToken($genericstring);
129 if (empty($backtourl)) {
130 $backtourl = DOL_URL_ROOT.
'/';
133 header(
'Location: '.$backtourl);
152 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
157 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
158 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
160 header(
'Location: '.$backtourl);
163 print $e->getMessage();
168 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
169 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
170 $_SESSION[
'oauthstateanticsrf'] = $state;
175 $url = $apiService->getAuthorizationUri(array(
'state' => $state));
177 $url = $apiService->getAuthorizationUri();
181 header(
'Location: '.$url);
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$uriFactory
Create a new instance of the URI class with the current URI, stripping the query string.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.