You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is already an "OpenID" support in Dolibarr, but it is actually OpenID version 2.0 (with the use of Yadis, XRDS document and such) and it is not well documented.
The "OpenID" protocol in today's world rather means OpenID Connect (third generation of OpenID), supported by Auth0, Keycloak, Google etc. Read here: https://openid.net/connect/.
This implementation focuses on providing the authentication with zero modification on the Dolibarr codebase. The integration only consists of copy-pasting a new file + application configuration, before going further.
Coming along with PR #22741. If you want to try, see how to sections below.
Use case
Leverage federated identity which is the way to go. Whether to use SAML vs OpenID #6600 is another story. In the meantime, Dolibarr may support both and it should be up to the end user to choose depending on his constraints.
How to use: OpenID Server requirements
OpenID Server configuration
Check that grant type Authorization code is enabled.
A local URL like http://localhost:1234 can also be used for testing.
Note about Dolibarr user login
On the OpenID user profiles, there must be a claim (= user attribute) matching the Dolibarr user login, otherwise Dolibarr will say that the user could not be found in its database. Use this claim in MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM.
E.g.:
Bob used to log in into Dolibarr with login bob42 and password ********.
With OpenID Connect, Bob now uses his OpenID credentials to log in, for e.g. e-mail bob@domain.com and password **********. But Dolibarr still expects Bob's internal login bob42 to recognize him for authentication, his user permissions etc. We must then be able to retrieve this login from Bob's profile on the Identity Provider.
If this login cannot be retrieved from the Identity Provider for some reason, the Dolibarr database must be edited and all user logins have to be updated to an existing claim on the OpenID profile (e.g.: email, or nickname). Hint: in the Dolibarr database, see table llx_user, column login.
How to use: Dolibarr configuration
On the Dolibarr host
Configure the authentication methods in conf.php (/var/www/html/conf/conf.php) and add openid_connect.
For e.g.:
Copy/paste the file functions_openid_connect.php from NEW #22740 Add OpenID Connect impl #22741 in the core/login directory.
We then have /var/www/html/core/login/functions_openid_connect.php.
For Docker environments, the file can be mounted as a volume: -v $PWD/functions_openid_connect.php:/var/www/html/core/login/functions_openid_connect.php:ro.
Composing MAIN_AUTHENTICATION_OPENID_URL
This is the main OpenID Connect authentication URL, which allows the user to log in and then be redirected back to Dolibarr. It makes use of some already existing OpenID 2.0 features.
Retrieve the /authorize endpoint. The value depends on the used Identity Provider.
E.g.: https://tenant.us.auth0.com/authorize
Build the URL parameters
Param name
Description
Example
client_id
Application client ID
My-Super-Awesome-Client-ID-1234
redirect_uri
Dolibarr URL followed by /?openid_mode=true, then URL encoded. Must be authorized as callback URL
Before URL encoding: https://dolibarr.domain.com/?openid_mode=true - After URL encoding: https%3A%2F%2Fdolibarr.domain.com%2F%3Fopenid_mode%3Dtrue
scope
OpenID scope of required user info
openid profile email
response_type
OAuth flow name, here we use code for the Authorization Code flow
code
The final MAIN_AUTHENTICATION_OPENID_URL content should be like:
The final configuration step is to create the following values in Home > Setup > Other Setup.
Name
Example
Comment
Description
MAIN_AUTHENTICATION_OPENID_URL
See above
OpenID Connect URL
Composed OpenID Connect URL
MAIN_LOGOUT_GOTO_URL
See above
Identity Provider logout URL
Composed IdP logout URL
MAIN_AUTHENTICATION_OIDC_CLIENT_ID
My-Super-Awesome-Client-ID-1234
OpenID Connect Client ID
Application client ID
MAIN_AUTHENTICATION_OIDC_CLIENT_SECRET
My-Very-Hidden-Client-Secret-1234
OpenID Connect Client Secret
Application client secret
MAIN_AUTHENTICATION_OIDC_TOKEN_URL
https://tenant.us.auth0.com/oauth/token
OpenID Connect token URL
/token endpoint
MAIN_AUTHENTICATION_OIDC_USERINFO_URL
https://tenant.us.auth0.com/userinfo
OpenID Connect userinfo URL
/userinfo endpoint
MAIN_AUTHENTICATION_OIDC_REDIRECT_URL
https://dolibarr.domain.com/?openid_mode=true
OpenID Connect redirect URL
Dolibarr URL followed by /?openid_mode=true
MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM
email
OpenID Connect login claim
OpenID Connect claim matching the Dolibarr user login. If not set or empty, defaults to email
Limitations
Only authentication with OpenID is implemented i.e. check that username:password are valid. This does not provision Dolibarr users based on OpendID data like you would find in other applications, as user creation and authentication are handled separately in Dolibarr.
So, users must first be created with the Dolibarr UI before they can login using OpenID credentials. This is also the case for LDAP authentication for example.
Read more about user login handling in the OpenID Server requirements above.
Error messages are in English, there is no internationalization because that would require modification on the Dolibarr codebase.
Multicompany mode is not supported (I don't have any use case for it nor means for testing).
Notes for maintainers
The following are current considerations that any Dolibarr developper can change or contribute to.
Code
This implementation has no footprint on the Dolibarr codebase. Why? Because it is easier to maintain and contribute to, until (and if) it is merged officially into the Dolibarr repository.
I tried very much to use already existing Dolibarr functions like GETPOST, getURLContent etc. based on what I could find in the other auth methods. This also allows not to rely on third-party libraries (e.g. https://github.com/jumbojett/OpenID-Connect-PHP) because that would require adding new includes.
Naming
The name openid_connect is chosen carefully from what is already implemented in Dolibarr.
In login.tpl.php: preg_match('/openid/') will match openid_connect, which allows us to display and use MAIN_AUTHENTICATION_OPENID_URL on the login page (implemented with OpenID 2.0 support).
return_uri in MAIN_AUTHENTICATION_OPENID_URL
The return_uri parameter is built specifically to include openid_mode=something. Here we used openid_mode=true.
if (GETPOST('openid_mode', 'alpha', 1)) {
$goontestloop = true;
}
Using this technique, we can leverage the login page as the OpenID callback URL, then trigger the Dolibarr standard login pipeline which calls our new function.
MAIN_LOGOUT_GOTO_URL
This is an already existing feature from logout.php.
We can then make use of this hook to remove the session on the Identity Provider. If this is not done, the OpenID session would remain valid and clicking the MAIN_AUTHENTICATION_OPENID_URL on the login page would immediately authenticate the user without asking for credentials.
Configuration
The specific configuration variables (MAIN_AUTHENTICATION_OIDC_CLIENT_ID, CLIENT_SECRET etc.) have been added from the UI because this is the way it is done for the used built-in variables, as MAIN_AUTHENTICATION_OPENID_URL and MAIN_LOGOUT_GOTO_URL are already configured from the UI. It is practical to access all configuration variables on a single area.
Otherwise, they may have been provided in and retrieved from conf.php, something like $dolibarr_main_auth_oidc_client_id=.
Other implementations
I found there is another recent OpenID Connect support for Dolibarr here: #21333 but I am not sure of its intended scope.
There is already an "OpenID" support in Dolibarr, but it is actually OpenID version 2.0 (with the use of Yadis, XRDS document and such) and it is not well documented.
The "OpenID" protocol in today's world rather means OpenID Connect (third generation of OpenID), supported by Auth0, Keycloak, Google etc. Read here: https://openid.net/connect/.
This is a very simple implementation of the OpenID Connect Authorization flow (w/o PKCE) for Dolibarr. Read here: https://developer.okta.com/docs/guides/implement-grant-type/authcode/main/#grant-type-flow
This implementation focuses on providing the authentication with zero modification on the Dolibarr codebase. The integration only consists of copy-pasting a new file + application configuration, before going further.
Coming along with PR #22741. If you want to try, see how to sections below.
Use case
Leverage federated identity which is the way to go. Whether to use SAML vs OpenID #6600 is another story. In the meantime, Dolibarr may support both and it should be up to the end user to choose depending on his constraints.
How to use: OpenID Server requirements
OpenID Server configuration
Authorization codeis enabled.https://dolibarr.domain.comhttps://dolibarr.domain.comA local URL like
http://localhost:1234can also be used for testing.Note about Dolibarr user login
On the OpenID user profiles, there must be a claim (= user attribute) matching the Dolibarr user login, otherwise Dolibarr will say that the user could not be found in its database. Use this claim in
MAIN_AUTHENTICATION_OIDC_LOGIN_CLAIM.E.g.:
Bob used to log in into Dolibarr with login
bob42and password********.With OpenID Connect, Bob now uses his OpenID credentials to log in, for e.g. e-mail
bob@domain.comand password**********. But Dolibarr still expects Bob's internal loginbob42to recognize him for authentication, his user permissions etc. We must then be able to retrieve this login from Bob's profile on the Identity Provider.If this login cannot be retrieved from the Identity Provider for some reason, the Dolibarr database must be edited and all user logins have to be updated to an existing claim on the OpenID profile (e.g.:
email, ornickname). Hint: in the Dolibarr database, see tablellx_user, columnlogin.How to use: Dolibarr configuration
On the Dolibarr host
conf.php(/var/www/html/conf/conf.php) and addopenid_connect.For e.g.:
functions_openid_connect.phpfrom NEW #22740 Add OpenID Connect impl #22741 in thecore/logindirectory.We then have
/var/www/html/core/login/functions_openid_connect.php.For Docker environments, the file can be mounted as a volume:
-v $PWD/functions_openid_connect.php:/var/www/html/core/login/functions_openid_connect.php:ro.Composing
MAIN_AUTHENTICATION_OPENID_URLThis is the main OpenID Connect authentication URL, which allows the user to log in and then be redirected back to Dolibarr. It makes use of some already existing OpenID 2.0 features.
Retrieve the
/authorizeendpoint. The value depends on the used Identity Provider.E.g.:
https://tenant.us.auth0.com/authorizeBuild the URL parameters
My-Super-Awesome-Client-ID-1234/?openid_mode=true, then URL encoded. Must be authorized as callback URLhttps://dolibarr.domain.com/?openid_mode=true- After URL encoding:https%3A%2F%2Fdolibarr.domain.com%2F%3Fopenid_mode%3Dtrueopenid profile emailcodefor the Authorization Code flowcodeMAIN_AUTHENTICATION_OPENID_URLcontent should be like:Composing
MAIN_LOGOUT_GOTO_URLRetrieve the
/logoutendpoint. The value depends on the used Identity Provider.E.g.:
https://tenant.us.auth0.com/v2/logoutBuild the URL parameters
My-Super-Awesome-Client-ID-1234https://dolibar.domain.comMAIN_LOGOUT_GOTO_URLcontent should be like:Dolibarr application setup
The final configuration step is to create the following values in Home > Setup > Other Setup.
MAIN_AUTHENTICATION_OPENID_URLMAIN_LOGOUT_GOTO_URLMAIN_AUTHENTICATION_OIDC_CLIENT_IDMy-Super-Awesome-Client-ID-1234MAIN_AUTHENTICATION_OIDC_CLIENT_SECRETMy-Very-Hidden-Client-Secret-1234MAIN_AUTHENTICATION_OIDC_TOKEN_URLhttps://tenant.us.auth0.com/oauth/token/tokenendpointMAIN_AUTHENTICATION_OIDC_USERINFO_URLhttps://tenant.us.auth0.com/userinfo/userinfoendpointMAIN_AUTHENTICATION_OIDC_REDIRECT_URLhttps://dolibarr.domain.com/?openid_mode=true/?openid_mode=trueMAIN_AUTHENTICATION_OIDC_LOGIN_CLAIMemailemailLimitations
Only authentication with OpenID is implemented i.e. check that username:password are valid. This does not provision Dolibarr users based on OpendID data like you would find in other applications, as user creation and authentication are handled separately in Dolibarr.
So, users must first be created with the Dolibarr UI before they can login using OpenID credentials. This is also the case for LDAP authentication for example.
Read more about user login handling in the OpenID Server requirements above.
Error messages are in English, there is no internationalization because that would require modification on the Dolibarr codebase.
Multicompany mode is not supported (I don't have any use case for it nor means for testing).
Notes for maintainers
The following are current considerations that any Dolibarr developper can change or contribute to.
Code
This implementation has no footprint on the Dolibarr codebase. Why? Because it is easier to maintain and contribute to, until (and if) it is merged officially into the Dolibarr repository.
I tried very much to use already existing Dolibarr functions like
GETPOST,getURLContentetc. based on what I could find in the other auth methods. This also allows not to rely on third-party libraries (e.g. https://github.com/jumbojett/OpenID-Connect-PHP) because that would require adding new includes.Naming
The name
openid_connectis chosen carefully from what is already implemented in Dolibarr.In login.tpl.php:
preg_match('/openid/')will matchopenid_connect, which allows us to display and useMAIN_AUTHENTICATION_OPENID_URLon the login page (implemented with OpenID 2.0 support).return_uriinMAIN_AUTHENTICATION_OPENID_URLThe
return_uriparameter is built specifically to includeopenid_mode=something. Here we usedopenid_mode=true.This is because of main.inc.php:
Using this technique, we can leverage the login page as the OpenID callback URL, then trigger the Dolibarr standard login pipeline which calls our new function.
MAIN_LOGOUT_GOTO_URLThis is an already existing feature from logout.php.
We can then make use of this hook to remove the session on the Identity Provider. If this is not done, the OpenID session would remain valid and clicking the
MAIN_AUTHENTICATION_OPENID_URLon the login page would immediately authenticate the user without asking for credentials.Configuration
The specific configuration variables (
MAIN_AUTHENTICATION_OIDC_CLIENT_ID,CLIENT_SECRETetc.) have been added from the UI because this is the way it is done for the used built-in variables, asMAIN_AUTHENTICATION_OPENID_URLandMAIN_LOGOUT_GOTO_URLare already configured from the UI. It is practical to access all configuration variables on a single area.Otherwise, they may have been provided in and retrieved from
conf.php, something like$dolibarr_main_auth_oidc_client_id=.Other implementations
I found there is another recent OpenID Connect support for Dolibarr here: #21333 but I am not sure of its intended scope.