Skip to content

Commit

Permalink
Merge pull request #88 from dcc-bjorn/main
Browse files Browse the repository at this point in the history
Provide oauth user to login event
  • Loading branch information
dododedodonl authored Mar 20, 2024
2 parents 4326cae + 4f1c93a commit dc457f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Events/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Laravel\Socialite\Contracts\User as SocialiteUser;

class Login
{
Expand All @@ -18,6 +19,7 @@ class Login
*/
public function __construct(
public FilamentSocialiteUserContract $socialiteUser,
public SocialiteUser $oauthUser,
) {
}
}
10 changes: 5 additions & 5 deletions src/Http/Controllers/SocialiteLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ protected function isUserAllowed(SocialiteUserContract $user): bool
return in_array($emailDomain, $domains);
}

protected function loginUser(string $provider, FilamentSocialiteUserContract $socialiteUser): RedirectResponse
protected function loginUser(string $provider, FilamentSocialiteUserContract $socialiteUser, SocialiteUserContract $oauthUser): RedirectResponse
{
// Log the user in
$this->socialite->getGuard()->login($socialiteUser->getUser(), $this->socialite->getPlugin()->getRememberLogin());

// Dispatch the login event
Events\Login::dispatch($socialiteUser);
Events\Login::dispatch($socialiteUser, $oauthUser);

return app()->call($this->socialite->getLoginRedirectCallback(), ['provider' => $provider, 'socialiteUser' => $socialiteUser]);
}
Expand All @@ -115,7 +115,7 @@ protected function registerSocialiteUser(string $provider, SocialiteUserContract
Events\SocialiteUserConnected::dispatch($socialiteUser);

// Login the user
return $this->loginUser($provider, $socialiteUser);
return $this->loginUser($provider, $socialiteUser, $oauthUser);
}

protected function registerOauthUser(string $provider, SocialiteUserContract $oauthUser): RedirectResponse
Expand All @@ -132,7 +132,7 @@ protected function registerOauthUser(string $provider, SocialiteUserContract $oa
Events\Registered::dispatch($socialiteUser);

// Login the user
return $this->loginUser($provider, $socialiteUser);
return $this->loginUser($provider, $socialiteUser, $oauthUser);
}

public function processCallback(string $provider): RedirectResponse
Expand All @@ -158,7 +158,7 @@ public function processCallback(string $provider): RedirectResponse
// Try to find a socialite user
$socialiteUser = $this->retrieveSocialiteUser($provider, $oauthUser);
if ($socialiteUser) {
return $this->loginUser($provider, $socialiteUser);
return $this->loginUser($provider, $socialiteUser, $oauthUser);
}

// See if a user already exists, but not for this socialite provider
Expand Down

0 comments on commit dc457f1

Please sign in to comment.