Signing in users with Twitter
This document shows you how to use Identity Platform to sign in users with Twitter.
Before you begin
This tutorial assumes you've already enabled Identity Platform, and have a basic web app written using HTML and JavaScript. See the Quickstart to learn how.
Configuring Twitter as a provider
To configure Twitter as an identity provider:
Go to the Identity Providers page in the Google Cloud console.
Click Add A Provider.
Select Twitter from the list.
Enter your Twitter App ID and App Secret. If you don't already have an ID and secret, you can obtain one from the Twitter Apps page.
Configure the URI listed under Configure Twitter as a valid OAuth redirect URI for your Twitter app. If you configured a custom domain in Identity Platform, update the redirect URI in your Twitter app configuration to use the custom domain instead of the default domain. For example, change
https://myproject.firebaseapp.com/__/auth/handler
tohttps://auth.myownpersonaldomain.com/__/auth/handler
.Register your app's domains by clicking Add Domain under Authorized Domains. For development purposes,
localhost
is already enabled by default.Under Configure your application, click Setup Details. Copy the snippet into your app's code to initialize the Identity Platform Client SDK.
Click Save.
Signing in users with the Client SDK
Create an instance of the Twitter provider object:
Web version 9
import { TwitterAuthProvider } from "firebase/auth"; const provider = new TwitterAuthProvider();
Web version 8
var provider = new firebase.auth.TwitterAuthProvider();
Optional: Localize the authentication flow. You can specify a language, or use the device's default language:
Web version 9
import { getAuth } from "firebase/auth"; const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // auth.useDeviceLanguage();