catalyst / moodle-auth_saml2

SAML done 100% in Moodle, fast, simple, secure
https://moodle.org/plugins/auth_saml2
70 stars 132 forks source link

When creating new user, Notice: Undefined property: stdClass::$username in /.../auth/saml2/classes/auth.php on line 963 #739

Closed thepurpleblob closed 1 year ago

thepurpleblob commented 1 year ago

Version: 2022111700 Moodle: 3.11.11

When creating a new user with SAML2 the above notice is thrown.

Analysis: This error is occurring in function update_user_record_from_attribute_map(&$user, $attributes, $newuser= false) At the above line a call to $this->is_email_taken($email, $user->username) is made which tries to get the username from the $user record.

However... The update_user_record_from_attribute_map function is being called from within function saml_login_complete, specifically the block starting around line 670 that checks for !$user and then creates $user as an empty object. When update_user_record_from_attribute_map is called at line 696, $user is still an empty object and therefore the call to is_email_taken will generate a notice.

An additional check is required for $user->username having a value.

danmarsden commented 1 year ago

duplicates #734 - will try to get a new release out soon.. - was hoping to do a simplesaml update at the same time...

hope you have a good Christmas!

thepurpleblob commented 1 year ago

Ahh.... I did look but I missed it.

Hoe you have a good Christmas too :)