3

I am setting up my app with Google sign in and can't figure how you get the access token. We have a front-end app where the user logs in. I then need to send the access token to the back end for user authentication. I fetch the user details (name etc) and also get the authentication-token.

I used the code given by Google and the examples from here: https://github.com/googlesamples/google-services/tree/master/android/signin

I got through all the stages but I can't figure where I get the access token to send to the backend for authentication. It says in the docs that the auth token "can be exchanged for an access and refresh token" but I can't for the life of me find out how.

I am a newbie with Google signin so I might be doing it completely wrong.

After posting I found a similar question: Google login get access token with new GoogleSignInOptions

Community
  • 1
  • 1
theblitz
  • 6,683
  • 16
  • 60
  • 114
  • Have you read this ? https://developers.google.com/android/guides/http-auth – Vyacheslav Jan 31 '16 at 16:02
  • Yes. I followed those instructions. My code looks exactly like that (even kept the same names). It returns an Authentication token but from what I understand this is not the same as an access token. – theblitz Jan 31 '16 at 16:14
  • Sorry - I seem to have confused things. I am using the GoogleApiClient and apparently it doesn't return an access token. Just found a similar question: http://stackoverflow.com/questions/33844330/google-login-get-access-token-with-new-googlesigninoptions – theblitz Feb 01 '16 at 08:53
  • Does http://android-developers.blogspot.com/2016/01/using-google-sign-in-with-your-server.html help? – Steven Feb 03 '16 at 05:52
  • Possible duplicate of [How to get access token after user is signed in from Gmail in Android?](https://stackoverflow.com/questions/33998335/how-to-get-access-token-after-user-is-signed-in-from-gmail-in-android) – Gauthier Nov 15 '18 at 13:49

1 Answers1

2

After SignIn , you get object with email and another information You can use method authentication of this object for getting object with access_token

Example in flutter :

var response =  await _googleSignIn.signIn();
var email = response.email;
var response2 = await response.authentication;
var accessToken = response2.accessToken;
Hunter
  • 29
  • 6