vITs
vITs

Reputation: 1560

Google apis sdk for windows phone store app

I have developed windows phone store app and integrated google login without using Google.Apis sdk.

I used WebAuthenticationBroker and its working fine.

UPDATE 1:

Now I am trying to explore updated Google.Apis SDK for google integration for login.

I am able to get into google login screen by using this:

credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                new Uri("ms-appx:///Assets/client_secrets.json"),
                new[] { "openid", "email" , "profile"},
                "user",
                CancellationToken.None);

and in webAuthenticationResult getting response containg code needed further.

But, to use it further I needed to know all APIs it gives apart from GoogleWebAuthorizationBroker.AuthorizeAsync, Is there any API document You explained about Blogger/Drive APIs but not about access token expiry handling APIs normal login flow needs.

I will be very thankful to you if you take time and give me a direction on how to use this SDK for second time app launch, handle token expiry using refresh token as I seen it is navigated to login page every time I use GoogleWebAuthorizationBroker.AuthorizeAsync.

Should we need to handle these all scenarios or SDK takes care about it?

Any help is really appreciated Peleyal. Thanks.

Upvotes: 0

Views: 518

Answers (1)

peleyal
peleyal

Reputation: 3512

I just updated the documentation earlier today to include a short tutorial for using OAuth 2.0 in Windows Phone 8.1 apps.

Take a look: https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#wp81

UPDATE:

It's important to mention that as part of the Google Apis Auth library, when getting the authorization code, the app will replace it with refresh and access tokens.
The access token will be automatically refreshed using the refresh token, as you can find out in: https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#credentials

UPDATE 2:
By following the instructions, I saw that the flow confused some of our users (I'll be update the doc soon), and I'm trying to make it clear here:

  • In the first time that you need to access Google APIs you should call your GetFilesAsync (or some other function that access files \ videos \ blogs or whatever API you are using).
    This will eventually result in calling to GoogleWebAuthorizationBroker.AuthorizeAsync. The implementation checks if there are already access and refresh tokens, and because there aren't, it continues to check if an authorization code was saved in data store using SerializableWebAuthResult.Name. That's not the case, so it starts the authorization flow which suspends the current app and opens the login window.

  • After the app is activated again, we call the continuation manager to continue the flow (Step 5 in the doc), which in turn calls ContinueWebAuthentication (step 6).
    The ContinueWebAuthentication stores the authorization code we just received and calls GetFilesAsync again. This time an authorization code exists in the data store, so the AuthorizeAsync method exchanges it for access and refresh token and stores them in the data store. Then it's the developer responsibility to delete the authorization code form the data store (using the SerializableWebAuthResult.Name key. This step will might be simplified in the future).

  • Notice that in this point, the access token and refresh token are stored so any future call to GetFiles and AuthorizeAsync will result in retrieving the tokens form the data store and checking if the access token is still valid, if not - the library will automatically refresh it for you using the refresh token.

Hope that it make the flow clearer, feel free to add more comments so I'll try to make this flow as clear as possible.

Upvotes: 3

Related Questions