Skip to content

Commit 0320183

Browse files
committed
Fix issue when for unprovisioned user not in group
When a user does not exist in WordPress, auto-provisioning is enabled, group-to-role mapping is enabled, and the signed-in user does not belong to any of the defined groups, we should deny access if there is no default user role defined. If there is a default user role defined, we allow access. This commit addresses issue where un-provisioned users would always get access denied, even if there was a default role defined.
1 parent f3e3f53 commit 0320183

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

aad-sso-wordpress.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Plugin URI: http://github.com/psignoret/aad-sso-wordpress
66
Description: Allows you to use your organization's Azure Active Directory user accounts to log in to WordPress. If your organization is using Office 365, your user accounts are already in Azure Active Directory. This plugin uses OAuth 2.0 to authenticate users, and the Azure Active Directory Graph to get group membership and other details.
77
Author: Philippe Signoret
8-
Version: 0.6.4
8+
Version: 0.6.5
99
Author URI: https://www.psignoret.com/
1010
Text Domain: aad-sso-wordpress
1111
Domain Path: /languages/
@@ -414,13 +414,19 @@ function get_wp_user_from_aad_user( $jwt, $group_memberships ) {
414414
// need to decide whether to create a new user in WordPress on-the-fly, or to stop here.
415415
if ( true === $this->settings->enable_auto_provisioning ) {
416416

417-
// 3. If we are configured to check, and there are no groups for this user, we should not be creating it.
418-
if ( true === $this->settings->enable_aad_group_to_wp_role && empty( $group_memberships->value ) ) {
419-
// The user was authenticated, but is not a member a role-granting group.
417+
// Do not create a user if the user is required to be a member of a group, but is not a member
418+
// of any of the groups, and there is no fall-back role configured.
419+
if ( true === $this->settings->enable_aad_group_to_wp_role
420+
&& empty( $group_memberships->value )
421+
&& empty( $this->settings->default_wp_role ) ) {
422+
423+
// The user was authenticated, but is not a member a role-granting group, and there is
424+
// no default role defined. Deny access.
420425
return new WP_Error(
421426
'user_not_assigned_to_group',
422427
sprintf(
423-
__( 'ERROR: The authenticated user \'%s\' does not have a group assignment for this site.',
428+
__( 'ERROR: Access denied. You\'re not a member of any group granting you'
429+
'access to this site. You\'re signed in as \'%s\'.',
424430
'aad-sso-wordpress' ),
425431
$unique_name
426432
)

0 commit comments

Comments
 (0)