27require
'../../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
29use OAuth\Common\Storage\DoliStorage;
30use OAuth\Common\Consumer\Credentials;
33$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
34$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
38$action =
GETPOST(
'action',
'aZ09');
39$backtourl =
GETPOST(
'backtourl',
'alpha');
40$keyforprovider =
GETPOST(
'keyforprovider',
'aZ09');
41if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
42 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
44$genericstring =
'MICROSOFT2';
54$currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/microsoft2_oauthcallback.php');
62$serviceFactory = new \OAuth\ServiceFactory();
63$httpClient = new \OAuth\Common\Http\Client\CurlClient();
67$serviceFactory->setHttpClient($httpClient);
70$keyforparamid =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
71$keyforparamsecret =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
72$keyforparamtenant =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_TENANT';
75$storage =
new DoliStorage($db, $conf, $keyforprovider,
getDolGlobalString($keyforparamtenant));
77$credentials =
new Credentials(
80 $currentUri->getAbsoluteUri()
86$requestedpermissionsarray = array();
88 $requestedpermissionsarray = explode(
',', $state);
90if ($action !=
'delete' && empty($requestedpermissionsarray)) {
91 print
'Error, parameter state is not defined';
101 $nameofservice = ucfirst(strtolower($genericstring));
102 $apiService = $serviceFactory->createService($nameofservice, $credentials, $storage, $requestedpermissionsarray);
103 '@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService';
105 print $e->getMessage();
115if (empty($apiService)) {
116 print
'Error, failed to create serviceFactory';
123$langs->load(
"oauth");
126 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
129 accessforbidden(
'Setup of service is not complete. Secret key is missing');
132 accessforbidden(
'Setup of service is not complete. Tenant/Annuary ID key is missing');
140if ($action ==
'delete' && (!empty($user->admin) || $user->id ==
GETPOSTINT(
'userid'))) {
142 $storage->clearToken($genericstring);
146 if (empty($backtourl)) {
147 $backtourl = DOL_URL_ROOT.
'/';
150 header(
'Location: '.$backtourl);
174 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
184 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
185 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
187 header(
'Location: '.$backtourl);
190 print $e->getMessage();
195 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
196 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
197 $_SESSION[
'oauthstateanticsrf'] = $state;
206 $url = $apiService->getAuthorizationUri(array(
'state' => $state));
208 $url = $apiService->getAuthorizationUri();
216 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.
$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.