humanmade/wp-simple-saml

Sorry, that username already exists! Error after first login attempt

rfair404 opened this issue · 3 comments

I have installed the plugin and coordinated the metadata with my SAML provider. Everything seems to be working as expected, however when I attempt to log in for a second time I get an error: Sorry, that username already exists!

Any idea how this can be resolved?

I'm experiencing the same issue on a multi site instance. Users were able to sign in and then on a second attempt Sorry, that username already exists! continues to show up.

Looks like on my end it was an issue with a username being used as the NameID while not being an actual email address.

$is_email_auth = 'emailAddress' === substr( $saml->getNameIdFormat(), - strlen( 'emailAddress' ) );
if ( $is_email_auth ) {
$email = filter_var( $saml->getNameId(), FILTER_VALIDATE_EMAIL );
} else {
$email_field = $map['user_email'];
$email = current( (array) $saml->getAttribute( $email_field ) );
}

We had this issue as well because our current site was not using email address for the user logins. so i changed the logic to be

	if ( $is_email_auth ) {
		$email = filter_var( $saml->getNameId(), FILTER_VALIDATE_EMAIL );
	} else {
		$email_field = $map['user_email'];
		$email       = current( (array) $saml->getAttribute( $email_field ) );
	}

	if(!$email)
	{
		//fix for not being able to find the email address
		$email = isset( $map['user_email'], $attributes[ $map['user_email'] ] ) && is_array( $attributes[ $map['user_email'] ] ) ? reset( $attributes[ $map['user_email'] ] ) : '';
	}