Exchange Google "idToken" or "authCode" for Auth0 credentials

Hi,

I’m struggling to find out how to obtain Auth0 credentials, after having successfully authenticated my user with Google in my Android App following Google Sign In instructions (Integrating Google Sign-In into Your Android App).

I have basically tried 2 approaches:

  1. Obtained an idToken from Google like this:

    val googleSignInIdTokenOptions = Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestScopes("open_id , email, etc… ")
    .requestIdToken(BuildConfig.OATH2_WEB_CLIENT_ID)
    .requestEmail()
    .build()
    val googleSignInClient = GoogleSignIn.getClient(activity, googleSignInIdTokenOptions)
    activity.startActivityForResult(googleSignInClient.signInIntent, 2468)

Then in onActivityResult() I obtain the google account with the idToken.

  1. Or, obtained an serverAuthCode from Google like this:
    val googleSignInOptions = Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestScopes(Scope(Scopes.EMAIL), Scope(Scopes.PROFILE))
    .requestServerAuthCode(BuildConfig.OATH2_CLIENT_ID)
    .requestEmail()
    .build()
    val googleSignInClient = GoogleSignIn.getClient(activity, googleSignInOptions)
    activity.startActivityForResult(googleSignInClient.signInIntent, 2468)

Then in onActivityResult() I obtain the google account with the serverAuthCode.

Then this is the point where I’m lost. How do I use either the idToken or the serverAuthCode to exchange it for Auth0 credentials ?

Thanks a lot !

Hi @thsaraiva,

I’m not too familiar with setting up Google Sign-In via Google itself and not through an Auth0 SDK.

Have you checked out the docs for the Android SDK? Auth0.Android

When you use Auth0, you can outsource the authentication process and display social connections such as Google, or other types of login options in one place.

The Auth0 SDK will make the Access Token and ID Token available to your app. That way no matter how a user logs in/signs up for your app, your app only needs to integrate with Auth0 for authentication.

1 Like