Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar: Additional Scope enforced to be requested when it is not needed #17922

Open
bunnis opened this issue Aug 21, 2023 · 11 comments
Open

Calendar: Additional Scope enforced to be requested when it is not needed #17922

bunnis opened this issue Aug 21, 2023 · 11 comments
Labels
api: calendar Issues related to the Calendar API API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@bunnis
Copy link

bunnis commented Aug 21, 2023

Environment details

  1. Specify the API at the beginning of the title. Calendar API
  2. OS type and version: Android target SDK 33
  3. Java version: Android 13
  4. version(s): com.google.apis:google-api-services-calendar:v3-rev20230707-2.0.0

Steps to reproduce

  1. Sign-In to Google and request Scope CALENDAR_EVENTS_READONLY =
    https://www.googleapis.com/auth/calendar.events.readonly"
  2. Retrieve the Calendar Events List for a certain CalendarID
  3. Get warning [GoogleAuthUtil] isUserRecoverableError status: NEED_REMOTE_CONSENT, which triggers exception UserRecoverableAuthIOException
  4. Upon handling exception, Request_Permission is requesting Scope "https://www.googleapis.com/auth/calendar". This is not needed, as observed in https://developers.google.com/calendar/api/v3/reference/events/list, and selecting only the events.readonly scope

Code example (simplified)

        GoogleSignInOptions mGoogleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .requestScopes(new Scope(CalendarScopes.CALENDAR_EVENTS_READONLY)) //https://developers.google.com/identity/protocols/oauth2/scopes#calendar
                .build();

        // Build a GoogleSignInClient with the options specified by gso.
        GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(MainActivity.this, mGoogleSignInOptions);
        Intent signInIntent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(signInIntent, SIGN_IN_REQUEST_CODE); 


            do {
                page++;
                Events events;
                Log.i(appLogTAG, "Sending events request, page "+page);

                events = calendarService.events().list(calendarID).execute();


                List<Event> items = events.getItems();

                for (Event event : items) {
                    //some work
                }

                pageToken = events.getNextPageToken();
                syncToken = events.getNextSyncToken();
            } while (pageToken != null);


        }catch (UserRecoverableAuthIOException e) {
            toastInUI("Error while retrieving data. ");

            //request missing permissions
            Intent intent = e.getIntent();
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            appContext.startActivity(intent);

        } catch (GoogleJsonResponseException e) {
            if (e.getStatusCode() == 410) {
                // A 410 status code, "Gone", indicates that the sync token is invalid.
                Log.e(appLogTAG,"Invalid sync token, clearing event store and re-syncing.");
            } else {
                throw new RuntimeException(e);
            }
        }catch (SocketTimeoutException e) {
            Log.e(appLogTAG, "Timeout while retrieving data.");
            toastInUI("Timeout while retrieving data.");
        }catch (IOException e) {
            Log.e(appLogTAG, "Unknown error.");
            throw new RuntimeException(e);
        }
       

Stack trace

W  [GoogleAuthUtil] isUserRecoverableError status: NEED_REMOTE_CONSENT

External references such as API reference guides

Any additional information below

I have tried debugging to understand where the enforced permission request comes from without success. From the link in External References the requested Scope is enough to list all events in the Calendar.

Thanks!

@product-auto-label product-auto-label bot added the api: calendar Issues related to the Calendar API API. label Aug 21, 2023
@blakeli0 blakeli0 added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Aug 25, 2023
@blakeli0
Copy link
Contributor

@TimurSadykov Is this something you can help with?

@suztomo
Copy link
Member

suztomo commented Sep 1, 2023

@bunnis Would you attach the stacktrace? It tells file name and line number that causes the exception.

"W" at the beginning is warning.

@bunnis
Copy link
Author

bunnis commented Sep 1, 2023

@suztomo I don't have any indication of the line number that causes the exception, this is what I see in Logcat:

2023-09-01 20:20:06.884 18935-20392 ABSKULAITY.BDAYCN       pt....aity.bdaynotificationsgooglec  I  Starting to Retrieve Calendar Bday Events
2023-09-01 20:20:06.885 18935-20392 ABSKULAITY.BDAYCN       pt....aity.bdaynotificationsgooglec  D  Setting up Google Credentials
2023-09-01 20:20:06.886 18935-20392 ABSKULAITY.BDAYCN       pt....aity.bdaynotificationsgooglec  D  Creating Calendar Service
2023-09-01 20:20:06.891 18935-20392 ABSKULAITY.BDAYCN       pt....aity.bdaynotificationsgooglec  I  Starting the events fetching logic 
2023-09-01 20:20:06.891 18935-20392 ABSKULAITY.BDAYCN       pt....aity.bdaynotificationsgooglec  I  Sending events request, page 1
**2023-09-01 20:20:07.071 18935-20392 Auth                    pt....aity.bdaynotificationsgooglec  W  [GoogleAuthUtil] isUserRecoverableError status: NEED_REMOTE_CONSENT**

@suztomo
Copy link
Member

suztomo commented Sep 8, 2023

exception UserRecoverableAuthIOException

Can I see the stacktrace of this exception?

@bunnis
Copy link
Author

bunnis commented Sep 11, 2023

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:288)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:880)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:552)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:493)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:603)
at mypackage.DataRepo.retrieveCalendarBdayEvents(DataRepo.java:277)
at mypackage.DataRepo.loadData(DataRepo.java:410)
at mypackage.DataRepo.run(DataRepo.java:193)
at java.lang.Thread.run(Thread.java:1012)
                                                                                                    Caused by: com.google.android.gms.auth.UserRecoverableAuthException: NeedRemoteConsent
at com.google.android.gms.auth.zzl.zzg(com.google.android.gms:play-services-auth-base@@18.0.4:20)
at com.google.android.gms.auth.zzl.zzb(com.google.android.gms:play-services-auth-base@@18.0.4:4)
at com.google.android.gms.auth.zzf.zza(Unknown Source:6)
at com.google.android.gms.auth.zzl.zzh(com.google.android.gms:play-services-auth-base@@18.0.4:6)
at com.google.android.gms.auth.zzl.zza(com.google.android.gms:play-services-auth-base@@18.0.4:15)
at com.google.android.gms.auth.zzl.getToken(com.google.android.gms:play-services-auth-base@@18.0.4:3)
at com.google.android.gms.auth.zzl.getToken(com.google.android.gms:play-services-auth-base@@18.0.4:1)
at com.google.android.gms.auth.zzl.getToken(com.google.android.gms:play-services-auth-base@@18.0.4:6)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(com.google.android.gms:play-services-auth-base@@18.0.4:3)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:258)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:283)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:880)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:552)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:493)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:603)
at mypackage.DataRepo.retrieveCalendarBdayEvents(DataRepo.java:277)
at mypackage.DataRepo.loadData(DataRepo.java:410)
at mypackage.DataRepo.run(DataRepo.java:193)
at java.lang.Thread.run(Thread.java:1012)

@suztomo
Copy link
Member

suztomo commented Sep 21, 2023

Thank you.

@TimurSadykov
Copy link
Member

@blakeli0 No, sorry, it looks like this code does not use GUAC auth libs.

@bunnis
Copy link
Author

bunnis commented Oct 9, 2023

any progress?

@TimurSadykov
Copy link
Member

@bunnis The main problem seems to be the "NEED_REMOTE_CONSENT" error. This seems to be service specific and related to app verification status or error handeling, do you have your app verified, have you tried to handle like in the example?

@bunnis
Copy link
Author

bunnis commented Oct 27, 2023

@TimurSadykov I handle the error correctly and everything works. The main problem is that using the API vs Web, the permissions are different. Via Web I only need read-only permission the access the data. Using the API, if I request the read-only permission then the Error Handling will force me to request read and write permissions. Obviously this is a different behaviour than the Web. Please refer to my initial description in 4:

Upon handling exception, Request_Permission is requesting Scope "https://www.googleapis.com/auth/calendar". This is not needed, as observed in https://developers.google.com/calendar/api/v3/reference/events/list, and selecting only the events.readonly scope

@blakeli0 blakeli0 added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 19, 2024
@bunnis
Copy link
Author

bunnis commented Jan 30, 2024

gentle nudge @TimurSadykov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: calendar Issues related to the Calendar API API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants