Skip to content

Commit

Permalink
Always fallback if fallback credentials have been given
Browse files Browse the repository at this point in the history
Closes #287
  • Loading branch information
stevebauman committed May 30, 2021
1 parent 7d0d7dc commit 0ea1567
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/Auth/DatabaseUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,23 @@ public function updateRememberToken(Authenticatable $user, $token)
*/
public function retrieveByCredentials(array $credentials)
{
// If an LDAP user is not located by their credentials and fallback
// is enabled, we will attempt to locate the local database user
// instead and perform validation on their password normally.
if (! $user = $this->fetchLdapUserByCredentials($credentials)) {
return isset($credentials['fallback'])
? $this->retrieveByCredentialsUsingEloquent($credentials)
$this->fallback = isset($credentials['fallback']);

$fetch = function () use ($credentials) {
return $this->fetchLdapUserByCredentials($credentials);
};

// If fallback is enabled, we want to make sure we catch
// any exceptions that may occur so we do not interrupt
// the fallback process and exit authentication early.
$user = $this->fallback ? rescue($fetch) : value($fetch);

// If the user was unable to be located and fallback is
// enabled, we will attempt to fetch the database user
// and perform validation on their password normally.
if (! $user) {
return $this->fallback
? $this->retrieveByCredentialsUsingEloquent($credentials['fallback'])
: null;
}

Expand All @@ -187,9 +198,7 @@ public function retrieveByCredentials(array $credentials)
*/
protected function retrieveByCredentialsUsingEloquent($credentials)
{
$this->shouldFallback();

return $this->eloquent->retrieveByCredentials($credentials['fallback']);
return $this->eloquent->retrieveByCredentials($credentials);
}

/**
Expand Down

0 comments on commit 0ea1567

Please sign in to comment.