How to authenticate Google Android using Node server

I am trying to embed a Google Account account in my Android application and authenticate it with my Node server.

I followed this tutorial to successfully implement the Google login button on Android, but I know that I don’t understand how to authenticate it to my back end.

From this documentation, I suggested that I need to get and send getIdToken() or getServerAuthCode() , but I'm not sure which one I should send, so I voted to send getServerAuthCode() .

On my server side of Node, I installed this library and used this method:

 var google = require('googleapis'); var plus = google.plus('v1'); var OAuth2 = google.auth.OAuth2; var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL); // Retrieve tokens via token exchange explained above or set them: oauth2Client.setCredentials({ access_token: 'ACCESS TOKEN HERE', refresh_token: 'REFRESH TOKEN HERE' }); plus.people.get({ userId: 'me', auth: oauth2Client }, function(err,response) { // handle err and response }); 

I thought this was the right method, but then I found this , and I realized that the data returned by getServerAuthCode() must be exchanged for a real access token in order to receive information from the user.

My questions:

1) What data should be sent from Android to Node? (In Node, I get basic information such as email address and username).

2) If I send the correct data, is the library that I use for Node correct? If I am not sending the correct data, in which library do you recommend me checking getIdToken() .

3) In Node, How do I exchange data from getServerAuthCode() to get the desired token and update the token?

Any other authentication information and examples are appreciated.

Thanks.

+5
source share

All Articles