You can let your users authenticate with Firebase using their Twitter accounts by integrating Twitter authentication into your app. You can integrate Twitter authentication either by using the Firebase SDK to carry out the sign-in flow, or by carrying out the Twitter OAuth flow manually and passing the resulting access token and secret to Firebase.
Before you begin
- Add Firebase to your JavaScript project .
- In the Firebase console , open the Auth section.
- On the Sign in method tab, enable the Twitter provider.
- Add the API key
and API secret
from that provider's developer console to the
provider configuration:
- Register your app as a developer application on Twitter and get your app's OAuth API key and API secret .
- Make sure your Firebase OAuth redirect URI
(e.g.
my-app-12345.firebaseapp.com/__/auth/handler) is set as your Authorization callback URL in your app's settings page on your Twitter app's config .
- Click Save .
Handle the sign-in flow with the Firebase SDK
If you are building a web app, the easiest way to authenticate your users with Firebase using their Twitter accounts is to handle the sign-in flow with the Firebase JavaScript SDK. (If you want to authenticate a user in Node.js or other non-browser environment, you must handle the sign-in flow manually.)
To handle the sign-in flow with the Firebase JavaScript SDK, follow these steps:
- Create an instance of the Twitter provider object:
Web
import { TwitterAuthProvider } from "firebase/auth" ; const provider = new TwitterAuthProvider ();
Web
var provider = new firebase . auth . TwitterAuthProvider ();
- Optional: To localize the provider's OAuth flow to the user's preferred
language without explicitly passing the relevant custom OAuth parameters, update the language
code on the Auth instance before starting the OAuth flow. For example:
Web
import { getAuth } from "firebase/auth" ; const auth = getAuth (); auth . languageCode = 'it' ; // To apply the default browser preference instead of explicitly setting it. // auth.useDeviceLanguage();

