opnform-host-nginx/app/Integrations/OAuth/Drivers/OAuthGoogleDriver.php

40 lines
924 B
PHP
Raw Normal View History

<?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
{
protected GoogleProvider $provider;
public function __construct()
{
$this->provider = Socialite::driver('google');
}
public function getRedirectUrl(): string
{
return $this->provider
->scopes([Sheets::DRIVE_FILE])
->stateless()
->with([
'access_type' => 'offline',
'prompt' => 'consent select_account'
])
->redirect()
->getTargetUrl();
}
public function getUser(): User
{
return $this->provider
->stateless()
->user();
}
}