25 require
'../../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
27 use OAuth\Common\Storage\DoliStorage;
28 use OAuth\Common\Consumer\Credentials;
29 use OAuth\OAuth2\Service\GitHub;
32 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
33 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
38 $action =
GETPOST(
'action',
'aZ09');
39 $backtourl =
GETPOST(
'backtourl',
'alpha');
48 $currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/github_oauthcallback.php');
56 $serviceFactory = new \OAuth\ServiceFactory();
57 $httpClient = new \OAuth\Common\Http\Client\CurlClient();
61 $serviceFactory->setHttpClient($httpClient);
64 $storage =
new DoliStorage($db, $conf);
67 $credentials =
new Credentials(
68 $conf->global->OAUTH_GITHUB_ID,
69 $conf->global->OAUTH_GITHUB_SECRET,
70 $currentUri->getAbsoluteUri()
73 $requestedpermissionsarray = array();
74 if (
GETPOST(
'state')) $requestedpermissionsarray = explode(
',',
GETPOST(
'state'));
75 if ($action !=
'delete' && empty($requestedpermissionsarray))
77 print 'Error, parameter state is not defined';
83 $apiService = $serviceFactory->createService(
'GitHub', $credentials, $storage, $requestedpermissionsarray);
88 $langs->load(
"oauth");
95 if ($action ==
'delete')
97 $storage->clearToken(
'GitHub');
101 header(
'Location: '.$backtourl);
105 if (!empty($_GET[
'code']))
110 dol_syslog(
"We are coming from the oauth provider page");
118 $state = isset($_GET[
'state']) ? $_GET[
'state'] : null;
128 $token = $apiService->requestAccessToken($_GET[
'code']);
136 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
137 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
139 header(
'Location: '.$backtourl);
142 print $e->getMessage();
146 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
152 $url = $apiService->getAuthorizationUri(array(
'state'=>
GETPOST(
'state')));
154 $url = $apiService->getAuthorizationUri();
158 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= '')
Set event messages in dol_events session object.
$uriFactory
Create a new instance of the URI class with the current URI, stripping the query string.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.