| 1 |
HumHub |
| 2 |
====== |
| 3 |
|
| 4 |
|image0| |
| 5 |
|
| 6 |
Présentation |
| 7 |
------------ |
| 8 |
|
| 9 |
`HumHub <https://humhub.org/>`__ is a free and open-source social |
| 10 |
network written on top of the `Yii2 PHP |
| 11 |
framework <https://www.yiiframework.com/>`__ that provides an easy to |
| 12 |
use toolkit for creating and launching your own social network. |
| 13 |
|
| 14 |
Unauthenticated users may connect using a login form against HumHub |
| 15 |
local database or a LDAP directory, or choose which authentication |
| 16 |
service they want to use. |
| 17 |
|
| 18 |
Administrator can configure one or several OAuth, OAuth2 or OIDC |
| 19 |
authentication services to be displayed as buttons on the login page. |
| 20 |
|
| 21 |
With :doc:`OpenID Connect<>` authentication service, users successfully |
| 22 |
authenticated by LemonLDAP::NG will be registered in HumHub upon their |
| 23 |
first login. |
| 24 |
|
| 25 |
|
| 26 |
.. danger:: |
| 27 |
|
| 28 |
HumHub retrieves a user from his username and the |
| 29 |
authentication service he came through. As a result, a former local or |
| 30 |
LDAP user will be rejected when trying to authenticate using another |
| 31 |
authentication service. See |
| 32 |
:doc:`Migrate former local or ldap Humhub account to connect through SSO<>` |
| 33 |
|
| 34 |
|
| 35 |
OpenID Connect |
| 36 |
-------------- |
| 37 |
|
| 38 |
|
| 39 |
.. note:: |
| 40 |
|
| 41 |
This set-up works with option enablePrettyUrl activated in |
| 42 |
Humhub. If not activated, rewrite URL in Humhub HTTP server and allowed |
| 43 |
redirect URL in LemonLDAP needs to be adapted to work with the non |
| 44 |
pretty URL format. |
| 45 |
|
| 46 |
Configuring HumHub |
| 47 |
~~~~~~~~~~~~~~~~~~ |
| 48 |
|
| 49 |
First disable LDAP (Administration > Users section) and delete (or |
| 50 |
:doc:`migrate<>`) any local users whose username or email are |
| 51 |
conflicting with the username or email of your OIDC users. |
| 52 |
|
| 53 |
Then install and configure the `OIDC connector for |
| 54 |
humhub <https://github.com/Worteks/humhub-auth-oidc>`__ extension using |
| 55 |
composer : |
| 56 |
|
| 57 |
- Install composer. |
| 58 |
|
| 59 |
- Consider using prestissimo, to speed up composer update command (4x |
| 60 |
faster): |
| 61 |
|
| 62 |
:: |
| 63 |
|
| 64 |
composer global require hirak/prestissimo |
| 65 |
|
| 66 |
- Go to ``{humhub_home}`` folder |
| 67 |
|
| 68 |
- Check if composer.json file is present. If not, download it for your |
| 69 |
current version: |
| 70 |
|
| 71 |
:: |
| 72 |
|
| 73 |
wget https://raw.githubusercontent.com/humhub/humhub/v1.3.15/composer.json |
| 74 |
|
| 75 |
- Install the connector as a dependency: |
| 76 |
|
| 77 |
:: |
| 78 |
|
| 79 |
composer require --no-update --update-no-dev worteks/humhub-auth-oidc |
| 80 |
composer update worteks/humhub-auth-oidc --no-dev --prefer-dist -vvv |
| 81 |
|
| 82 |
|
| 83 |
.. note:: |
| 84 |
|
| 85 |
If you just need to update the connector, change its version |
| 86 |
in composer.json and run the above composer update command. |
| 87 |
|
| 88 |
- Edit `{humhub_home}/protected/config/common.php` with the client configuration : |
| 89 |
|
| 90 |
:: |
| 91 |
|
| 92 |
'components' => [ |
| 93 |
'authClientCollection' => [ |
| 94 |
'clients' => [ |
| 95 |
// ... |
| 96 |
'lemonldapng' => [ |
| 97 |
'class' => 'worteks\humhub\authclient\OIDC', |
| 98 |
'domain' => 'https://auth.example.com', |
| 99 |
'clientId' => 'myClientId', // Client ID for this RP in LemonLDAP |
| 100 |
'clientSecret' => 'myClientSecret', // Client secret for this RP in LemonLDAP |
| 101 |
'defaultTitle' => 'auth.example.com', // Text displayed in login button |
| 102 |
'cssIcon' => 'fa fa-lemon-o', // Icon displayed in login button |
| 103 |
], |
| 104 |
], |
| 105 |
// ... |
| 106 |
] |
| 107 |
|
| 108 |
- Edit ``{humhub_home}/protected/config/web.php`` to disconnect users from LemonLDAP::NG after they logged out of Humhub: |
| 109 |
|
| 110 |
:: |
| 111 |
|
| 112 |
return [ |
| 113 |
// ... |
| 114 |
'modules' => [ |
| 115 |
'user' => [ |
| 116 |
'logoutUrl' => 'https://auth.domain.com/?logout=1', |
| 117 |
], |
| 118 |
] |
| 119 |
]; |
| 120 |
|
| 121 |
User can now log in through SSO using a button on humhub logging page. |
| 122 |
If you want to remove this intermediate login page, so user are |
| 123 |
automatically logged in through SSO when they first access Humhub, you |
| 124 |
can set up a redirection in the http server in front of the application |
| 125 |
: |
| 126 |
|
| 127 |
- Example in apache |
| 128 |
|
| 129 |
:: |
| 130 |
|
| 131 |
RewriteEngine On |
| 132 |
RewriteCond %{QUERY_STRING} !nosso [NC] |
| 133 |
RewriteRule "^/user/auth/login$" "/user/auth/external?authclient=lemonldapng" [L,R=301] |
| 134 |
|
| 135 |
- Example in nginx |
| 136 |
|
| 137 |
:: |
| 138 |
|
| 139 |
if ($query_string !~ "nosso"){ |
| 140 |
rewrite ^/user/auth/login$ /user/auth/external?authclient=lemonldapng permanent; |
| 141 |
} |
| 142 |
|
| 143 |
If the authentication was successful but the user could not be |
| 144 |
registered in Humhub (which often happen if there is a conflict between |
| 145 |
source, username or email), Humhub will redirect to the login page to |
| 146 |
display the error, which trigger a redirection to the portal, ultimately |
| 147 |
triggering a loop error while registration error is not displayed. |
| 148 |
|
| 149 |
To change this behavior and display the registration error, |
| 150 |
AuthController.onAuthSuccess method needs to be adapted so redirect to |
| 151 |
SSO will be bypassed when a registration error occured. This works for |
| 152 |
version 1.3.15 : |
| 153 |
|
| 154 |
- Go to ``{humhub_home}`` folder |
| 155 |
- Execute |
| 156 |
|
| 157 |
:: |
| 158 |
|
| 159 |
sed -i "s|return \$this->redirect(\['/user/auth/login'\]);|return \$this->redirect(['/user/auth/login','nosso'=>'showerror']);|" protected/humhub/modules/user/controllers/AuthController.php |
| 160 |
|
| 161 |
Configuring LemonLDAP |
| 162 |
~~~~~~~~~~~~~~~~~~~~~ |
| 163 |
|
| 164 |
If not done yet, configure LemonLDAP::NG as an |
| 165 |
:doc:`OpenID Connect service<..//openidconnectservice>`. |
| 166 |
|
| 167 |
Then, configure LemonLDAP::NG to recognize your HumHub instance as a |
| 168 |
valid :doc:`new OpenID Connect Relying Party<..//idpopenidconnect>` |
| 169 |
using the following parameters: |
| 170 |
|
| 171 |
* **Client ID**: the same you set in HumHub configuration |
| 172 |
* **Client Secret**: the same you set in HumHub configuration |
| 173 |
* Add the following **exported attributes** |
| 174 |
* **given_name**: user's givenName attribute |
| 175 |
* **family_name**: user's sn attribute |
| 176 |
* **email**: user's mail attribute |
| 177 |
* **Redirect URIs** containing your Yii2 auth client ID. |
| 178 |
|
| 179 |
Configuration sample using CLI: |
| 180 |
|
| 181 |
:: |
| 182 |
|
| 183 |
$ /usr/libexec/lemonldap-ng/bin/lemonldap-ng-cli -yes 1 \ |
| 184 |
addKey \ |
| 185 |
oidcRPMetaDataExportedVars/humhub given_name givenName \ |
| 186 |
oidcRPMetaDataExportedVars/humhub family_name sn \ |
| 187 |
oidcRPMetaDataExportedVars/humhub email mail \ |
| 188 |
oidcRPMetaDataOptions/humhub oidcRPMetaDataOptionsClientID myClientId \ |
| 189 |
oidcRPMetaDataOptions/humhub oidcRPMetaDataOptionsClientSecret myClientSecret \ |
| 190 |
oidcRPMetaDataOptions/humhub oidcRPMetaDataOptionsRedirectUris 'https://humhub.example.com/user/auth/external?authclient=lemonldapng' \ |
| 191 |
oidcRPMetaDataOptions/humhub oidcRPMetaDataOptionsPostLogoutRedirectUris 'https://humhub.example.com' \ |
| 192 |
oidcRPMetaDataOptions/humhub oidcRPMetaDataOptionsIDTokenSignAlg RS512 \ |
| 193 |
oidcRPMetaDataOptions/humhub oidcRPMetaDataOptionsIDTokenExpiration 3600 \ |
| 194 |
oidcRPMetaDataOptions/humhub oidcRPMetaDataOptionsAccessTokenExpiration 3600 \ |
| 195 |
oidcRPMetaDataOptions/humhub oidcRPMetaDataOptionsBypassConsent 1 |
| 196 |
|
| 197 |
Migrate former local or ldap Humhub account to connect through SSO |
| 198 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 199 |
|
| 200 |
You need to manually update Humhub database to swith authentication mode |
| 201 |
to LemonLDAP::NG. |
| 202 |
|
| 203 |
Table "user": |
| 204 |
|
| 205 |
* Columns "username" and "email" should match exactly OIDC sub and email attributes ; |
| 206 |
* If former ldap user, change column "auth_mode" to "local". |
| 207 |
|
| 208 |
Table "user_auth": |
| 209 |
|
| 210 |
* Add an entry with user_id, username and "lemonldapng" as source (or the name you chose in your connector configuration) : |
| 211 |
|
| 212 |
:: |
| 213 |
|
| 214 |
+---------+-------------+-------------+ |
| 215 |
| user_id | source | source_id | |
| 216 |
+---------+-------------+-------------+ |
| 217 |
| 4 | lemonldapng | jdoe | |
| 218 |
|
| 219 |
Troubleshooting |
| 220 |
~~~~~~~~~~~~~~~ |
| 221 |
|
| 222 |
If LemonLDAP login page freezes because of a browser security blockage, |
| 223 |
adapt security's CSP Form Action to allow HumHub host : |
| 224 |
|
| 225 |
:: |
| 226 |
|
| 227 |
$ /usr/libexec/lemonldap-ng/bin/lemonldap-ng-cli -yes 1 \ |
| 228 |
set \ |
| 229 |
cspFormAction "'self' https://*.example.com" |
| 230 |
|
| 231 |
.. |image0| image:: /applications/humhub_logo.png |
| 232 |
:class: align-center |
| 233 |
|