androidgoogle-drive-apigoogle-oauthgoogle-drive-android-apigoogle-one-tap

Using Google Drive API with One-Tap Sign-In on Android


I implemented Google's One-Tap Sign-Up/In in my Android application through which I obtain credential of type SignInCredential by using oneTapClient.getSignInCredentialFromIntent(result.data). I can further obtain the idToken from this SignInCredential object.

Further, I want to access user's Google Drive using the Drive API (I have enabled the API and selected the required scopes from the API Console) which I assume requires me to implement OAuth2 flow somewhat like this:

val cred = GoogleAccountCredential.usingOAuth2(this,Collections.singleton(Scopes.DRIVE_FILE))
cred.selectedAccount
val googleDriveService = com.google.api.services.drive.Drive.Builder(AndroidHttp.newCompatibleTransport(), GsonFactory(), cred ) 
    .setApplicationName(getString(R.string.app_name))
    .build()

My question is what do I do with the idToken obtained from the One-Tap flow? Am I supposed to pass it to the OAuth2 call in some way? I referred this oauth2 documentation and these docs of Google API Clients for Java but both of them don't answer the aforementioned question. And how do I further "recieve" the oauth token, if any?

Thanking you in advance.


Solution

  • One-Tab is a service oriented towards account creation and login. As described by the overview docs:

    With just one tap, they (users) get a secure, token-based, passwordless account with your service, protected by their Google Accoun

    On the other hand, if you want to interact with the APIs as an user, then you would need to use an OAuth 2.0. approach in order to handle the authentication flow. This service is independent of One-Tap, so you need different tokens per each. If you need to work with the Drive API, you can follow this quickstart to develop a working OAuth 2.0 token flow.