Skip to content

Commit

Permalink
Merge pull request #85 from Gazi96/Add-new-argument-to-wpsimplesaml_m…
Browse files Browse the repository at this point in the history
…atch_user

Add nameID argument to wpsimplesaml_match_user
  • Loading branch information
mikelittle authored Apr 3, 2024
2 parents 0fc8645 + c84da4f commit 87d1d1e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,13 @@ function get_or_create_wp_user( \OneLogin\Saml2\Auth $saml ) {

$map = get_attribute_map();
$attributes = $saml->getAttributes();
$name_id = $saml->getNameId();

// Check whether email is the unique identifier set in SAML IDP

Check failure on line 419 in inc/namespace.php

View check run for this annotation

HM Linter / hmlinter

inc/namespace.php#L419

Inline comments must end in full-stops, exclamation marks, or question marks
Raw output
{
  "line": 419,
  "column": 5,
  "severity": "error",
  "message": "Inline comments must end in full-stops, exclamation marks, or question marks",
  "source": "Squiz.Commenting.InlineComment.InvalidEndChar"
}
$is_email_auth = 'emailAddress' === substr( $saml->getNameIdFormat(), - strlen( 'emailAddress' ) );

if ( $is_email_auth ) {
$email = filter_var( $saml->getNameId(), FILTER_VALIDATE_EMAIL );
$email = filter_var( $name_id, FILTER_VALIDATE_EMAIL );
} else {
$email_field = $map['user_email'];
$email = current( (array) $saml->getAttribute( $email_field ) );
Expand All @@ -430,10 +431,11 @@ function get_or_create_wp_user( \OneLogin\Saml2\Auth $saml ) {
*
* @param string $email Email from SAMLResponse
* @param array $attributes SAML Attributes parsed from SAMLResponse
* @param string $name_id Name ID from SAMLResponse
*
* @return null|false|\WP_User User object or false if not found
*/
$user = apply_filters( 'wpsimplesaml_match_user', null, $email, $attributes );
$user = apply_filters( 'wpsimplesaml_match_user', null, $email, $attributes, $name_id );

if ( null === $user ) {
$user = get_user_by( 'email', $email );
Expand All @@ -447,7 +449,7 @@ function get_or_create_wp_user( \OneLogin\Saml2\Auth $saml ) {

$user_data = [
'ID' => null,
'user_login' => isset( $map['user_login'], $attributes[ $map['user_login'] ] ) ? $attributes[ $map['user_login'] ][0] : $saml->getNameId(),
'user_login' => isset( $map['user_login'], $attributes[ $map['user_login'] ] ) ? $attributes[ $map['user_login'] ][0] : $name_id,
'user_pass' => wp_generate_password(),
'user_nicename' => implode( ' ', array_filter( [ $first_name, $last_name ] ) ),
'first_name' => $first_name,
Expand Down

0 comments on commit 87d1d1e

Please sign in to comment.