From 5422c00e6ded029720d98dcdfe1bbbc61256fe77 Mon Sep 17 00:00:00 2001 From: Andres Rosado Date: Thu, 22 Aug 2019 09:20:06 -0400 Subject: [PATCH 1/2] Changed how the email is obtained from the IdP It takes into consideration if the email sent on the `nameid` field by the IdP is invalid. --- inc/namespace.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/inc/namespace.php b/inc/namespace.php index c9d732a..fab279b 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -350,12 +350,11 @@ function get_or_create_wp_user( \OneLogin\Saml2\Auth $saml ) { // Check whether email is the unique identifier set in SAML IDP $is_email_auth = 'emailAddress' === substr( $saml->getNameIdFormat(), - strlen( 'emailAddress' ) ); + $email = filter_var( $saml->getNameId(), FILTER_VALIDATE_EMAIL ); - if ( $is_email_auth ) { - $email = filter_var( $saml->getNameId(), FILTER_VALIDATE_EMAIL ); - } else { + if ( $is_email_auth && !$email ) { $email_field = $map['user_email']; - $email = current( (array) $saml->getAttribute( $email_field ) ); + $email = current( (array) $saml->getAttribute( $email_field ) ); } /** From 3e7338aa84908ca16a1d0606ef726888f533c6fa Mon Sep 17 00:00:00 2001 From: Andres Rosado Date: Thu, 22 Aug 2019 09:24:11 -0400 Subject: [PATCH 2/2] Fixing lint error --- inc/namespace.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/namespace.php b/inc/namespace.php index fab279b..d0bf4fc 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -352,7 +352,7 @@ function get_or_create_wp_user( \OneLogin\Saml2\Auth $saml ) { $is_email_auth = 'emailAddress' === substr( $saml->getNameIdFormat(), - strlen( 'emailAddress' ) ); $email = filter_var( $saml->getNameId(), FILTER_VALIDATE_EMAIL ); - if ( $is_email_auth && !$email ) { + if ( $is_email_auth && ! $email ) { $email_field = $map['user_email']; $email = current( (array) $saml->getAttribute( $email_field ) ); }