I want to login user via Google Javascript SDK which get short time token from Google and then need to send this token to Laravel 11 which shouuld connect to Google with the token and get user data. I would like to use socialite but dont see any documentation which would support this model.
I dont want to redirect user anywhere but use JS SDK. Does Socialite have methods to connect Google with token? Thanks.
I have a Vue application which login user with Google. Javascript get access_token and send this token to Laravel. What I expect is the Socialite should be able to login to Google API with this token and get user data and login user. I tried this
// $token is that one which Javascript send to Laravel
$user_google_data = Socialite::driver('google')->userFromToken($token);
But this throws me an error:
resulted in a `401 Unauthorized` response:
{
"error": "invalid_request",
"error_description": "Invalid Credentials"
}
{"exception":"[object] (GuzzleHttp\\Exception\\ClientException(code: 401): Client error: `GET https://www.googleapis.com/oauth2/v3/userinfo?prettyPrint=false` resulted in a `401 Unauthorized` response:
{
\"error\": \"invalid_request\",
\"error_description\": \"Invalid Credentials\"
}
If you already have a valid access token for a user, you can retrieve their user details using Socialite's userFromToken method:
That means that this is not a way to authenticate, but to retrieve the user's informations. You can use the userFromToken method only if the user is already authenticated.
The userFromToken method is only to retrieve the authenticated user's informations when he is already authenticated, because you need to pass the token to the method.