On iOS, I am trying to use Xamarin.Auth and the Google Drive APIs and I’m having trouble creating a Google Drive service with stored credentials. I’m using Xamarin.Auth (1.5.0) and the Google Drive API (v3).
Here is what I’ve done so far.
In my authentication initialization routine, I’m using a native SFSafariViewController
with Xamarin.Auth...
// Create an Authenticator and subscribe to Completed Events
var authorizeURL = new Uri ("https://accounts.google.com/o/oauth2/auth");
var redirectURL = new Uri ("com.googleusercontent.apps.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:/oauth2redirect");
var accessTokenURL = new Uri ("https://www.googleapis.com/oauth2/v4/token");
Authenticator = new Xamarin.Auth.OAuth2Authenticator (ClientID, ClientSecret, GoogleDriveScope, authorizeURL, redirectURL, accessTokenURL, null, true);
Authenticator.Completed += OnAuthCompleted;
then I intercept the response in my AppDelegate's OpenUrl
method…
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
// Google Authentication - because we are using NativeUI
if (sourceApplication == "com.apple.SafariViewService")
{
Uri uri_abs = new Uri(url.AbsoluteString);
App.Manager.GoogleDriveService.Authenticator.OnPageLoading(uri_abs);
return true;
}
//...
and my OnAuthCompleted
method is called, where I’m able to save an Xamarin.Auth.AccountStore
...
private async void OnAuthCompleted (object sender, AuthenticatorCompletedEventArgs e)
{
if (e.IsAuthenticated) { // Success
Store.Save(e.Account, “google”);
// ...
So far so good. But how do I new up a Google.Apis.Drive.v3.DriveService using saved credentials in a Xamarin.Auth.AccountStore?
Before, with the older API, when initializing the DriveService, I used to be able to pass in an IAuthenticator
, but now I see that the DriveService
class takes an Google.Apis.Services.BaseClientService.Initializer
. Are there any samples that demonstrate using Xamarin.Auth AccountStores on iOS with the GoogleDrive API?