26require
'../../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
28use OAuth\Common\Storage\DoliStorage;
29use OAuth\Common\Consumer\Credentials;
30use OAuth\OAuth2\Service\GitHub;
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 =
'MICROSOFT';
53$currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/microsoft_oauthcallback.php');
61$serviceFactory = new \OAuth\ServiceFactory();
62$httpClient = new \OAuth\Common\Http\Client\CurlClient();
66$serviceFactory->setHttpClient($httpClient);
69$storage =
new DoliStorage($db, $conf, $keyforprovider);
72$keyforparamid =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
73$keyforparamsecret =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
74$keyforparamtenant =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_TENANT';
75$credentials =
new Credentials(
78 $currentUri->getAbsoluteUri()
83$requestedpermissionsarray = array();
85 $requestedpermissionsarray = explode(
',', $state);
87if ($action !=
'delete' && empty($requestedpermissionsarray)) {
88 print
'Error, parameter state is not defined';
98 $apiService = $serviceFactory->createService(ucfirst(strtolower($genericstring)), $credentials, $storage, $requestedpermissionsarray);
100 print $e->getMessage();
110if (empty($apiService)) {
111 print
'Error, failed to create serviceFactory';
118$langs->load(
"oauth");
121 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
124 accessforbidden(
'Setup of service is not complete. Secret key is missing');
132if ($action ==
'delete') {
133 $storage->clearToken($genericstring);
137 if (empty($backtourl)) {
138 $backtourl = DOL_URL_ROOT.
'/';
141 header(
'Location: '.$backtourl);
165 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
175 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
176 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
178 header(
'Location: '.$backtourl);
181 print $e->getMessage();
186 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
187 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
188 $_SESSION[
'oauthstateanticsrf'] = $state;
197 $url = $apiService->getAuthorizationUri(array(
'state' => $state));
199 $url = $apiService->getAuthorizationUri();
207 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.