Dynamic OauthDriver scope (#544)
* Dynamic OauthDriver scope * support migration for mysql * Refactor default scopes for integrations * Small UI changes * fix flet select tooltip * fix linter * Fix google token size in DB --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -7,7 +7,14 @@ use Laravel\Socialite\Contracts\User;
|
||||
interface OAuthDriver
|
||||
{
|
||||
public function getRedirectUrl(): string;
|
||||
public function setRedirectUrl($url): self;
|
||||
public function setRedirectUrl(string $url): self;
|
||||
public function setScopes(array $scopes): self;
|
||||
public function getUser(): User;
|
||||
public function canCreateUser(): bool;
|
||||
|
||||
/**
|
||||
* Set up all the scopes required by OpnForm for various integrations.
|
||||
* This method configures the necessary permissions for the current OAuth driver.
|
||||
*/
|
||||
public function fullScopes(): self;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use Laravel\Socialite\Two\GoogleProvider;
|
||||
class OAuthGoogleDriver implements OAuthDriver
|
||||
{
|
||||
private ?string $redirectUrl = null;
|
||||
private ?array $scopes = [];
|
||||
|
||||
protected GoogleProvider $provider;
|
||||
|
||||
@@ -22,7 +23,7 @@ class OAuthGoogleDriver implements OAuthDriver
|
||||
public function getRedirectUrl(): string
|
||||
{
|
||||
return $this->provider
|
||||
->scopes([Sheets::DRIVE_FILE])
|
||||
->scopes($this->scopes ?? [])
|
||||
->stateless()
|
||||
->redirectUrl($this->redirectUrl ?? config('services.google.redirect'))
|
||||
->with([
|
||||
@@ -46,10 +47,20 @@ class OAuthGoogleDriver implements OAuthDriver
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setRedirectUrl($url): OAuthDriver
|
||||
public function setRedirectUrl(string $url): OAuthDriver
|
||||
{
|
||||
$this->redirectUrl = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setScopes(array $scopes): OAuthDriver
|
||||
{
|
||||
$this->scopes = $scopes;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function fullScopes(): OAuthDriver
|
||||
{
|
||||
return $this->setScopes([Sheets::DRIVE_FILE]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user