Encountering NEED_REMOTE_CONSENT error in RequestTokenManager when trying to authorize Google Drive

I’m working on a Kotlin app and I’m having trouble with Google Drive authorization. I’ve set up my app in the Google Cloud Console and enabled the Google Drive API. I’m using credentialManager for authentication.

The initial Google sign-in works fine, but when I try to get authorization for Drive, it fails. The code goes into the addOnSuccessListener, but I don’t get an accessToken or any allowed scopes.

Here’s a simplified version of what I’m trying:

fun authorize(activity: Activity) {
    val driveScope = Scope("https://www.googleapis.com/auth/drive.file")
    val request = AuthorizationRequest.Builder()
        .setRequestedScopes(listOf(driveScope))
        .build()

    Identity.getAuthorizationClient(activity).authorize(request)
        .addOnSuccessListener { result ->
            // This runs, but result.grantedScopes is empty and result.accessToken is null
            println("Authorized scopes: ${result.grantedScopes}")
        }
        .addOnFailureListener { error ->
            println("Auth failed: ${error.message}")
        }
}

Any ideas what I might be doing wrong? I’m stumped!

hey alex, check your oauth consent screen. it might not be fully set up. ensure all req. fields and scopes are added and verify the package name and sha-1 match in the console. hope this helps, good luck!

Hey Alex, I’ve run into this issue before. It’s a tricky one! From my experience, the NEED_REMOTE_CONSENT error often pops up when there’s a mismatch between your app’s configuration and what’s set up in the Google Cloud Console.

First, double-check your OAuth consent screen in the Cloud Console. Make sure all required fields are filled out, especially the scopes. Sometimes, it’s easy to miss adding the right Drive scope.

Also, verify that your app’s package name and SHA-1 fingerprint in the console match exactly with your actual app. Even a small typo here can cause headaches.

One thing that helped me was clearing the app’s data on my test device and uninstalling/reinstalling. Sometimes, old auth tokens can stick around and cause weird issues.

If none of that works, try implementing a more robust error handling in your code. Log the full error message and maybe add a retry mechanism. It could reveal more details about what’s going wrong.

Hope this helps! Let us know if you figure it out.

I’ve encountered this issue before. Make sure your OAuth consent screen in the Google Cloud Console is properly configured. All required fields should be filled out, including the application name, user support email, and developer contact information. Also, ensure you’ve added the necessary Google Drive API scopes (like https://www.googleapis.com/auth/drive.file) under the Scopes section.

Another crucial step is to verify that your app’s package name and SHA-1 certificate fingerprint in your Android project match exactly with what’s registered in the Cloud Console. Even a small mismatch can cause authorization failures.

If you’ve done all this and still face issues, try updating your dependencies to the latest versions. Outdated libraries can sometimes cause unexpected behavior. Lastly, implement proper error handling to catch and log any specific error messages, which could provide more insight into the problem.