Search code examples
androidtwitterfirebase-authenticationtwitter-oauthfirebaseui

Twitter sign-in with FirebaseUI on Android


Implementation of Google sign-in and facebook sign-in in my app works fine using FirebaseUI. However, I failed to add Twitter sign-in. When I click on Twitter sign-in button, I managed to get access to Twitter API and the redirect URL is correctly handled. But authentication fails in my app and I get a FirebaseUIException "Developer Error". The analyse of "com.firebase.ui.auth.util.data.ProviderUtils", lign 229, let me know that the reason is : "There is an existing user who only has unsupported sign in methods".

I found informations about how to do with Twitter authentication using Firebase-Auth, but not the slightest up to date information with FirebaseUI. So, here is what I've done:

  • I've added Twitter provider in Firebase console and copied the redirect URL for Twitter.
  • I've created the Twitter app, enabled OAuth 1.0a and OAuth 2.0 authentications, filled the Firebase redirect URL field and copied the Twitter's API key and API secret.
  • I've added the Twitter's API key and API secret in Twitter provider's fields in Firebase console.

In Android, I've tried to add what follows, but without any effect:

  • Into AndroidManifest (one of each or both):

    android:usesCleartextTraffic="true"

    android:supportsRtl="false" tools:replace="android:supportsRtl"

  • Into gradle repositories (one of each):

    mavenLocal()

    maven { url 'https://maven.fabric.io/public' }

    maven { url 'https://maven.google.com' }

  • Into gradle dependencies (one of each):

    implementation ("com.twitter.sdk.android:twitter-core:latest.release") { transitive = true }

    implementation ("com.twitter.sdk.android:twitter-core:latest.release") { transitive(true) }

    implementation ("com.twitter.sdk.android:twitter-core:latest.release@aar") { transitive = true }

    implementation ("com.twitter.sdk.android:twitter-core:latest.release@aar") { transitive(true) }

    implementation 'com.twitter.sdk.android:twitter-core:latest.release'

  • Into strings.xml :

    <string name="twitter_consumer_key" translatable="false">my_twitter_api_key</string>

    <string name="twitter_consumer_secret" translatable="false">my_twitter_api_secret</string>

Now, I wonder whether it's still possible to use Twitter API for auth into FirebaseUI or not.

If yes, how to achieve it ?

I don't know if the issue takes place in my code or in Firebase or Tweeter console...


Solution

  • Well, I finally managed to authenticate myself with Twitter, after spending hours trying to figure out why I was throwing a FirebaseUI Exception.

    I havn't received any answer to my post, but I communicate my feedback to possibly prevent others from suffering the same setbacks and the same loss of time:

    In the end, to implement Twitter auth with FirebaseUI, no entry is necessary in the manifest, gradle or strings. Everything happens in Firebase and Twitter dev. It turns out that the app was correctly configured at the level of these two consoles. The app on Twitter in "elevated" access. Permission "read" + email is enough for authentication.

    In fact, I only succeeded in authenticating after having modified, several times consecutively, the permission to "read+write", "read+write+more" and "read" and having restarted the authentication each time after each change.

    Weird, then ! The parameters displayed were therefore not correctly taken into account (!!!). This manipulation must have put something square, but I don't know what or why this problem occurred...