Laravel socialite config access type as offline google login

Well i am trying to implement in laravel 5.1 login from google using socialite and i have no problem with scopes but i need to implement access_type as offline someone knows how i can set this up in socialite for Laravel?

this is my line of communication

$scopes = [
        'https://www.googleapis.com/auth/plus.me',
        'https://www.googleapis.com/auth/plus.profile.emails.read',
        'https://www.googleapis.com/auth/gmail.readonly'

    ];
    return Socialize::driver('google')->scopes($scopes)->setAccessType('offline')->redirect();

      

thanks for the help

+3


source to share


2 answers


I literally only had this problem yesterday while playing around with the Gmail API.

I am assuming that you want to get a refresh token for an already authenticated user. I couldn't find a way to do this natively in Socialite (I'm not sure where you are getting the method setAccessType()

from as it doesn't exist in google or provider abstract classes).



In the end, I just temporarily changed the string returned by the method getAuthUrl()

to bind the query string parameter at the end, went through the authentication process, and then returned the file (so that there was no Composer moaning at me next time I updated).

It's not a perfect solution, but hopefully it helps if you just want to re-authenticate yourself.

0


source


Maybe an update since the last answer to this question; it looks like Taylor added functionality to pass optional parameters. Call the method with

using an associative array:



$scopes = [
    'https://www.googleapis.com/auth/plus.me',
    'https://www.googleapis.com/auth/plus.profile.emails.read',
    'https://www.googleapis.com/auth/gmail.readonly'
];
$parameters = ['access_type' => 'offline'];
return Socialize::driver('google')->scopes($scopes)->with($parameters)->redirect();

      

+15


source







All Articles