Starting with version 5.0, Admidio can be used by other applications to authenticate users against Admidios user base. These instructions will guide you through the process of connecting WordPress to Admidio to use Admidio's login. For general instructions, and other apps, please visit the general Single-Sign-On overview page.
Throughout the document we will assume you have both Admidio and WordPress already set up properly at https://admidio.local/ and https://wordpress.local/. Please modify these URLs to your actual installation.
As a first step, one needs to configure Admidio to act as an OpenID Provider (OP). This has to be done once and is not specific to any particular client. Please folow this guide:
Basically, one needs to enable OpenID Connect (OIDC). The Issuer URL should in most cases be left blank, which means Admidio's public URL will be used as issuer URL.
The page https://admidio.local/adm_program/modules/preferences.php?panel=sso also provides the link to the automatic discovery URL, and the individual settings in case a client does not support auto-configuration via metadata.
Setting up a client (OpenID “Relying Party” = “RP”) to use Admidio's user accounts for log-in consists of two steps: (1) The client (RP, WordPress in our case) needs to be set up with the data about the OpenID Provider (OP). As WordPress does not support auto-configuration useing the OpenID discovery endpoint, one has to manually paste the endpoint URLs of the OpenID provider. Since Admidio provides those URLs with copy buttons in the preferences screen, even the manual configuration is rather straigtforward. (2) Admidio needs to be told about the client. In particular, the entity ID and the redirect URL must be given, and a custom-generated (random) secret must be copied to the client configuration.
The concrete steps are:
There are several OpenID plugins for WordPress, but none of the free versions supports permission mapping based on groups easily. The best free plugin we found is the OpenID Connect for WP plugin, which is a hard fork of Jonathan Daggerhart's OpenID Connect Generic plugin (which he is no longer able to maintain due to WordPress's stance on WP Engine and the fallout of the actions of Matt Mullenweg). The “OpenID Connect for WP” plugin is not available in the Wordpress plugin directory, only the previous “OpenID Connect Generic” by Daggerhart. We still recommend to use the newer “OpenID Connect for WP” and install it manually (either using git or by downloading the plugin code to the WP installation). See the plugin's source code repository on GitHub: https://github.com/forumone/openid-connect-wp-dist That plugin also allows mapping Admidio's groups to WordPress roles, but that involves writing a tiny Wordpress plugin for the mapping. See below for the instructions.
If you have shell access to the WP installation, the easiest way is to use the git shell command:
# Switch to the base directory of your WordPress installation. Then: cd wp-content/plugins/ git clone https://github.com/forumone/openid-connect-wp-dist.git
After installation it can be configured in the menu item “Settings” → “OpenID Connect Client”.
It is now a good idea to keep two browser windows open so one can easily select and copy the settings. Admidio even provides little “copy” buttons/icons to copy the various settings to the clipboard for easy pasting into the WordPress configuration.
Return to Admidio's SSO preferences page, go to the “Single-Sign-On Client Administration” (the button right below the endpoint URLs and above the “Save” button), and create a new client.
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:
https://[YOUR-WORDPRESS]/wp-login.php?loggedout=true&lang=de_DE. Insert this exactly in the “Allowed logout return URLs” box. Wildcards are allowed, so it's probably better to use https://[YOUR-WORDPRESS]/wp-login.php?loggedout=true* to allow any language.After saving the changes (both in WordPress and Admidio), the apps should should now be set up for single-sign-on in WordPress.
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 wp-content/mu-plugins/admidio-role-map.php of your WordPress installation. All files in the mu-plugins (“mu” is short for “must use”) directory are always loaded by WordPress, so this plugin will not appear in the Plugin manager and does not need to be enabled:
<?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( 'administrator' => array( 'Administrator', 'admin', 'Webmaster' ), 'editor' => array( 'editor', 'Board' ), 'author' => array( 'author', 'Trainer', 'Another Admidio Group' ), 'contributor' => array( 'contributor', 'Staff', 'Volunteer', 'Janitor' ), 'subscriber' => array( 'subscriber', 'Players' ), ); } add_action( 'openid-connect-wp-user-create', 'admidio_apply_role', 10, 2 ); add_action( 'openid-connect-wp-update-user-using-current-claim', 'admidio_apply_role', 10, 2 ); function admidio_apply_role( $user, $user_claim ) { // Never modify the local WordPress administrator! if ( (int) $user->ID === 1 ) { 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) $user_claim['groups'] : array(); $groups = array_map( 'strtolower', array_map( 'trim', array_filter( $groups, 'is_string' ) ) ); $role = ''; foreach ( admidio_role_map() as $wp_role => $admidio_roles ) { $admidio_roles = array_map( 'strtolower', array_map( 'trim', $admidio_roles ) ); if ( array_intersect( $admidio_roles, $groups ) ) { $role = $wp_role; break; } } if ( '' === $role ) { // No mapped group: no WP access. Use 'subscriber' instead if you // prefer every Admidio user to keep a read-only account. $user->set_role( '' ); return; } if ( ! in_array( $role, (array) $user->roles, true ) ) { $user->set_role( $role ); // set_role replaces all existing roles } }
Admidio and WordPress should now be set up to use Admidio for logging in to WordPress. If you log out of WordPress and try to log in again, you will be shown the Admidio login screen and then redirected back to WordPress.