dolibarr 21.0.0-beta
openid_connect.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2023 Maximilien Rozniecki <mrozniecki@easya.solutions>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/openid_connect.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/openid_connect.lib.php';
31
40$langs->load("admin");
41$langs->load("openidconnect");
42
43if (!$user->admin) accessforbidden();
44
45$action = GETPOST('action', 'alpha');
46
47
48/*
49 * Actions
50 */
51
52$errors = [];
53$error = 0;
54
55if ($action == 'set') {
56 $client_id = GETPOST('MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM', 'alpha');
57 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM', $client_id, 'chaine', 0, '', 0);
58 if (!$res > 0) {
59 $errors[] = $db->lasterror();
60 $error++;
61 }
62
63 $client_id = GETPOST('MAIN_AUTHENTICATION_OIDC_CLIENT_ID', 'alpha');
64 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_CLIENT_ID', $client_id, 'chaine', 0, '', 0);
65 if (!$res > 0) {
66 $errors[] = $db->lasterror();
67 $error++;
68 }
69
70 $client_secret = GETPOST('MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET', 'alpha');
71 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET', $client_secret, 'chaine', 0, '', 0);
72 if (!$res > 0) {
73 $errors[] = $db->lasterror();
74 $error++;
75 }
76
77 $scopes = GETPOST('MAIN_AUTHENTICATION_OIDC_SCOPES', 'alpha');
78 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_SCOPES', $scopes, 'chaine', 0, '', 0);
79 if (!$res > 0) {
80 $errors[] = $db->lasterror();
81 $error++;
82 }
83
84 $authorize_url = GETPOST('MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL', 'alpha');
85 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL', $authorize_url, 'chaine', 0, '', 0);
86 if (!$res > 0) {
87 $errors[] = $db->lasterror();
88 $error++;
89 }
90
91 $value = GETPOST('MAIN_AUTHENTICATION_OIDC_TOKEN_URL', 'alpha');
92 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_TOKEN_URL', $value, 'chaine', 0, '', 0);
93 if (!$res > 0) {
94 $errors[] = $db->lasterror();
95 $error++;
96 }
97
98 $value = GETPOST('MAIN_AUTHENTICATION_OIDC_USERINFO_URL', 'alpha');
99 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_USERINFO_URL', $value, 'chaine', 0, '', 0);
100 if (!$res > 0) {
101 $errors[] = $db->lasterror();
102 $error++;
103 }
104
105 $logout_url = GETPOST('MAIN_AUTHENTICATION_OIDC_LOGOUT_URL', 'alpha');
106 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_LOGOUT_URL', $logout_url, 'chaine', 0, '', 0);
107 if (!$res > 0) {
108 $errors[] = $db->lasterror();
109 $error++;
110 }
111}
112
113if ($action != '') {
114 if (!$error) {
115 setEventMessage($langs->trans("SetupSaved"));
116 header("Location: " . $_SERVER["PHP_SELF"]);
117 exit;
118 } else {
119 setEventMessages('', $errors, 'errors');
120 }
121}
122
123
124/*
125 * View
126 */
127
128$form = new Form($db);
129
130llxHeader();
131
132$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
133print load_fiche_titre($langs->trans("OpenIDconnectSetup"), $linkback, 'title_setup');
134print "<br>\n";
135
136$head = openid_connect_prepare_head();
137
138print dol_get_fiche_head($head, 'settings', $langs->trans("Parameters"), 0, 'action');
139
140
141print '<br>';
142print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
143print '<input type="hidden" name="token" value="'.newToken().'">';
144print '<input type="hidden" name="action" value="set">';
145
146$var=true;
147
148print '<table class="noborder" width="100%">';
149print '<tr class="liste_titre">';
150print '<td>'.$langs->trans("Parameters").'</td>'."\n";
151print '<td align="center">&nbsp;</td>'."\n";
152print '<td align="right">'.$langs->trans("Value").'</td>'."\n";
153print "</tr>\n";
154
155// MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM
156$var = !$var;
157print '<tr ' . $bc[$var] . '>' . "\n";
158print '<td>'.$langs->trans("MainAuthenticationOidcLoginClaimName").'</td>'."\n";
159print '<td>'.$langs->trans("MainAuthenticationOidcLoginClaimDesc").'</td>'."\n";
160print '<td align="right">' . "\n";
161print '<input name="MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM" id="MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM" class="minwidth300" value="'.dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM') ? GETPOST('MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM', 'nohtml') : (!empty($conf->global->MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM) ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM") : ''))).'"></td></tr>';
162print '</td></tr>' . "\n";
163
164// MAIN_AUTHENTICATION_OIDC_CLIENT_ID
165$var = !$var;
166print '<tr ' . $bc[$var] . '>' . "\n";
167print '<td>'.$langs->trans("MainAuthenticationOidcClientIdName").'</td>'."\n";
168print '<td>'.$langs->trans("MainAuthenticationOidcClientIdDesc").'</td>'."\n";
169print '<td align="right">' . "\n";
170print '<input name="MAIN_AUTHENTICATION_OIDC_CLIENT_ID" id="MAIN_AUTHENTICATION_OIDC_CLIENT_ID" class="minwidth300" value="'.dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_CLIENT_ID') ? GETPOST('MAIN_AUTHENTICATION_OIDC_CLIENT_ID', 'nohtml') : (!empty($conf->global->MAIN_AUTHENTICATION_OIDC_CLIENT_ID) ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_CLIENT_ID") : ''))).'"></td></tr>';
171print '</td></tr>' . "\n";
172
173// MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET
174$var = !$var;
175print '<tr ' . $bc[$var] . '>' . "\n";
176print '<td>'.$langs->trans("MainAuthenticationOidcClientSecretName").'</td>'."\n";
177print '<td>'.$langs->trans("MainAuthenticationOidcClientSecretDesc").'</td>'."\n";
178print '<td align="right">' . "\n";
179print '<input type="password" name="MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET" id="MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET" class="minwidth300" value="'.dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET') ? GETPOST('MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET', 'nohtml') : (!empty($conf->global->MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET) ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET") : ''))).'"></td></tr>';
180print '</td></tr>' . "\n";
181
182// MAIN_AUTHENTICATION_OIDC_SCOPES
183$var = !$var;
184print '<tr ' . $bc[$var] . '>' . "\n";
185print '<td>'.$langs->trans("MainAuthenticationOidcScopesName").'</td>'."\n";
186print '<td>'.$langs->trans("MainAuthenticationOidcScopesDesc").'</td>'."\n";
187print '<td align="right">' . "\n";
188print '<input name="MAIN_AUTHENTICATION_OIDC_SCOPES" id="MAIN_AUTHENTICATION_OIDC_SCOPES" class="minwidth300" value="'.dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_SCOPES') ? GETPOST('MAIN_AUTHENTICATION_OIDC_SCOPES', 'nohtml') : (!empty($conf->global->MAIN_AUTHENTICATION_OIDC_SCOPES) ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_SCOPES") : ''))).'"></td></tr>';
189print '</td></tr>' . "\n";
190
191// MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL
192$var = !$var;
193print '<tr ' . $bc[$var] . '>' . "\n";
194print '<td>'.$langs->trans("MainAuthenticationOidcAuthorizeUrlName").'</td>'."\n";
195print '<td>'.$langs->trans("MainAuthenticationOidcAuthorizeUrlDesc").'</td>'."\n";
196print '<td align="right">' . "\n";
197print '<input name="MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL" id="MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL" class="minwidth300" value="'.dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL') ? GETPOST('MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL', 'nohtml') : (!empty($conf->global->MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL) ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL") : ''))).'"></td></tr>';
198print '</td></tr>' . "\n";
199
200// MAIN_AUTHENTICATION_OIDC_TOKEN_URL
201$var = !$var;
202print '<tr ' . $bc[$var] . '>' . "\n";
203print '<td>'.$langs->trans("MainAuthenticationOidcTokenUrlName").'</td>'."\n";
204print '<td>'.$langs->trans("MainAuthenticationOidcTokenUrlDesc").'</td>'."\n";
205print '<td align="right">' . "\n";
206print '<input name="MAIN_AUTHENTICATION_OIDC_TOKEN_URL" id="MAIN_AUTHENTICATION_OIDC_TOKEN_URL" class="minwidth300" value="'.dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_TOKEN_URL') ? GETPOST('MAIN_AUTHENTICATION_OIDC_TOKEN_URL', 'nohtml') : (!empty($conf->global->MAIN_AUTHENTICATION_OIDC_TOKEN_URL) ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_TOKEN_URL") : ''))).'"></td></tr>';
207print '</td></tr>' . "\n";
208
209// MAIN_AUTHENTICATION_OIDC_USERINFO_URL
210$var = !$var;
211print '<tr ' . $bc[$var] . '>' . "\n";
212print '<td>'.$langs->trans("MainAuthenticationOidcUserinfoUrlName").'</td>'."\n";
213print '<td>'.$langs->trans("MainAuthenticationOidcUserinfoUrlDesc").'</td>'."\n";
214print '<td align="right">' . "\n";
215print '<input name="MAIN_AUTHENTICATION_OIDC_USERINFO_URL" id="MAIN_AUTHENTICATION_OIDC_USERINFO_URL" class="minwidth300" value="'.dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_USERINFO_URL') ? GETPOST('MAIN_AUTHENTICATION_OIDC_USERINFO_URL', 'nohtml') : (!empty($conf->global->MAIN_AUTHENTICATION_OIDC_USERINFO_URL) ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_USERINFO_URL") : ''))).'"></td></tr>';
216print '</td></tr>' . "\n";
217
218// MAIN_AUTHENTICATION_OIDC_LOGOUT_URL
219$var = !$var;
220print '<tr ' . $bc[$var] . '>' . "\n";
221print '<td>'.$langs->trans("MainAuthenticationOidcLogoutUrlName").'</td>'."\n";
222print '<td>'.$langs->trans("MainAuthenticationOidcLogoutUrlDesc").'</td>'."\n";
223print '<td align="right">' . "\n";
224print '<input name="MAIN_AUTHENTICATION_OIDC_LOGOUT_URL" id="MAIN_AUTHENTICATION_OIDC_LOGOUT_URL" class="minwidth300" value="'.dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_LOGOUT_URL') ? GETPOST('MAIN_AUTHENTICATION_OIDC_LOGOUT_URL', 'nohtml') : (!empty($conf->global->MAIN_AUTHENTICATION_OIDC_LOGOUT_URL) ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_LOGOUT_URL") : ''))).'"></td></tr>';
225print '</td></tr>' . "\n";
226
227// REDIRECT_URL
228$var = !$var;
229print '<tr ' . $bc[$var] . '>' . "\n";
230print '<td>'.$langs->trans("MainAuthenticationOidcRedirectUrlName").'</td>'."\n";
231print '<td>'.$langs->trans("MainAuthenticationOidcRedirectUrlDesc").'</td>'."\n";
232print '<td align="right">' . "\n";
233print '<input class="minwidth300" value="'.dol_escape_htmltag(openid_connect_get_redirect_url()).'" disabled></td></tr>';
234print '</td></tr>' . "\n";
235
236// LOGOUT_URL
237$var = !$var;
238print '<tr ' . $bc[$var] . '>' . "\n";
239print '<td>'.$langs->trans("MainAuthenticationOidcLogoutRedirectUrlName").'</td>'."\n";
240print '<td>'.$langs->trans("MainAuthenticationOidcLogoutRedirectUrlDesc").'</td>'."\n";
241print '<td align="right">' . "\n";
242print '<input class="minwidth300" value="'.dol_escape_htmltag(getDolGlobalString('MAIN_LOGOUT_GOTO_URL', DOL_MAIN_URL_ROOT . "/index.php")).'" disabled></td></tr>';
243print '</td></tr>' . "\n";
244
245print '</table>'."\n";
246
247print '<br>';
248print '<div align="center">';
249print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
250print '</div>';
251
252print '</form>';
253
254print '<br>';
255
256print dol_get_fiche_end();
257
258llxFooter();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message 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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.