Google SignIn error getToken() -> NEED_REMOTE_CONSENT

Viewed 2110

Few month ego, my google signIn procedure works without problem, but today the emulator reply me in the Logcat this error:

E/Auth: [GoogleAccountDataServiceImpl] getToken() -> NEED_REMOTE_CONSENT. App: com_pro.bandweb.mycpstore, Service: oauth2:email https://www.googleapis.com/auth/spreadsheets.readonly openid profile

try to look in google but I not find any suggestion...this are the code that I use for sigIn:

public void InitGoogle() throws IOException {
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(SPREADSHEETS_SCOPE))
                .requestEmail()
                .build();
        googleSignInClient = com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(this, gso);

        if (GoogleSignIn.getLastSignedInAccount(this) == null) {
            Log.v(TAG, "getting sign-on again");
            //startActivityForResult(googleSignInClient.getSignInIntent(), RC_SIGN_IN);
            SignInActivityResult.launch(googleSignInClient.getSignInIntent());
        } else {
            Log.v(TAG, "sign-on is still good, reusing");

            //faccio la richiesta solo se è stato inserito il foglio di google shhet nelle preferenze, altrimenti avviso
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
            if (!sharedPreferences.contains(getString(R.string.pref_googleSheetId_key))
                    || StringUtils.isBlank(sharedPreferences.getString(getString(R.string.pref_googleSheetId_key), ""))
                    || !(spreadsheetIdPattern.matcher(sharedPreferences.getString(getString(R.string.pref_googleSheetId_key), ""))).find()) {
                // no Google sheet ID has been specified - can't retrieve ingredients
                progressBar.setVisibility(ProgressBar.GONE);
                Toasty.info(this, getString(R.string.missing_pref_id_sheet_title), Toasty.LENGTH_LONG, true).show();
            }else {
                //scelgo il tipo di sincronizzazione quando inizializzo il tablet, in base alla scelta nelle preferenze
                if(AppSettings.get().getSyncModeOnStartup() == UPLOAD_DATI)
                    synchGoogleSheet(UPLOAD_DATI);
                else if(AppSettings.get().getSyncModeOnStartup() == DOWNLOAD_DATI)
                    synchGoogleSheet(DOWNLOAD_DATI);
                else
                    synchGoogleSheet(UPLOAD_DOWNLOAD_NONE);
            }
        }
        progressBar.setVisibility(ProgressBar.GONE);

..
..
..
..





ActivityResultLauncher<Intent> SignInActivityResult= registerForActivityResult(
        new ActivityResultContracts.StartActivityForResult(),
        new ActivityResultCallback<ActivityResult>() {
            @Override
            public void onActivityResult(ActivityResult result) {
                if(result.getResultCode() != RESULT_CANCELED) {
                    if (result.getResultCode() == Activity.RESULT_OK && null != result.getData())
                    {
                        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(result.getData());
                        handleSignInResult(task);
                    }
                }else{
                    progressBar.setVisibility(ProgressBar.GONE);
                }
            }
        });
7 Answers

I had the same issue on a Google Pixel 5 with Android 11.

2021-08-11 13:32:59.603 29917-30363/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> NEED_REMOTE_CONSENT. App: de.aoksystems.ma.abp.app.internal, Service: oauth2:https://www.googleapis.com/auth/fitness.activity.read https://www.googleapis.com/auth/fitness.heart_rate.read https://www.googleapis.com/auth/fitness.nutrition.read

But it works fine on a Samsung S10 with Android 11

4 Weeks ago it works.

Make sure you do all steps below:

In my case, after a lot of solutions without working. I found and used this solution for only UserRecoverableAuthIOException error, and it work.

Java version

catch (UserRecoverableAuthIOException userRecoverableException) {
   myActivity.startActivityForResult(
   userRecoverableException.getIntent(), MyActivity.REQUEST_AUTHORIZATION);
}

Kotlin version

catch (e: Exception) {
   if (e is UserRecoverableAuthIOException) {
   myActivity.startActivityForResult(e.getIntent(), MyActivity.REQUEST_AUTHORIZATION);
   } else {
      // other cases
   }
}
   

I'm experiencing the same error, and for me it's looking like it's related to my Google account.

My app uses the Google Drive API, and I haven't touched the code since 2016. I don't use the app that often, but at some point in the past year the drive integration stopped working for me on my old phone which was running Android 8. I've just switched to a new phone running Android 11, and get the same error on that. However, one other person is using my app and they have no issues at all (also Android 11).

In the security section of my Google account my app used to appear as having third-party access, however that's now disappeared and I know I wouldn't have revoked it myself. For the other user of my app it's still present in their account.

Update: I've managed to resolve this, without actually making any code changes to the app. I set up an emulator (Pixel 5, Android 11) connected to my Google account, ran my app on that and it correctly displayed the consent screen instead of returning this error. After allowing that, and thus having my app now appear in my account as having third-party access, functionality of the app was immediately restored on my phone.

It doesn't sound like this solution will work for everyone, but at least in my case that error message seemed to mean my account wasn't authorised for my app, and was stuck in such a way that it needed another device/emulator to "force" it through.

I had the same problem with Google Drive API. I was requesting DRIVE_FILE and DRIVE scopes. I deleted requesting DRIVE scope permission and the problem disappeared. I'm pretty sure the problem is encountered by developers, who doesn't have necessary permissions in Google API Console. So, you should check your permissions there.

In my app this error message was caused by missing OAuth Consent screen. To fix that you have to do following:

  1. Go to Google Cloud Console
  2. Select your project
  3. Select APIs & Service
  4. Select OAuth consent screen
  5. Fill all required information

After doing that NEED_REMOTE_CONSENT error disappeared immediately.

In my case, this seems it may be related to Android 12.

My app runs and authenticates fine on Android R (API30) but when I deploy the same apk on Android S (API31) I get the exact same error message:

E/Auth: [GoogleAccountDataServiceImpl] getToken() -> NEED_REMOTE_CONSENT.  In both cases I'm testing on the Android Emulator as well a physical devices.

In my case, the problem is in accessing the Google Fit and Google Tasks APIs

Related