33require
'../../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
44use OAuth\Common\Storage\DoliStorage;
45use OAuth\Common\Consumer\Credentials;
49$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
52$action =
GETPOST(
'action',
'aZ09');
53$backtourl =
GETPOST(
'backtourl',
'alpha');
54$keyforprovider =
GETPOST(
'keyforprovider',
'aZ09');
55if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
56 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
58$genericstring =
'MICROSOFT3';
67$currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/microsoft3_oauthcallback.php');
75$serviceFactory = new \OAuth\ServiceFactory();
76$httpClient = new \OAuth\Common\Http\Client\CurlClient();
78$serviceFactory->setHttpClient($httpClient);
81$keyforparamid =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
82$keyforparamsecret =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
83$keyforparamtenant =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_TENANT';
86$storage =
new DoliStorage($db, $conf, $keyforprovider,
getDolGlobalString($keyforparamtenant));
88$credentials =
new Credentials(
91 $currentUri->getAbsoluteUri()
96$requestedpermissionsarray = array();
98 $requestedpermissionsarray = explode(
',', $state);
100if ($action !=
'delete' && empty($requestedpermissionsarray)) {
101 print
'Error, parameter state is not defined';
106 $nameofservice = ucfirst(strtolower($genericstring));
107 $apiService = $serviceFactory->createService($nameofservice, $credentials, $storage, $requestedpermissionsarray);
108 '@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService';
110 print $e->getMessage();
114if (empty($apiService)) {
115 print
'Error, failed to create serviceFactory';
119$langs->load(
"oauth");
122 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
125 accessforbidden(
'Setup of service is not complete. Secret key is missing');
128 accessforbidden(
'Setup of service is not complete. Tenant/Annuary ID key is missing');
135if ($action ==
'delete' && (!empty($user->admin) || $user->id ==
GETPOSTINT(
'userid'))) {
137 $storage->clearToken($genericstring);
141 if (empty($backtourl)) {
142 $backtourl = DOL_URL_ROOT.
'/';
145 header(
'Location: '.$backtourl);
156 if (isset($_SESSION[
'oauthstateanticsrf']) && $state != $_SESSION[
'oauthstateanticsrf']) {
158 unset($_SESSION[
'oauthstateanticsrf']);
167 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
171 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
172 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
174 header(
'Location: '.$backtourl);
177 print $e->getMessage();
182 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
183 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
184 $_SESSION[
'oauthstateanticsrf'] = $state;
188 $params = array(
'prompt' =>
'consent');
190 $params[
'state'] = $state;
192 $url = $apiService->getAuthorizationUri($params);
198 header(
'Location: '.$url);
global $dolibarr_main_url_root
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
$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.