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->loadLangs(["admin", "openidconnect"]);
41
42if (!$user->admin) {
44}
45
46$action = GETPOST('action', 'alpha');
47
48
49/*
50 * Actions
51 */
52
53$errors = [];
54$error = 0;
55
56if ($action == 'set') {
57 $client_id = GETPOST('MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM', 'alpha');
58 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM', $client_id, 'chaine', 0, '', 0);
59 if (!$res > 0) {
60 $errors[] = $db->lasterror();
61 $error++;
62 }
63
64 $client_id = GETPOST('MAIN_AUTHENTICATION_OIDC_CLIENT_ID', 'alpha');
65 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_CLIENT_ID', $client_id, 'chaine', 0, '', 0);
66 if (!$res > 0) {
67 $errors[] = $db->lasterror();
68 $error++;
69 }
70
71 $client_secret = GETPOST('MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET', 'alpha');
72 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET', $client_secret, 'chaine', 0, '', 0);
73 if (!$res > 0) {
74 $errors[] = $db->lasterror();
75 $error++;
76 }
77
78 $scopes = GETPOST('MAIN_AUTHENTICATION_OIDC_SCOPES', 'alpha');
79 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_SCOPES', $scopes, 'chaine', 0, '', 0);
80 if (!$res > 0) {
81 $errors[] = $db->lasterror();
82 $error++;
83 }
84
85 $authorize_url = GETPOST('MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL', 'alpha');
86 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL', $authorize_url, 'chaine', 0, '', 0);
87 if (!$res > 0) {
88 $errors[] = $db->lasterror();
89 $error++;
90 }
91
92 $value = GETPOST('MAIN_AUTHENTICATION_OIDC_TOKEN_URL', 'alpha');
93 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_TOKEN_URL', $value, 'chaine', 0, '', 0);
94 if (!$res > 0) {
95 $errors[] = $db->lasterror();
96 $error++;
97 }
98
99 $value = GETPOST('MAIN_AUTHENTICATION_OIDC_USERINFO_URL', 'alpha');
100 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_USERINFO_URL', $value, 'chaine', 0, '', 0);
101 if (!$res > 0) {
102 $errors[] = $db->lasterror();
103 $error++;
104 }
105
106 $logout_url = GETPOST('MAIN_AUTHENTICATION_OIDC_LOGOUT_URL', 'alpha');
107 $res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_LOGOUT_URL', $logout_url, 'chaine', 0, '', 0);
108 if (!$res > 0) {
109 $errors[] = $db->lasterror();
110 $error++;
111 }
112}
113
114if ($action != '') {
115 if (!$error) {
116 setEventMessage($langs->trans("SetupSaved"));
117 header("Location: " . $_SERVER["PHP_SELF"]);
118 exit;
119 } else {
120 setEventMessages('', $errors, 'errors');
121 }
122}
123
124
125/*
126 * View
127 */
128
129$form = new Form($db);
130
131llxHeader();
132
133$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
134print load_fiche_titre($langs->trans("OpenIDconnectSetup"), $linkback, 'title_setup');
135print "<br>\n";
136
137$head = openid_connect_prepare_head();
138
139print dol_get_fiche_head($head, 'settings', $langs->trans("Parameters"), 0, 'action');
140
141
142print '<br>';
143print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
144print '<input type="hidden" name="token" value="'.newToken().'">';
145print '<input type="hidden" name="action" value="set">';
146
147print '<table class="noborder" width="100%">';
148print '<tr class="liste_titre">';
149print '<td>'.$langs->trans("Parameters").'</td>'."\n";
150print '<td align="center">&nbsp;</td>'."\n";
151print '<td align="right">'.$langs->trans("Value").'</td>'."\n";
152print "</tr>\n";
153
154// MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM
155print '<tr class="oddeven">' . "\n";
156print '<td>'.$langs->trans("MainAuthenticationOidcLoginClaimName").'</td>'."\n";
157print '<td>'.$langs->trans("MainAuthenticationOidcLoginClaimDesc").'</td>'."\n";
158print '<td align="right">' . "\n";
159print '<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>';
160print '</td></tr>' . "\n";
161
162// MAIN_AUTHENTICATION_OIDC_CLIENT_ID
163print '<tr class="oddeven">' . "\n";
164print '<td>'.$langs->trans("MainAuthenticationOidcClientIdName").'</td>'."\n";
165print '<td>'.$langs->trans("MainAuthenticationOidcClientIdDesc").'</td>'."\n";
166print '<td align="right">' . "\n";
167print '<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>';
168print '</td></tr>' . "\n";
169
170// MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET
171print '<tr class="oddeven">' . "\n";
172print '<td>'.$langs->trans("MainAuthenticationOidcClientSecretName").'</td>'."\n";
173print '<td>'.$langs->trans("MainAuthenticationOidcClientSecretDesc").'</td>'."\n";
174print '<td align="right">' . "\n";
175print '<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>';
176print '</td></tr>' . "\n";
177
178// MAIN_AUTHENTICATION_OIDC_SCOPES
179print '<tr class="oddeven">' . "\n";
180print '<td>'.$langs->trans("MainAuthenticationOidcScopesName").'</td>'."\n";
181print '<td>'.$langs->trans("MainAuthenticationOidcScopesDesc").'</td>'."\n";
182print '<td align="right">' . "\n";
183print '<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>';
184print '</td></tr>' . "\n";
185
186// MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL
187print '<tr class="oddeven">' . "\n";
188print '<td>'.$langs->trans("MainAuthenticationOidcAuthorizeUrlName").'</td>'."\n";
189print '<td>'.$langs->trans("MainAuthenticationOidcAuthorizeUrlDesc").'</td>'."\n";
190print '<td align="right">' . "\n";
191print '<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>';
192print '</td></tr>' . "\n";
193
194// MAIN_AUTHENTICATION_OIDC_TOKEN_URL
195print '<tr class="oddeven">' . "\n";
196print '<td>'.$langs->trans("MainAuthenticationOidcTokenUrlName").'</td>'."\n";
197print '<td>'.$langs->trans("MainAuthenticationOidcTokenUrlDesc").'</td>'."\n";
198print '<td align="right">' . "\n";
199print '<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>';
200print '</td></tr>' . "\n";
201
202// MAIN_AUTHENTICATION_OIDC_USERINFO_URL
203print '<tr class="oddeven">' . "\n";
204print '<td>'.$langs->trans("MainAuthenticationOidcUserinfoUrlName").'</td>'."\n";
205print '<td>'.$langs->trans("MainAuthenticationOidcUserinfoUrlDesc").'</td>'."\n";
206print '<td align="right">' . "\n";
207print '<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>';
208print '</td></tr>' . "\n";
209
210// MAIN_AUTHENTICATION_OIDC_LOGOUT_URL
211print '<tr class="oddeven">' . "\n";
212print '<td>'.$langs->trans("MainAuthenticationOidcLogoutUrlName").'</td>'."\n";
213print '<td>'.$langs->trans("MainAuthenticationOidcLogoutUrlDesc").'</td>'."\n";
214print '<td align="right">' . "\n";
215print '<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>';
216print '</td></tr>' . "\n";
217
218// REDIRECT_URL
219print '<tr class="oddeven">' . "\n";
220print '<td>'.$langs->trans("MainAuthenticationOidcRedirectUrlName").'</td>'."\n";
221print '<td>'.$langs->trans("MainAuthenticationOidcRedirectUrlDesc").'</td>'."\n";
222print '<td align="right">' . "\n";
223print '<input class="minwidth300" value="'.dol_escape_htmltag(openid_connect_get_redirect_url()).'" disabled></td></tr>';
224print '</td></tr>' . "\n";
225
226// LOGOUT_URL
227print '<tr class="oddeven">' . "\n";
228print '<td>'.$langs->trans("MainAuthenticationOidcLogoutRedirectUrlName").'</td>'."\n";
229print '<td>'.$langs->trans("MainAuthenticationOidcLogoutRedirectUrlDesc").'</td>'."\n";
230print '<td align="right">' . "\n";
231print '<input class="minwidth300" value="'.dol_escape_htmltag(getDolGlobalString('MAIN_LOGOUT_GOTO_URL', DOL_MAIN_URL_ROOT . "/index.php")).'" disabled></td></tr>';
232print '</td></tr>' . "\n";
233
234print '</table>'."\n";
235
236print '<br>';
237print '<div align="center">';
238print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
239print '</div>';
240
241print '</form>';
242
243print '<br>';
244
245print dol_get_fiche_end();
246
247llxFooter();
248$db->close();
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).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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.
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.