7a137 google auth (#520)

* google oauth

* fix lint

* cleanup debug

* Oauth changes, alert message, email validation

* fix exception and inline return condition

* fix google oauth

* UI fixes

* fix provider user

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Favour Olayinka
2024-08-19 14:22:57 +01:00
committed by GitHub
parent 5049ba7fb1
commit 7ac8503201
14 changed files with 273 additions and 52 deletions

View File

@@ -7,5 +7,7 @@ use Laravel\Socialite\Contracts\User;
interface OAuthDriver
{
public function getRedirectUrl(): string;
public function setRedirectUrl($url): self;
public function getUser(): User;
public function canCreateUser(): bool;
}

View File

@@ -10,6 +10,8 @@ use Laravel\Socialite\Two\GoogleProvider;
class OAuthGoogleDriver implements OAuthDriver
{
private ?string $redirectUrl = null;
protected GoogleProvider $provider;
public function __construct()
@@ -22,6 +24,7 @@ class OAuthGoogleDriver implements OAuthDriver
return $this->provider
->scopes([Sheets::DRIVE_FILE])
->stateless()
->redirectUrl($this->redirectUrl ?? config('services.google.redirect'))
->with([
'access_type' => 'offline',
'prompt' => 'consent select_account'
@@ -34,6 +37,19 @@ class OAuthGoogleDriver implements OAuthDriver
{
return $this->provider
->stateless()
->redirectUrl($this->redirectUrl ?? config('services.google.redirect'))
->user();
}
public function canCreateUser(): bool
{
return true;
}
public function setRedirectUrl($url): OAuthDriver
{
$this->redirectUrl = $url;
return $this;
}
}