You're viewing the legacy docs. They are deprecated as of May 18, 2016.
These docs are for version 2.5.2 and below of the Java SDK. Go to our current docs, or see our Android migration guide.

Java Android Guide

Twitter Authentication

Configuring Your Application

To get started with Twitter authentication, you need to first create a new Twitter application. Click the Create New App button at the top right of that page and fill in a name, description, and website for your application.

After configuring your Twitter application, head on over to the Login & Auth section in your App Dashboard. Enable Twitter authentication and then copy your Twitter application credentials (API key and API secret) into the appropriate inputs. You can find your Twitter application's key and secret at the top of the API Keys tab of the application's Twitter dashboard.

Authenticating Twitter users to your Firebase App

After configuring your app to process the OAuth flow from Twitter, you can use the returned token to authenticate a secure Firebase session. After the user has been authenticated with Twitter, signing them into your Firebase app can be triggered by:

Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>");

// setup the OAuth options for Twitter
Map<String, String> options = new HashMap<String, String>();
options.put("oauth_token", "<OAuth token>");
options.put("oauth_token_secret", "<OAuth token secret>");
options.put("user_id", "<Twitter user id>");

ref.authWithOAuthToken("twitter", options, new Firebase.AuthResultHandler() {
    public void onAuthenticated(AuthData authData) {
        // the Twitter user is now authenticated with your Firebase app

    public void onAuthenticationError(FirebaseError firebaseError) {
        // there was an error

The authData object returned to your callback contains the following getter methods:

authData Object
Field Description Type
getUid() A unique user ID, intended as the user's unique key across all providers. String
getProvider() The authentication method used, in this case: twitter. String
getToken() The Firebase authentication token for this session. String
getAuth() The contents of the authentication token, which will be available as the auth variable within your Security and Firebase Rules. Map<String,Object>
getExpires() A timestamp, in seconds since the UNIX epoch, indicating when the authentication token expires. Long
getProviderData() A Map containing provider-specific data. Map<String,Object>
getProviderData().get("id") The Twitter user's ID. String
getProviderData().get("displayName") The Twitter user's full name. String
getProviderData().get("username") The Twitter user's screen name, handle, or alias. Twitter screen names are unique, but subject to change. String
getProviderData().get("profileImageURL") The URL of the Twitter user's profile picture. String
getProviderData().get("cachedUserProfile") The Twitter user's raw profile, as specified by Twitter's user documentation. Note that the data included in this payload is generated by Twitter and may be changed by them at any time. Object

Security & Rules

Now that the client is logged in, your Security and Firebase Rules have access to their verified account data. The auth variable contains the following values:

auth Variable
Field Description Type
uid A unique user ID, intended as the user's unique key across all providers. String
provider The authentication method used, in this case: twitter. String

Here is an example of how to use the auth variable in your Security and Firebase Rules:

  "rules": {
    "users": {
      "$uid": {
        // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
        ".write": "auth !== null && auth.uid === $uid",

        // grants read access to any user who is logged in twitter
        ".read": "auth !== null && auth.provider === 'twitter'"
See the User Based Security articles for more details.
  1. 1


    Installation & Setup

  2. 2


    Understanding Data

  3. 3


    Saving Data

  4. 4


    Retrieving Data

  5. 5


    Structuring Data

  6. 6


    Understanding Security

  7. 7


    User Authentication

  8. 8


    Offline Capabilities