Search code examples
androidlaraveljwtgoogle-authenticationlaravel-socialite

laravel socialite get google access token from google Authorization Code


I've an Android app that use google authentication to register users
and I am using laravel socillite for the authentication

I can't get this to work because the android app send me an authorization code not the access token and I do't know how can I get the access token from that Authorization Code
From my understanding I should do the following:

  • get the access token from android Authorization Code
  • use Socialite::driver('google')->userFromToken($token) to get user data
  • send JWT token to the android device
    Can anyone explain how can I do this using laravel socillite

Solution

  • I did solve this by using a getAccessTokenResponse function as the followoing:

    $access_token = Socialite::driver($provider)->getAccessTokenResponse($token);
    $user = Socialite::driver($provider)->userFromToken($access_token['access_token']);