klippa-app/nativescript-login

How to get google access token for iOS?

Closed this issue · 4 comments

There is no issue with the plugin its just that access token is not available GoogleSignInResult property unlike in facebook.
Thank you so much

Hello. Did you read the documentation for the Google options? Especially SignInType and ServerClientId?

Hi, yes but Im having this error.
Error while singing in to Google: Missing ServerClientId while SignInType is ServerAuthCode
Where can i get/put this ServerClientId?

Im sorry Im still new with nativescript. Not sure how they did it in nativescript-oauth2 but that is not working in iOS after we add the firebase plugin, after successful login the user will be redirected to a blank google search page instead of returning the results. Before we implement the firebase plugin, At android and iOS we can get the access token and pass it to BE side without ServerClientID

I finally find out how to get the access token, good thing the code is well written and kinda easy to understand result.AccessToken = signInDetails.User.authentication.accessToken;

For Google this works different from Facebook. Facebook gives you a token that you can use directly to interact with the API.
For Google you should add a ServerClientId to your request and set SignInType=ServerAuthCode, then Google will return an Auth Code that you can exchange server side for an access token to interact with the API and fetch the profile.

You can also add RequestIdToken: true and then the SDK will return an JWT Token that you can also verify serverside.

The benefit of this is that the user will never have access to the authentication token (with server code) or can't alter it (with ID token), only you will have it serverside.
You can read more about it here:
https://developers.google.com/identity/sign-in/android/backend-auth (Android)
https://developers.google.com/identity/sign-in/ios/backend-auth (iOS)

I'll close this for now.