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 16:31] – [Quick Overview] kainhofer | en:2.0:single_sign_on:oidc_wordpress [2026/09/07 00:03] (current) – [Setting up the Client (SP) in Admidio] kainhofer | ||
|---|---|---|---|
| Line 34: | Line 34: | ||
| ==== Configuring the Service Provider (WordPress) ==== | ==== Configuring the Service Provider (WordPress) ==== | ||
| - | There are several OpenID plugins for WordPress, but none of the free versions supports permission mapping based on groups. The best free plugin we found is the [[https:// | + | There are several OpenID plugins for WordPress, but none of the free versions supports permission mapping based on groups |
| + | That plugin also allows mapping Admidio' | ||
| If you have shell access to the WP installation, | If you have shell access to the WP installation, | ||
| Line 63: | Line 64: | ||
| - 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' | ||
| - | {{ : | ||
| Line 75: | Line 74: | ||
| + | ==== Mapping Admidio roles to WordPress roles ==== | ||
| + | |||
| + | Although the Wordpress OpenID Connect plugin does not provide any graphical way to map roles passed from Admidio as OIDC groups to WordPress roles, one can hook into the WordPress internals and write a small plugin that assigns the proper WordPress roles based on OIDC groups. | ||
| + | |||
| + | 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 ==== | ||