Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/martinarafat/entra-id-sso/archive/refs/heads/main.zipEntra ID SSO for WordPress
Sign in to WordPress with a Microsoft work account (Entra ID). Accounts are created on first sign-in and the WordPress role comes from Entra app roles or groups.
How the sign-in works
- The user clicks Sign in with Microsoft on the login page.
- The plugin creates a one-time
state, anonceand a PKCE code verifier, stores them server-side for 10 minutes, and ties thestateto the browser with an HttpOnly cookie. - The user is sent to Entra ID (authorization code flow with PKCE, S256).
- Entra sends the user back to
wp-login.phpwith a code. Thestatemust exist, must not have been used, and must match the browser cookie. - The code is exchanged for tokens using the client secret and the PKCE verifier.
- The ID token is checked before anything else happens:
- RS256 signature against the tenant's signing keys (cached for a day, re-downloaded once if the key ID is new, since Microsoft rotates keys)
- issuer, audience, tenant ID, expiry, not-before, issued-at, and nonce
- The user is matched by Entra object ID (
oid), then by email if linking is on, otherwise a new account is created. - The role is set from the role map, the user is logged in, and the attempt is written to the sign-in log.
If any check fails, the sign-in stops with a message and the attempt is logged.
Entra ID setup
- Azure portal > Microsoft Entra ID > App registrations > New registration
- Supported account types: this organizational directory only
- Redirect URI: platform Web, and paste the URL shown on Settings > Microsoft SSO (it's your
wp-login.phpURL). Entra requires HTTPS, except forlocalhost.
- From the app Overview, copy the Application (client) ID and Directory (tenant) ID.
- Certificates & secrets > New client secret, and copy the value.
- For role mapping, pick one:
- App roles (recommended): App roles > create roles such as
Intranet.Editor, then assign users or groups in Enterprise applications > your app > Users and groups. They arrive in therolesclaim. - Security groups: Token configuration > Add groups claim > Security groups. Group object IDs arrive in the
groupsclaim.
- App roles (recommended): App roles > create roles such as
WordPress setup
-
Activate the plugin and open Settings > Microsoft SSO.
-
Paste the tenant ID and client ID.
-
Add the secret. For production, put it in
wp-config.phpinstead of the database:define( 'ENTRA_SSO_CLIENT_SECRET', 'your-secret' );It can also come from an environment variable with the same name, which is how it would be loaded from Azure Key Vault on App Service.
-
Add role rules, one per line. The first match wins:
Intranet.Admin = administrator Intranet.Editor = editor 3f2a9c1e-0000-0000-0000-000000000000 = author
Options
- Create accounts on first sign-in, with a default role (administrator is never allowed as the default)
- Link existing accounts by email, so current users keep their content
- Private site: visitors who aren't signed in are sent straight to Microsoft sign-in
- Sign out of Microsoft too when logging out of WordPress
Notes
- MFA is enforced in Entra with Conditional Access, so the plugin doesn't need to handle it.
- Groups overage: if a user is in more than about 200 groups, Entra leaves the list out of the token. The plugin detects this and logs it. App roles avoid the problem.
- Lockout safety: a role rule never demotes an administrator, and the normal WordPress password form stays available for break-glass access.
- Uninstalling removes the settings and log, but keeps user accounts.
Requirements
WordPress 6.4+, PHP 7.4+ with OpenSSL, HTTPS.