I recently embarked on a journey to simplify logins to a client’s network of WordPress sites with Single Sign-On (SSO). I didn’t really care what identity provider was going to be used, but they also used Google Workspace which I knew had support for SAML. I also figured that, being Google Workspace, the support for it would be well established, with lots of nice and simple clicky interfaces.
Until this point my only real experience with SSO had been as a consumer; I’ve had many accounts that have implemented some form of SSO (often based on Google accounts) and it has been relatively seamless. But trying to implement it myself from a cold start I found frustrating.
I first tried auth0’s setup with their WordPress plugin, but the auth0 WordPress guide was a little out-of-date. I found the auth0 interface super overwhelming at a glance, and gave up quickly.
Some more searching put me on to the OneLogin SAML SSO plugin (GitHub), which has zero documentation on the WordPress plugins site, in their GitHub, or anywhere else that I can find. The plugin, once installed in WordPress, yields a settings page with a billion different options. While they are mostly well-described, it’s not super-clear what you need to do in order to get up and running, especially with Google Workspace.
Some trial and error and help from this support thread and it was working pretty quickly – although I still don’t know what is going on under the hood, so it will be a while before I decide to use this in any production capacity – so just wanted to document the process as it stands for WordPress and Google Workspace (as of March 2021, anyway).
There are two sides you need to configure to make this work – OneLogin’s WordPress plugin, and the Google Workspace SAML setup.
Starting with the Workspace side:
- Broadly, we’re following Google’s own instructions: “Set up your own custom SAML application“.
- Log into Workspace Admin, go to Apps, and select “SAML Apps”.
- Open the “Add App” dropdown and select “Add custom SAML app”.
- Enter whatever for the app name & click “Continue”.
- Copy the “SSO URL”, “Entity ID” and “Certificate” fields, taking care to get it all and preserve formatting. (You can download the IdP metadata as well for backup purposes, but you can retrieve this information again easily at any time, so don’t stress.) Click “Continue”.
- Now it will ask for your “Service provider details” – “ACS URL” and “Entity ID”. The Learn More link here provides no useful information about what these are or where to get them from – but they come from your WordPress setup.
So now we switch to the WordPress side:
- In a new tab/browser, log into your WordPress admin panel and install the OneLogin SAML SSO plugin, and activate it.
- Go to Settings->SSO/SAML Settings, which is where this plugin keeps its settings.
- At the very top of the page, there is a link: “Go to the metadata of this SP”. Clicking this will open an XML document which has the information needed for the Google Workspaces form.
- Two two values we want are as follows (note: both of these values seem to be able to be customised elsewhere in the OneLogin plugin settings):
- ACS URL: this is in the tag that looks like this:
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://example.com/wp-login.php?saml_acs" index="1"/>– we want the value in the Location field.
- Entity ID: this is in the very first tag that looks like:
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" validUntil="2021-03-04T00:22:23Z" cacheDuration="PT604800S" entityID="php-saml">. Default seems to be
- ACS URL: this is in the tag that looks like this:
- You can ignore the rest of the fields in the “Name ID” section & just click Continue.
- Now we need to configure the Attributes. Basically just replicate the below screenshot (
Primary email -> email, First name -> firstname, Last name -> lastname, Primary email -> username).
- Click ‘Save’.
Now, back to the WordPress SSO config:
- Set “IdP Entity Id” to be the “Entity ID” field that we copied from the Google settings up earlier on.
- Set “Single Sign On Service Url” to be the “SSO URL” field.
- Set “X.509 Certificate” to have the certificate from the “Certificate” field.
- Look for the “Create user if not exists” field. Whether or not you want this checked depends on whether you already have your user accounts set up. It may be easiest, if you’re just trying to get this working at all, to check this and try with an account that doesn’t already exist in WordPress with the same email address.
- Look for “Match WordPress account by” and change this to “E-mail”. Google Workspace does not appear to expose any username field (maybe you can make this work with mapping but not sure).
- Scroll down to “ATTRIBUTE MAPPING”. As with the Google Workspace-side mapping, we do the same here:
First Name: firstname
Last Name: lastname
- There are tons of other things that you should look at – for example, “Prevent reset password” might be something you want to do to make sure a user can’t accidentally have their WordPress password reset to bring it out of sync with their Workspace account (I suspect in theory this should not impact things as users should not be able to login without going through the SSO, but in case of WordPress bugs or vulnerabilities in plugins or whatever it’s probably safer).
- Once you’re ready, scroll back up to the top and check the “Enable” checkbox.
- I strongly recommend opening a new private browser session and logging in as admin at this point, just in case any of this blows up access to your admin section.
- Then back to the bottom, hold on to your butts, and click “Save Changes”.
- You should now be able to log into your WordPress site with your Google Workspace credentials.
This document is a work-in-progress as I figure out more about what is going on; very interested in comments and feedback.
- Single Logout (SLO) does not seem to be supported by Google Workspace at the moment so there is no easy way to log out of all services at once [that I can see].