Google Drive API: UserRecoverableAuthIOException (NeedRemoteConsent)

Viewed 493

Background

My app uses Google Drive API to create/manage files in an isolated folder using the non-sensitive scope on a user's Google Drive account after they've linked the account using the standard OAuth consent flow.

I have the following scopes enabled for my OAuth consent screen:

  • ./auth/drive.appdata
  • ./auth/drive.file

Issue

I'm observing user-reported issues where clients are unable to perform actions on their Google Drive account because of the following stack trace:

Non-fatal Exception: com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException
   at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:297)
   at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)
   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:476)
   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:409)
   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:526)
   at com.mystuff.app.cloud.google.drive.GoogleDriveQuery.executeListQuery(GoogleDriveQuery.java:84)
   at com.mystuff.app.cloud.google.drive.GoogleDriveQuery.getList(GoogleDriveQuery.java:39)
   ...
Caused by com.google.android.gms.auth.UserRecoverableAuthException: NeedRemoteConsent
   at com.google.android.gms.auth.zze.zzb(zze.java:13)
   at com.google.android.gms.auth.zzd.zza(zzd.java:77)
   at com.google.android.gms.auth.zzd.zzb(zzd.java:20)
   at com.google.android.gms.auth.zzd.getToken(zzd.java:7)
   at com.google.android.gms.auth.zzd.getToken(zzd.java:5)
   at com.google.android.gms.auth.zzd.getToken(zzd.java:2)
   at com.google.android.gms.auth.GoogleAuthUtil.getToken(GoogleAuthUtil.java:55)
   at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:267)
   at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:292)
   at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)
   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:476)
   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:409)
   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:526)
   at com.mystuff.app.cloud.google.drive.GoogleDriveQuery.executeListQuery(GoogleDriveQuery.java:84)
   ...

Code

The code that executes is this, it essentially fetches a list of all the eligible folders that my app has created:

private FileList executeListQuery(GoogleDriveService driveService, String q, String pageToken) {
  try {
    final Drive.Files.List query =
        driveService
            .get()
            .files()
            .list()
            .setSpaces("drive")
            .setQ(q)
            .setFields(FILE_LIST_FIELDS)
            .setOrderBy("createdTime desc");
    if (pageToken != null) {
      query.setPageToken(pageToken);
    }
    return query.execute();
  } catch (IOException e) {
    return null;
  }
}

I don't think the issue is specific to this block of code but anywhere I execute queries to the Google API.

Question

It seems like this issue is happening to some users only even though they have consented to all the requested permissions and my API config has the correct non-sensitive scopes enabled. I'm unable to reproduce the issue on my own client but I am able to confirm through user-provided screenshots that this issue occurs even though permissions are fully granted during the consent screen.

Does anyone know what might be causing this issue? This issue seems to occur for certain users all the time and doesn't seem to fix itself. I'm unsure if it's account-specific.

Other context and things I've tried:

  • Happens across multiple Android versions (at least from 8 to 11)
  • I've attempted to revoke my own test account's Google Drive permissions but technically my app requires it and won't complete the OAuth without it
  • This post on SO sounds similar but my feature already works for most devices so I think my API scopes are already set up correctly

enter image description here

0 Answers
Related