The data that was being saved on the config settings for 'no_account_authenticated_user_account' was the User ID so we should change the code from user_load_by_name to user_load;
<?php
- $user = user_load_by_name($config->get('no_account_authenticated_user_account'));
+ $user = user_load($config->get('no_account_authenticated_user_account'));
?>
I have also modified the error message if the $user is empty:
<?php
- \Drupal::messenger()->addError(t('You have been authenticated but there is now account matching your access and now default role has been provided. Please contact a site administrator.'));
+ \Drupal::messenger()->addError(t('You have been authenticated but there is no account available for you to continue logging in. Please contact a site administrator.'));
?>
The logger also tries to pull an empty $user object so I removed it.
<?php
\Drupal::logger('saml_sp')->notice('User authenticated via %idp_label with email %mail, cannot grant access to generic account as the generic account could not be loaded.', [
'%idp_label' => $idp->label(),
'%mail' => $email,
'%name' => $user->getAccountName(),
?>
Attached is the patch I made.
Comments
Comment #2
mjgruta commentedComment #6
jrglasgow commenteduser_load is deprecated, I changes to Drupal\user\Entity\User::load()
merged