Is it possible to modify the scopes when connecting with Google? #380
-
I want to access analytics and search console data using the OAuth tokens from the login. 'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('GOOGLE_REDIRECT_URI' ),
'scopes' => [
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/webmasters.readonly',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
],
], It only requests the scopes for email and profile info. I'm using the livewire versions and have been through all the generated files, but I can't see where I should go about making changes. Any pointers would be graciously appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can update the code inside use JoelButcher\Socialstream\Providers;
use Laravel\Socialite\Facades\Socialite;
public function generate(string $provider)
{
$driver = Socialite::driver($provider);
if ($provider === Providers::google()) {
// add scopes here
}
return $driver->redirect();
} |
Beta Was this translation helpful? Give feedback.
-
Thanks! I had to match it against a string and ended up with this: namespace App\Actions\Socialstream;
use JoelButcher\Socialstream\Contracts\GeneratesProviderRedirect;
use Laravel\Socialite\Facades\Socialite;
use Symfony\Component\HttpFoundation\RedirectResponse;
class GenerateRedirectForProvider implements GeneratesProviderRedirect {
/**
* Generates the redirect for a given provider.
*/
public function generate( string $provider ): RedirectResponse {
$driver = Socialite::driver( $provider );
if ( $provider === 'google' ) {
return $driver->scopes( [
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/webmasters.readonly',
] )->redirect();
}
return $driver->redirect();
}
} It seems that scopes get merged with the defaults. |
Beta Was this translation helpful? Give feedback.
You can update the code inside
GenerateRedirectForProvider
: