简体   繁体   中英

Laravel socialite config access type as offline in google login

Well i'm trying to implement in laravel 5.1 the login with google using socialite and i don´t have problems with the scopes but i need to implement the access_type as offline, somebody know, how can i configure this in socialite for laravel?

this is my connection line

$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 your help

Maybe an update since this question was last answered; looks like Taylor added functionality to pass optional parameters. Call the with method with 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 Socialite::driver('google')->scopes($scopes)->with($parameters)->redirect();

I literally had this issue only yesterday when playing about with the Gmail API.

I assume you're wanting 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're getting an setAccessType() method from as it doesn't exist in the the Google or abstract provider classes).

In the end, I just temporarily changed the string the getAuthUrl() method returned to tack the query string parameter on the end, went through the authentication process, then reverted the file (so as not to have Composer moan at me next time I updated).

It's not an ideal solution, but hopefully it helps if you're just wanting to re-authenticate yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM