Separated laravel app to its own folder (#540)

This commit is contained in:
Julien Nahum
2024-08-26 18:24:56 +02:00
committed by GitHub
parent 39b8df5eed
commit 5bd1dda504
546 changed files with 124 additions and 143 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Integrations\OAuth\Drivers\Contracts;
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

@@ -0,0 +1,55 @@
<?php
namespace App\Integrations\OAuth\Drivers;
use App\Integrations\OAuth\Drivers\Contracts\OAuthDriver;
use Google\Service\Sheets;
use Laravel\Socialite\Contracts\User;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GoogleProvider;
class OAuthGoogleDriver implements OAuthDriver
{
private ?string $redirectUrl = null;
protected GoogleProvider $provider;
public function __construct()
{
$this->provider = Socialite::driver('google');
}
public function getRedirectUrl(): string
{
return $this->provider
->scopes([Sheets::DRIVE_FILE])
->stateless()
->redirectUrl($this->redirectUrl ?? config('services.google.redirect'))
->with([
'access_type' => 'offline',
'prompt' => 'consent select_account'
])
->redirect()
->getTargetUrl();
}
public function getUser(): User
{
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;
}
}