26 require
'../../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
28 use OAuth\Common\Storage\DoliStorage;
29 use OAuth\Common\Consumer\Credentials;
30 use 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');
41 if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
42 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
44 $genericstring =
'OTHER';
53 $currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/generic_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);
72 $keyforparamid =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
73 $keyforparamsecret =
'OAUTH_'.$genericstring.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
74 $credentials =
new Credentials(
77 $currentUri->getAbsoluteUri()
80 $requestedpermissionsarray = array();
82 $requestedpermissionsarray = explode(
',',
GETPOST(
'state'));
84 if ($action !=
'delete' && empty($requestedpermissionsarray)) {
85 print
'Error, parameter state is not defined';
91 $apiService = $serviceFactory->createService($genericstring, $credentials, $storage, $requestedpermissionsarray);
100 if (empty($apiService)) {
101 print
'Error, failed to create serviceFactory';
108 $langs->load(
"oauth");
111 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
114 accessforbidden(
'Setup of service is not complete. Secret key is missing');
122 if ($action ==
'delete') {
123 $storage->clearToken($genericstring);
127 header(
'Location: '.$backtourl);
135 dol_syslog(
"We are coming from the oauth provider page");
153 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
161 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
162 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
164 header(
'Location: '.$backtourl);
167 print $e->getMessage();
170 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
171 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
172 $_SESSION[
'oauthstateanticsrf'] = $state;
177 $url = $apiService->getAuthorizationUri(array(
'state' =>
GETPOST(
'state')));
179 $url = $apiService->getAuthorizationUri();
183 header(
'Location: '.$url);
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.