27require
'../../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
38use OAuth\Common\Storage\DoliStorage;
39use OAuth\Common\Consumer\Credentials;
42$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
43$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
47$action =
GETPOST(
'action',
'aZ09');
48$backtourl =
GETPOST(
'backtourl',
'alpha');
49$keyforprovider =
GETPOST(
'keyforprovider',
'aZ09');
50if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
51 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
53$genericstring =
'MICROSOFT';
61$currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/microsoft_oauthcallback.php');
69$serviceFactory = new \OAuth\ServiceFactory();
70$httpClient = new \OAuth\Common\Http\Client\CurlClient();
74$serviceFactory->setHttpClient($httpClient);
77$keyforparamid =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
78$keyforparamsecret =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
79$keyforparamtenant =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_TENANT';
84$credentials =
new Credentials(
87 $currentUri->getAbsoluteUri()
92$requestedpermissionsarray = array();
94 $requestedpermissionsarray = explode(
',', $state);
96if ($action !=
'delete' && empty($requestedpermissionsarray)) {
97 print
'Error, parameter state is not defined';
107 $nameofservice = ucfirst(strtolower($genericstring));
108 $apiService = $serviceFactory->createService($nameofservice, $credentials, $storage, $requestedpermissionsarray);
109 '@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService';
111 print $e->getMessage();
121if (empty($apiService)) {
122 print
'Error, failed to create serviceFactory';
129$langs->load(
"oauth");
132 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
135 accessforbidden(
'Setup of service is not complete. Secret key is missing');
138 accessforbidden(
'Setup of service is not complete. Tenant/Annuary ID key is missing');
146if ($action ==
'delete' && (!empty($user->admin) || $user->id ==
GETPOSTINT(
'userid'))) {
148 $storage->clearToken($genericstring);
152 if (empty($backtourl)) {
153 $backtourl = DOL_URL_ROOT.
'/';
156 header(
'Location: '.$backtourl);
180 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
190 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
191 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
193 header(
'Location: '.$backtourl);
196 print $e->getMessage();
201 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
202 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
203 $_SESSION[
'oauthstateanticsrf'] = $state;
212 $url = $apiService->getAuthorizationUri(array(
'state' => $state));
214 $url = $apiService->getAuthorizationUri();
222 header(
'Location: '.$url);
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$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.