Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| en:2.0:single_sign_on:oidc_wordpress [2026/09/06 18:28] – [Setting up the Client (SP) in Admidio] kainhofer | en:2.0:single_sign_on:oidc_wordpress [2026/09/09 18:12] (current) – kainhofer | ||
|---|---|---|---|
| Line 27: | Line 27: | ||
| * Choose an easily understood **label for the client** (only used in Admidio' | * Choose an easily understood **label for the client** (only used in Admidio' | ||
| * Enter the **ClientID from the RP**, copy the created Client Secret (you will later need to paste it into the WordPress configuration), | * Enter the **ClientID from the RP**, copy the created Client Secret (you will later need to paste it into the WordPress configuration), | ||
| + | * Many open source OIDC clients do not support encryption (PKCE, which is a security mechanism that prevents attackers from obtaining access unless their application started the initial login). By default, PKCE is required by Admidio, so in this case make sure that the requirement checkbox is turned off. Otherwise you will get an error. | ||
| * In Admidio, map the user ID, username, email and fullname to fields that are included in the OpenID login response (so-called " | * In Admidio, map the user ID, username, email and fullname to fields that are included in the OpenID login response (so-called " | ||
| Line 48: | Line 49: | ||
| {{ : | {{ : | ||
| - | First, one has to copy over the OpenID endpoint URLs from Admidio' | ||
| - | {{ : | ||
| - | The remaining settings in Wordpress are client-specific, | ||
| ==== Setting up the Client (SP) in Admidio ==== | ==== Setting up the Client (SP) in Admidio ==== | ||
| Line 58: | Line 56: | ||
| Return to Admidio' | Return to Admidio' | ||
| + | {{ : | ||
| + | |||
| + | The first step is to copy over the endpoint URLs from Admidio into the WordPress configuration. WordPress does not support automatic discovery, so the individual URLs (hidden by default in a foldable section at the top) must be copied individually: | ||
| + | {{ : | ||
| + | |||
| + | The remaining settings are individual to the WordPress installation: | ||
| {{ : | {{ : | ||
| - The **Client Name** is the label of the client in Admidio' | - The **Client Name** is the label of the client in Admidio' | ||
| - The **" | - The **" | ||
| + | - Many open source OIDC clients do not support encryption (PKCE, which is a security mechanism that prevents attackers from obtaining access unless their application started the initial login). By default, PKCE is required by Admidio, so in this case make sure that the requirement checkbox is turned off. Otherwise you will get an error. | ||
| - Enter the **scopes** you desire in the WordPress config and make sure that Admidio' | - Enter the **scopes** you desire in the WordPress config and make sure that Admidio' | ||
| - In Admidio, choose which field should be sent to and used by the Wordpress Plugin to uniquely identify users. This would typically be the login name, although the user ID or UUID area also possible. | - In Admidio, choose which field should be sent to and used by the Wordpress Plugin to uniquely identify users. This would typically be the login name, although the user ID or UUID area also possible. | ||
| + | - In addition, WordPress also provides settings to map OpenID claims (defined profile fields with a fixed name, defined in the OpenID standard) to the WordPress user's ID, nickname, email and fullname, as well as flags to enable automatic user creation when a new user logs in to WordPress. {{ : | ||
| + | - WordPress will display its **Redirect URL** at the very bottom of the form, which needs to be copied to Admidio' | ||
| + | - OIDC also requires clients to register a URL where the user is returned after a logout. Admidio must be configured with the exact logout redirect URL that the WordPress plugin sends on the logout request. This is typically '' | ||
| + | - WordPress' | ||
| - | - In addition, WordPress also provides settings to map OpenID claims (defined profile fields with a fixed name, defined in the OpenID standard) to the WordPress user's ID, nickname, email and fullname, as well as flags to enable automatic user creation when a new user logs in to WordPress. | ||
| - | {{ : | ||
| - | - WordPress will display its **Redirect URL** at the very bottom of the form, which needs to be copied to Admidio' | ||
| - | {{ : | ||
| - | - WordPress's OIDC implementation does not support PKCE for increased security, which is enabled by Admidio | + | After saving the changes (both in WordPress |
| - | {{ : | + | |
| + | ==== Mapping Admidio roles to WordPress roles ==== | ||
| - | After saving | + | Although |
| + | The following PHP code is a fully working skeleton, assigning WordPress roles based on OIDC groups, as specified in the mapping defined at the beginning of the plugin. Place this code in the file '' | ||
| + | <code php> | ||
| + | <?php | ||
| + | /** Plugin Name: Admidio OIDC role mapping */ | ||
| + | |||
| + | /** | ||
| + | * WP role slug => Admidio role names (or mapped group names) that grant it. | ||
| + | * Most privileged first: the first key with a match wins. | ||
| + | */ | ||
| + | function admidio_role_map() { | ||
| + | return array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | } | ||
| + | |||
| + | add_action( ' | ||
| + | add_action( ' | ||
| + | |||
| + | function admidio_apply_role( $user, $user_claim ) { | ||
| + | // Never modify the local WordPress administrator! | ||
| + | if ( (int) $user-> | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | // Retrieve the groups passed via OIDC and search through the map until the user has one of the given groups | ||
| + | $groups = isset( $user_claim[' | ||
| + | $groups = array_map( ' | ||
| + | |||
| + | $role = ''; | ||
| + | foreach ( admidio_role_map() as $wp_role => $admidio_roles ) { | ||
| + | $admidio_roles = array_map( ' | ||
| + | if ( array_intersect( $admidio_roles, | ||
| + | $role = $wp_role; | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | if ( '' | ||
| + | // No mapped group: no WP access. Use ' | ||
| + | // prefer every Admidio user to keep a read-only account. | ||
| + | $user-> | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | if ( ! in_array( $role, (array) $user-> | ||
| + | $user-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| ==== Setup completed, test Single-Sign-On ==== | ==== Setup completed, test Single-Sign-On ==== | ||