NEW: Add OIDC user auto-creation and fix login bugs (#37314)

* NEW #25922 Add OIDC user auto-creation and fix login bugs

NEW #25922 Add OIDC user auto-creation and fix login bugs

* Fix indentation in OIDC auto-create user admin settings block

* Move require_once statements to file level in openid_connect.lib.php

* Cast login_claim to string before user creation

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Sacha Pignot 2026-02-28 09:37:48 -05:00 committed by GitHub
parent 3ff4fedab1
commit 4810534025
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 369 additions and 57 deletions

View file

@ -27,7 +27,6 @@ require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/openid_connect.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/openid_connect.lib.php';
/**
* @var Conf $conf
@ -118,6 +117,41 @@ if ($action == 'set') {
$errors[] = $db->lasterror();
$error++;
}
$value = GETPOST('MAIN_AUTHENTICATION_OIDC_DEFAULT_GROUP', 'int');
$res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_DEFAULT_GROUP', $value, 'chaine', 0, '', 0);
if (!$res > 0) {
$errors[] = $db->lasterror();
$error++;
}
$value = GETPOSTINT('MAIN_AUTHENTICATION_OIDC_DEFAULT_CREATOR');
$res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_DEFAULT_CREATOR', $value, 'chaine', 0, '', 0);
if (!$res > 0) {
$errors[] = $db->lasterror();
$error++;
}
$value = GETPOST('MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME', 'alpha');
$res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME', $value, 'chaine', 0, '', 0);
if (!$res > 0) {
$errors[] = $db->lasterror();
$error++;
}
$value = GETPOST('MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME', 'alpha');
$res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME', $value, 'chaine', 0, '', 0);
if (!$res > 0) {
$errors[] = $db->lasterror();
$error++;
}
$value = GETPOST('MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL', 'alpha');
$res = dolibarr_set_const($db, 'MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL', $value, 'chaine', 0, '', 0);
if (!$res > 0) {
$errors[] = $db->lasterror();
$error++;
}
}
if ($action != '') {
@ -300,8 +334,70 @@ if (getDolGlobalString('MAIN_AUTHENTICATION_OIDC_ON')) {
print '<input name="MAIN_AUTHENTICATION_OPENID_URL_IMG" id="MAIN_AUTHENTICATION_OPENID_URL_IMG" class="minwidth400 centpercent" value="' . dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OPENID_URL_IMG') ? GETPOST('MAIN_AUTHENTICATION_OPENID_URL_IMG', 'nohtml') : (getDolGlobalString('MAIN_AUTHENTICATION_OPENID_URL_IMG') ? getDolGlobalString("MAIN_AUTHENTICATION_OPENID_URL_IMG") : ''))) . '">';
print '</td></tr>' . "\n";
print '</table>' . "\n";
print '</div>';
// --- User Auto-Creation Settings ---
print '</table></div>' . "\n";
$langs->load("errors");
global $dolibarr_main_authentication_autocreateuser;
if (empty($dolibarr_main_authentication_autocreateuser)) {
print info_admin($langs->trans("OIDCAutocreateUserDisabled"), 0, 0, 1, 'warning');
} else {
print info_admin($langs->trans("OIDCAutocreateUserEnabled"), 0, 0, 1, 'success');
}
if (!empty($dolibarr_main_authentication_autocreateuser)) {
print '<div class="div-table-responsive-no-min">';
print '<table class="tagtable noborder liste nobottomiftotal">';
print '<tr class="liste_titre">';
print '<th class="liste_titre" colspan="3">' . $langs->trans("MainAuthenticationOidcAutoCreateTitle") . '</th>' . "\n";
print "</tr>\n";
// MAIN_AUTHENTICATION_OIDC_DEFAULT_CREATOR
$form = new Form($db);
print '<tr class="oddeven">' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcDefaultCreatorName") . '</td>' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcDefaultCreatorDesc") . '</td>' . "\n";
print '<td align="right">' . "\n";
$creator_val = GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_DEFAULT_CREATOR') ? GETPOSTINT('MAIN_AUTHENTICATION_OIDC_DEFAULT_CREATOR') : getDolGlobalInt('MAIN_AUTHENTICATION_OIDC_DEFAULT_CREATOR');
print $form->select_dolusers($creator_val, 'MAIN_AUTHENTICATION_OIDC_DEFAULT_CREATOR', 1, null, 0, '', '', '', 0, 0, '(admin:=:1) AND (statut:=:1)', 0, '', 'minwidth200 maxwidth500');
print '</td></tr>' . "\n";
// MAIN_AUTHENTICATION_OIDC_DEFAULT_GROUP
print '<tr class="oddeven">' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcDefaultGroupName") . '</td>' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcDefaultGroupDesc") . '</td>' . "\n";
print '<td align="right">' . "\n";
$defaultgroup_val = GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_DEFAULT_GROUP') ? GETPOSTINT('MAIN_AUTHENTICATION_OIDC_DEFAULT_GROUP') : getDolGlobalInt('MAIN_AUTHENTICATION_OIDC_DEFAULT_GROUP');
$form->select_dolgroups($defaultgroup_val, 'MAIN_AUTHENTICATION_OIDC_DEFAULT_GROUP', 1);
print '</td></tr>' . "\n";
// MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME
print '<tr class="oddeven">' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcClaimFirstnameName") . '</td>' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcClaimFirstnameDesc") . '</td>' . "\n";
print '<td align="right">' . "\n";
print '<input name="MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME" id="MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME" class="minwidth400 centpercent" value="' . dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME') ? GETPOST('MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME', 'nohtml') : (getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME') ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME") : ''))) . '" placeholder="given_name">';
print '</td></tr>' . "\n";
// MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME
print '<tr class="oddeven">' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcClaimLastnameName") . '</td>' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcClaimLastnameDesc") . '</td>' . "\n";
print '<td align="right">' . "\n";
print '<input name="MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME" id="MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME" class="minwidth400 centpercent" value="' . dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME') ? GETPOST('MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME', 'nohtml') : (getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME') ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME") : ''))) . '" placeholder="family_name">';
print '</td></tr>' . "\n";
// MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL
print '<tr class="oddeven">' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcClaimEmailName") . '</td>' . "\n";
print '<td>' . $langs->trans("MainAuthenticationOidcClaimEmailDesc") . '</td>' . "\n";
print '<td align="right">' . "\n";
print '<input name="MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL" id="MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL" class="minwidth400 centpercent" value="' . dol_escape_htmltag((GETPOSTISSET('MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL') ? GETPOST('MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL', 'nohtml') : (getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL') ? getDolGlobalString("MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL") : ''))) . '" placeholder="email">';
print '</td></tr>' . "\n";
print '</table>' . "\n";
print '</div>';
} // end if autocreateuser
print '<br>';
print '<div align="center">';

View file

@ -245,6 +245,15 @@ $dolibarr_main_instance_unique_id='84b5bc91f83b56e458db71e0adac2b62';
$dolibarr_main_authentication='dolibarr';
// dolibarr_main_authentication_autocreateuser
// ============================================
// Auto-creation of Dolibarr users on first OIDC login.
// Set to 1 to allow new user accounts to be created automatically
// when a user authenticates via OpenID Connect but has no existing account.
// IMPORTANT: This must be set here in conf.php, not via the database setup.
$dolibarr_main_authentication_autocreateuser=0;
// Parameters used to setup LDAP authentication
// --------------------------------------------
// Uncomment them if dolibarr_main_authentication = 'ldap'

View file

@ -17,26 +17,70 @@
*/
/**
* \file htdocs/admin/openid_connect.php
* \file htdocs/core/lib/openid_connect.lib.php
* \ingroup openid_connect
* \brief Functions for the module openid_connect
* \brief Library of functions for OpenID Connect authentication
*/
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
/**
* return the current state
* Generate a self-verifiable state token for the OIDC authorization request.
*
* @return string String containing the state
* Uses HMAC with the instance unique ID as secret so the state can be verified
* without depending on the original session. This is necessary because browsers
* with SameSite=Lax cookies do not send the session cookie on cross-site redirects
* from the OIDC provider, causing a new session to be created on the callback.
*
* @return string State token (format: nonce.signature)
*/
function openid_connect_get_state()
{
return hash('sha256', session_id());
global $dolibarr_main_instance_unique_id;
$nonce = bin2hex(random_bytes(16));
$signature = hash_hmac('sha256', $nonce, $dolibarr_main_instance_unique_id);
return $nonce.'.'.$signature;
}
/**
* Verify an OIDC state token.
*
* Checks that the state was generated by this Dolibarr instance by recomputing
* the HMAC signature from the nonce and comparing it to the provided signature.
*
* @param string $state The state token to verify (format: nonce.signature)
* @return bool True if valid, false otherwise
*/
function openid_connect_verify_state($state)
{
global $dolibarr_main_instance_unique_id;
if (empty($state)) {
return false;
}
$parts = explode('.', $state, 2);
if (count($parts) !== 2) {
return false;
}
$nonce = $parts[0];
$signature = $parts[1];
$expected = hash_hmac('sha256', $nonce, $dolibarr_main_instance_unique_id);
return hash_equals($expected, $signature);
}
/**
* return the redirect url
* Return the OIDC callback redirect URL
*
* @return string Redirect url
* @return string Redirect URL
*/
function openid_connect_get_redirect_url()
{
@ -45,14 +89,116 @@ function openid_connect_get_redirect_url()
/**
* Return authentication url
* Return the OIDC authorization URL
*
* @return string Authentication url
* @return string Authorization URL
*/
function openid_connect_get_url()
{
// Note: For the scope, we msut use rawurlencode instead of urlencode.
// Note: For the scope, we must use rawurlencode instead of urlencode.
$url = getDolGlobalString('MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL').'?client_id='.urlencode(getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLIENT_ID')).'&redirect_uri='.urlencode(openid_connect_get_redirect_url()).'&scope='.rawurlencode(getDolGlobalString('MAIN_AUTHENTICATION_OIDC_SCOPES')).'&response_type=code&state='.urlencode(openid_connect_get_state());
return $url;
}
/**
* Create a Dolibarr user from OIDC userinfo claims.
*
* The login is sanitized to remove characters not allowed by Dolibarr (e.g. @ from emails).
* If the OIDC userinfo contains a preferred_username claim without bad characters, it is used instead.
*
* @param DoliDB $db Database handler
* @param stdClass $userinfo Decoded OIDC userinfo JSON (claims from json_decode)
* @param string $login Login value extracted from the configured claim
* @param int $entity Entity (multicompany) ID
* @return string|int Sanitized login string on success, negative int on failure
* @see check_user_password_openid_connect()
*/
function openid_connect_create_user($db, $userinfo, $login, $entity)
{
// Read claim mapping configuration
$claim_email = getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLAIM_EMAIL', 'email');
$claim_firstname = getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLAIM_FIRSTNAME', 'given_name');
$claim_lastname = getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLAIM_LASTNAME', 'family_name');
// Sanitize login: Dolibarr rejects certain characters (default: ,@<>"')
$badChars = getDolGlobalString('MAIN_LOGIN_BADCHARUNAUTHORIZED', ',@<>"\'');
$sanitized_login = $login;
if (preg_match('/['.preg_quote($badChars, '/').']/', $login)) {
// First try preferred_username from OIDC (common standard claim)
if (property_exists($userinfo, 'preferred_username') && !empty($userinfo->preferred_username)) {
$preferred = $userinfo->preferred_username;
if (!preg_match('/['.preg_quote($badChars, '/').']/', $preferred)) {
$sanitized_login = $preferred;
}
}
// If still invalid (no preferred_username or it also has bad chars), extract local part of email
if (preg_match('/['.preg_quote($badChars, '/').']/', $sanitized_login) && strpos($sanitized_login, '@') !== false) {
$sanitized_login = substr($sanitized_login, 0, strpos($sanitized_login, '@'));
}
// Final fallback: replace any remaining bad characters
$sanitized_login = preg_replace('/['.preg_quote($badChars, '/').']/', '.', $sanitized_login);
}
$newuser = new User($db);
$newuser->login = $sanitized_login;
$newuser->entity = $entity;
$newuser->statut = 1; // Active
$newuser->status = 1; // Active (alias)
if (property_exists($userinfo, $claim_email)) {
$newuser->email = $userinfo->$claim_email;
}
if (property_exists($userinfo, $claim_firstname)) {
$newuser->firstname = $userinfo->$claim_firstname;
}
if (property_exists($userinfo, $claim_lastname)) {
$newuser->lastname = $userinfo->$claim_lastname;
}
// If no lastname from claims, use login as fallback (lastname is required)
if (empty($newuser->lastname)) {
$newuser->lastname = $login;
}
// Set a random password (user authenticates via OIDC, not locally)
$newuser->pass = getRandomPassword(true);
// Find the admin user to set as creator (configurable, default: user ID 1)
$creator_id = getDolGlobalInt('MAIN_AUTHENTICATION_OIDC_DEFAULT_CREATOR', 1);
if ($creator_id <= 0) {
$creator_id = 1;
}
$adminuser = new User($db);
$result_fetch = $adminuser->fetch($creator_id);
if ($result_fetch <= 0 || empty($adminuser->admin) || $adminuser->statut != 1) {
dol_syslog("openid_connect_create_user::Error: configured creator user ID=".$creator_id." is not a valid active admin", LOG_ERR);
return -2;
}
$db->begin();
$result_create = $newuser->create($adminuser);
if ($result_create < 0) {
$db->rollback();
dol_syslog("openid_connect_create_user::Error creating user: ".$newuser->error, LOG_ERR);
return $result_create;
}
// Add to default group if configured
$default_group = getDolGlobalInt('MAIN_AUTHENTICATION_OIDC_DEFAULT_GROUP');
if ($default_group > 0) {
$res_group = $newuser->SetInGroup($default_group, $entity);
if ($res_group < 0) {
dol_syslog("openid_connect_create_user::Warning: Error adding user to group ".$default_group.": ".$newuser->error, LOG_WARNING);
// Don't fail user creation if group assignment fails
}
}
$db->commit();
dol_syslog("openid_connect_create_user::User created id=".$result_create." login=".$sanitized_login);
return $sanitized_login;
}

View file

@ -63,24 +63,26 @@ function check_user_password_openid_connect($usertotest, $passwordtotest, $entit
$_SESSION["dol_loginmesg"] = "Not an OpenID Connect flow";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::not an OIDC flow");
return false;
} elseif (!GETPOSTISSET('state')) {
// No state received
} elseif (empty($_SESSION['oidc_state'])) {
// No state in session (set by callback.php)
$_SESSION["dol_loginmesg"] = "Error in OAuth 2.0 flow (no state received)";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::no state received", LOG_ERR);
return false;
} elseif (!GETPOSTISSET('code')) {
// No code received
} elseif (empty($_SESSION['oidc_code'])) {
// No code in session (set by callback.php)
$_SESSION["dol_loginmesg"] = "Error in OAuth 2.0 flow (no code received)";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::no code received", LOG_ERR);
return false;
}
$auth_code = GETPOST('code', 'password');
$state = GETPOST('state', 'aZ09');
dol_syslog('functions_openid_connect::check_user_password_openid_connect code='.$auth_code.' state='.$state);
// Read OIDC params from session and clear immediately (single-use)
$auth_code = $_SESSION['oidc_code'];
$state = $_SESSION['oidc_state'];
unset($_SESSION['oidc_code'], $_SESSION['oidc_state']);
dol_syslog('functions_openid_connect::check_user_password_openid_connect state='.$state);
if ($state !== openid_connect_get_state()) {
// State does not match
if (!openid_connect_verify_state($state)) {
// State signature invalid - not generated by this Dolibarr instance
$_SESSION["dol_loginmesg"] = "Error in OAuth 2.0 flow (state does not match)";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::state does not match", LOG_ERR);
return false;
@ -109,7 +111,7 @@ function check_user_password_openid_connect($usertotest, $passwordtotest, $entit
$_SESSION["dol_loginmesg"] = "Error in OAuth 2.0 flow (".$token_response['content'].")";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::".$token_response['content'], LOG_ERR);
return false;
} elseif ($token_content->error) {
} elseif (property_exists($token_content, 'error') && $token_content->error) {
// Got token response but content is an error
$_SESSION["dol_loginmesg"] = "Error in OAuth 2.0 flow (".$token_content->error_description.")";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::".$token_content->error_description, LOG_ERR);
@ -144,7 +146,7 @@ function check_user_password_openid_connect($usertotest, $passwordtotest, $entit
$_SESSION["dol_loginmesg"] = "OpenID Connect user info error: " . $userinfo_response['content'];
dol_syslog("functions_openid_connect::check_user_password_openid_connect::".$userinfo_response['content'], LOG_ERR);
return false;
} elseif ($userinfo_content->error) {
} elseif (property_exists($userinfo_content, 'error') && $userinfo_content->error) {
// Got user info response but content is an error
$_SESSION["dol_loginmesg"] = "Error in OAuth 2.0 flow (".$userinfo_content->error_description.")";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::".$userinfo_content->error_description, LOG_ERR);
@ -181,8 +183,30 @@ function check_user_password_openid_connect($usertotest, $passwordtotest, $entit
}
$obj = $db->fetch_object($resql);
if (!$obj) {
dol_syslog("functions_openid_connect::check_user_password_openid_connect::Error no result from the query");
return false;
// User not found in Dolibarr - check if auto-creation is enabled
global $dolibarr_main_authentication_autocreateuser;
if (empty($dolibarr_main_authentication_autocreateuser)) {
$_SESSION["dol_loginmesg"] = "User not found in Dolibarr and auto-creation is disabled";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::User not found, auto-creation disabled");
return false;
}
dol_syslog("functions_openid_connect::check_user_password_openid_connect::User not found, auto-creating from OIDC claims");
$claim_value = (string) $userinfo_content->$login_claim;
$result_create = openid_connect_create_user($db, $userinfo_content, $claim_value, $entity);
if (is_numeric($result_create) && $result_create < 0) {
$_SESSION["dol_loginmesg"] = "Error creating user from OIDC";
dol_syslog("functions_openid_connect::check_user_password_openid_connect::Error creating user, result=".$result_create, LOG_ERR);
return false;
}
// $result_create is the sanitized login string
$newlogin = $result_create;
dol_syslog("functions_openid_connect::check_user_password_openid_connect::User auto-created login=".$newlogin);
$_SESSION['OPENID_CONNECT'] = true;
return $newlogin;
}
$_SESSION['OPENID_CONNECT'] = true;

View file

@ -18,15 +18,22 @@
/**
* \file htdocs/core/modules/openid_connect/public/callback.php
* \ingroup openid_connect
* \brief OpenID Connect: Authorization Code flow authentication
* \brief OpenID Connect: Authorization Code flow callback
*
* This page receives the authorization code from the OIDC provider and
* stores the OIDC parameters (code, state) in $_SESSION, then redirects
* to index.php via a same-site JS redirect (with tz detection from dst.js).
*
* The same-site redirect ensures the session cookie IS sent (SameSite=Lax
* allows same-site navigations). The OIDC code and state are transported
* via $_SESSION instead of GET parameters to avoid exposing them in
* web server access logs.
*/
define('NOLOGIN', '1');
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
define('NOTOKENRENEWAL', '1');
define('NOCSRFCHECK', 1);
require '../../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
@ -45,7 +52,7 @@ top_htmlhead('', '', 0, 0, $arrayofjs);
$prefix = dol_getprefix('');
$callbackUrl = $_COOKIE["DOL_rollback_url_".$prefix]; // Was set by login page to $_SERVER['REQUEST_URI'] to allow come back to initial requested page
$callbackUrl = isset($_COOKIE["DOL_rollback_url_".$prefix]) ? $_COOKIE["DOL_rollback_url_".$prefix] : '';
if (empty($callbackUrl) || !preg_match('/^\/[a-z0-9]/i', $callbackUrl)) {
// We accept only value that is an internal relative URL. URL starting with http are not allowed.
@ -56,26 +63,41 @@ if ($callbackUrl === '/') {
} else {
dolSetCookie('DOL_rollback_url_'.dol_getprefix(''), "", time() + 1);
}
// Get OIDC parameters from the provider's redirect (GET) and store in session
$oidcState = GETPOST('state', 'aZ09');
$oidcCode = GETPOST('code', 'password');
// Store in $_SESSION so they are not exposed as GET params on the redirect to index.php
$_SESSION['oidc_code'] = $oidcCode;
$_SESSION['oidc_state'] = $oidcState;
?>
<form id="login" name="login" method="post" action="<?php echo dolPrintHTMLForAttributeUrl($callbackUrl); ?>">
<!-- Add fields to send OpenID information -->
<input type="hidden" name="openid_mode" value="true" />
<input type="hidden" name="state" value="<?php echo GETPOST('state'); ?>" />
<input type="hidden" name="session_state" value="<?php echo GETPOST('session_state'); ?>" />
<input type="hidden" name="code" value="<?php echo GETPOST('code'); ?>" />
<input type="hidden" name="token" value="<?php echo newToken(); ?>" />
<!-- Add fields to send local user information -->
<input type="hidden" name="tz" id="tz" value="" />
<input type="hidden" name="tz_string" id="tz_string" value="" />
<input type="hidden" name="dst_observed" id="dst_observed" value="" />
<input type="hidden" name="dst_first" id="dst_first" value="" />
<input type="hidden" name="dst_second" id="dst_second" value="" />
<input type="hidden" name="screenwidth" id="screenwidth" value="" />
<input type="hidden" name="screenheight" id="screenheight" value="" />
</form>
<!-- Hidden fields for dst.js to populate with timezone detection -->
<input type="hidden" id="tz" value="" />
<input type="hidden" id="tz_string" value="" />
<input type="hidden" id="dst_observed" value="" />
<input type="hidden" id="dst_first" value="" />
<input type="hidden" id="dst_second" value="" />
<input type="hidden" id="screenwidth" value="" />
<input type="hidden" id="screenheight" value="" />
<script type="text/javascript">
$(document).ready(function () {
document.forms['login'].submit();
// dst.js has already populated the hidden fields above.
// Build a GET redirect URL with openid_mode flag + timezone info.
var baseUrl = '<?php echo dol_escape_js($callbackUrl); ?>';
var sep = baseUrl.indexOf('?') === -1 ? '?' : '&';
var url = baseUrl + sep + 'openid_mode=true';
url += '&tz=' + encodeURIComponent($('#tz').val());
url += '&tz_string=' + encodeURIComponent($('#tz_string').val());
url += '&dst_observed=' + encodeURIComponent($('#dst_observed').val());
url += '&dst_first=' + encodeURIComponent($('#dst_first').val());
url += '&dst_second=' + encodeURIComponent($('#dst_second').val());
url += '&screenwidth=' + encodeURIComponent($('#screenwidth').val());
url += '&screenheight=' + encodeURIComponent($('#screenheight').val());
window.location.href = url;
});
</script>

View file

@ -184,7 +184,6 @@ if (getDolGlobalInt('MAIN_AUTHENTICATION_OIDC_ON', 0) > 0 && isset($conf->file->
if (empty($_COOKIE["DOL_rollback_url_$prefix"])) {
dolSetCookie('DOL_rollback_url_'.$prefix, $_SERVER['REQUEST_URI'], time() + 3600); // $_SERVER["REQUEST_URI"] is for example /mydolibarr/mypage.php
}
// Auto redirect if OpenID Connect is the only authentication
if ($conf->file->main_authentication === 'openid_connect') {
// Avoid redirection hell

View file

@ -2649,6 +2649,19 @@ MainAuthenticationOidcAutofillWithWellknowUrl=Base URL of your OpenID Connect pr
MainAuthenticationOidcAutofillButton=Populate from well-known URL
MainAuthenticationOpenIDUrlImgName=OpenID url image
MainAuthenticationOpenIDUrlImgDesc=Non-mandatory link to an image to use instead of text in login button
MainAuthenticationOidcAutoCreateTitle=User Auto-Creation Settings
MainAuthenticationOidcCreateUserName=Auto-create users
MainAuthenticationOidcCreateUserDesc=Automatically create a Dolibarr user account on first OpenID Connect login if the user does not yet exist
MainAuthenticationOidcDefaultCreatorName=Creator admin user
MainAuthenticationOidcDefaultCreatorDesc=Admin user set as creator for auto-created accounts (default: first user). Must be an active admin.
MainAuthenticationOidcDefaultGroupName=Default group
MainAuthenticationOidcDefaultGroupDesc=Group to assign to automatically created users
MainAuthenticationOidcClaimFirstnameName=First name claim
MainAuthenticationOidcClaimFirstnameDesc=OIDC userinfo claim for first name (default: given_name)
MainAuthenticationOidcClaimLastnameName=Last name claim
MainAuthenticationOidcClaimLastnameDesc=OIDC userinfo claim for last name (default: family_name)
MainAuthenticationOidcClaimEmailName=Email claim
MainAuthenticationOidcClaimEmailDesc=OIDC userinfo claim for email (default: email)
BlackListWords=Blacklist of words
BlackListWordsHelp=List of words that will be completely removed from any answer. Words must be separated by a coma (",")
BlackListWordsAIHelp=This is a list of words that will be completely removed from the result of any AI requests

View file

@ -168,6 +168,8 @@ ErrorPaymentModeDefinedToWithoutSetup=A payment mode was set to type %s but setu
ErrorPHPNeedModule=Error, your PHP must have module <b>%s</b> installed to use this feature.
ErrorOpenIDSetupConfNotComplete=For security purposes, you must also setup the Dolibarr config file conf.php to allow OpenID authentication
ErrorOpenIDSetupNotComplete=You setup Dolibarr config file to allow OpenID authentication, but URL of OpenID service is not defined into constant %s
OIDCAutocreateUserDisabled=Auto-creation of users on OIDC login is currently disabled. To enable it, add $dolibarr_main_authentication_autocreateuser=1 to your conf.php file.
OIDCAutocreateUserEnabled=Auto-creation of users on OIDC login is enabled ($dolibarr_main_authentication_autocreateuser=1 is set in conf.php).
ErrorWarehouseMustDiffers=Source and target warehouses must differs
ErrorBadFormat=Bad format!
ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst=Error, this member is not yet linked to any third party. Link member to an existing third party or create a new third party before creating subscription with invoice.

View file

@ -736,15 +736,16 @@ if (!defined('NOLOGIN')) {
if ($login) {
$dol_authmode = $conf->authmode; // This property is defined only when logged, to say what mode was successfully used
$dol_tz = empty($_POST["tz"]) ? (empty($_SESSION["tz"]) ? '' : $_SESSION["tz"]) : $_POST["tz"];
$dol_tz_string = empty($_POST["tz_string"]) ? (empty($_SESSION["tz_string"]) ? '' : $_SESSION["tz_string"]) : $_POST["tz_string"];
// Check POST first, then GET (for OIDC callback redirect), then SESSION
$dol_tz = empty($_POST["tz"]) ? (empty($_GET["tz"]) ? (empty($_SESSION["tz"]) ? '' : $_SESSION["tz"]) : (int) $_GET["tz"]) : $_POST["tz"];
$dol_tz_string = empty($_POST["tz_string"]) ? (empty($_GET["tz_string"]) ? (empty($_SESSION["tz_string"]) ? '' : $_SESSION["tz_string"]) : $_GET["tz_string"]) : $_POST["tz_string"];
$dol_tz_string = preg_replace('/\s*\(.+\)$/', '', $dol_tz_string);
$dol_tz_string = preg_replace('/,/', '/', $dol_tz_string);
$dol_tz_string = preg_replace('/\s/', '_', $dol_tz_string);
$dol_dst = 0;
// Keep $_POST here. Do not use GETPOSTISSET
$dol_dst_first = empty($_POST["dst_first"]) ? (empty($_SESSION["dst_first"]) ? '' : $_SESSION["dst_first"]) : $_POST["dst_first"];
$dol_dst_second = empty($_POST["dst_second"]) ? (empty($_SESSION["dst_second"]) ? '' : $_SESSION["dst_second"]) : $_POST["dst_second"];
// Check POST first, then GET (for OIDC callback redirect), then SESSION
$dol_dst_first = empty($_POST["dst_first"]) ? (empty($_GET["dst_first"]) ? (empty($_SESSION["dst_first"]) ? '' : $_SESSION["dst_first"]) : (int) $_GET["dst_first"]) : $_POST["dst_first"];
$dol_dst_second = empty($_POST["dst_second"]) ? (empty($_GET["dst_second"]) ? (empty($_SESSION["dst_second"]) ? '' : $_SESSION["dst_second"]) : (int) $_GET["dst_second"]) : $_POST["dst_second"];
if ($dol_dst_first && $dol_dst_second) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$datenow = dol_now();
@ -754,8 +755,8 @@ if (!defined('NOLOGIN')) {
$dol_dst = 1;
}
}
$dol_screenheight = empty($_POST["screenheight"]) ? (empty($_SESSION["dol_screenheight"]) ? '' : $_SESSION["dol_screenheight"]) : $_POST["screenheight"];
$dol_screenwidth = empty($_POST["screenwidth"]) ? (empty($_SESSION["dol_screenwidth"]) ? '' : $_SESSION["dol_screenwidth"]) : $_POST["screenwidth"];
$dol_screenheight = empty($_POST["screenheight"]) ? (empty($_GET["screenheight"]) ? (empty($_SESSION["dol_screenheight"]) ? '' : $_SESSION["dol_screenheight"]) : (int) $_GET["screenheight"]) : $_POST["screenheight"];
$dol_screenwidth = empty($_POST["screenwidth"]) ? (empty($_GET["screenwidth"]) ? (empty($_SESSION["dol_screenwidth"]) ? '' : $_SESSION["dol_screenwidth"]) : (int) $_GET["screenwidth"]) : $_POST["screenwidth"];
//print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst.'-'.sdol_screenheight.'-'.sdol_screenwidth; exit;
}