CrossGeeks / GoogleClientPlugin

Google Client Plugin for Xamarin iOS and Android
https://www.pujolsluis.com/google-client-plugin-for-xamarin/
MIT License
89 stars 37 forks source link

Not able to get AccessToken and RefreshToken #22

Closed Lemedon closed 5 years ago

Lemedon commented 5 years ago

Describe the bug Hi! , I am not able to receive the access and refresh tokens with this library. I wanted to exchange the ActiveToken to access and refresh token directly from my app by calling this endpoint https://developers.google.com/identity/protocols/OAuth2WebServer#exchange-authorization-code but I only receive access_token with expires after 1 hour and without refresh_token. How can I access Google services like Gmail or Drive by using this library? Maybe I’m missing some authentication flow? Thanks for help :/

Pujolsluis commented 5 years ago

Hey @Lemedon ,

To access different API services from your backend server you need to initialize the plugin the scopes you want to use, you can read more about the topic here https://developers.google.com/identity/sign-in/android/offline-access

I believe @RomaRudyak can help you out with any questions about this, he collaborated with adding support for it on the plugin to make use of it on his projects. 💪

// Initialize method signature on Android
public static void Initialize(
            Activity activity,
            string serverClientId = null,
            string clientId = null,
            Api[] apis = null,
            string[] scopes = null)
// Initialize method signature on iOS
public static void Initialize(string clientId = null, params string[] scopes)
Lemedon commented 5 years ago

Yes, I’m passing scopes correctly but I’m not able to receive refresh token to get access token every time my user want to see his gmail or google drive data.

Lemedon commented 5 years ago

@RomaRudyak can you help me with this data flow?

RomaRudyak commented 5 years ago

@Lemedon Hi,

sorry for late replay.

  1. Do you using some kind of IoC containers or Productivity Frameworks for your project?
  2. Do you use web key as clientId ?
Lemedon commented 5 years ago
  1. Yes Im using MvvmCross
  2. Im passing clientId from auto-generated google web application as parameter to Initialize() method as @Pujolsluis has mentioned before but it's returns AccessToken only for iOS version. I would like to receive auto refreshed access_token every time on every platform . Is that possible?
RomaRudyak commented 5 years ago

@Lemedon do you register plugin as singelton in IoC of MvvmCross ? If yes, on Android MvvmCross creates first viewmidel which leads to resolving all dependencies and only then creates activity where configuration of plugin happens.

For now plugin not supports lazy configuration.

Pujolsluis commented 5 years ago

Hey @Lemedon ,

Any updates on your issue?. Thanks for all the support @RomaRudyak💪

Pujolsluis commented 5 years ago

Will proceed to close this issue, since there are no further updates.

Thanks again @RomaRudyak for your support🙌.