Skip to content

Commit

Permalink
[6.x] – Override default EloquentUserProvider to check $user->authPas…
Browse files Browse the repository at this point in the history
…sword before checking hashes match
  • Loading branch information
joelbutcher authored Jul 30, 2024
1 parent 7c32ec8 commit 5309717
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Auth/SocialstreamUserProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace JoelButcher\Socialstream\Auth;

use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;

class SocialstreamUserProvider extends EloquentUserProvider
{
public function validateCredentials(UserContract $user, #[\SensitiveParameter] array $credentials): bool
{
if (is_null($user->getAuthPassword())) {
return false;
}

return parent::validateCredentials($user, $credentials);
}
}
10 changes: 10 additions & 0 deletions src/SocialstreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use JoelButcher\Socialstream\Actions\ResolveSocialiteUser;
use JoelButcher\Socialstream\Actions\SetUserPassword;
use JoelButcher\Socialstream\Actions\UpdateConnectedAccount;
use JoelButcher\Socialstream\Auth\SocialstreamUserProvider;
use JoelButcher\Socialstream\Concerns\InteractsWithComposer;
use JoelButcher\Socialstream\Http\Livewire\ConnectedAccountsForm;
use JoelButcher\Socialstream\Http\Livewire\SetPasswordForm;
Expand Down Expand Up @@ -76,6 +77,7 @@ protected function registerResponseBindings(): void
*/
public function boot(): void
{
$this->configureAuth();
$this->configureDefaults();
$this->configureRoutes();
$this->configureCommands();
Expand All @@ -91,6 +93,14 @@ public function boot(): void
}
}

private function configureAuth(): void
{
Auth::provider('eloquent', fn ($app, array $config) => new SocialstreamUserProvider(
hasher: $app['hash'],
model: $config['model']
));
}

/**
* Sets sensible package defaults.
*/
Expand Down

0 comments on commit 5309717

Please sign in to comment.