Add a Twitter/X IdP
On this page
Add a Login with Twitter/X button to the FusionAuth login page. This guide shows how to collect the credentials from Twitter and configure the Twitter Identity Provider, a Social loginLogin through an account the user already has with a consumer service, such as Google or Apple. option.
After you configure the Identity Provider, you can enable the Twitter login button for one or more FusionAuth Applications. The following login page shows the Twitter Identity Provider:

The following diagram shows a login through Twitter on the FusionAuth hosted login pages:
A user logs in through an Identity Provider on the FusionAuth hosted login pages.
The user sees only the FusionAuth login page, the login page of Twitter, and your application. Your application completes a standard OAuth authorization code grant with FusionAuth, and FusionAuth handles the exchange with Twitter.
Create a Twitter Account#
Log in to Twitter, or create a Twitter account. Then open the Twitter Developer Portal.
When you don't have a developer account, apply for access to the Twitter API in the Twitter Developer Portal. After Twitter grants access to a developer account, continue to the next step.
Create a Twitter App#
Twitter creates an application as part of the developer account setup. When you don't have a Twitter app, create one in this step. When you already have a Twitter app for FusionAuth, review this section anyway to check that the app supports Twitter login.
Your level of access in the Twitter project limits app creation. To create more than one app in the project, or to change settings that Essential access restricts, apply for elevated access. For more information, see Twitter access levels and permissions.
The Twitter Developer Portal dashboard lists your Twitter apps.

The following sections cover the app settings that let Twitter connect with FusionAuth.
Record the Keys and Token#
Twitter shows the API key and API secret key when you create the app. Record the values for the FusionAuth Identity Provider.
Authentication Settings#
Under User authentication settings , change the app settings as shown:

Add a Callback URI#
The image labels this setting as step 1.
In the App Info section, register a Callback URI / Redirect URL and specify your website URL. Set the redirect URLThe URL where the authorization server sends the browser after login, with an authorization code or an error. to an absolute URL. For a FusionAuth hostname of login.piedpiper.com, the redirect URL is https://login.piedpiper.com/oauth2/callback.
Enable Request Email#
The image labels this setting as step 2.
To link users by email, check Request email from users. Some Twitter users have no email address. When your users may not have one, configure the Identity Provider to link on username, or use a reconcile lambda to map custom claims from Twitter. For workarounds, see Linking Strategies.
Keys and Tokens#
The Keys and tokens section shows the Consumer API Keys and Secret. The values match the values that Twitter showed when you created the app. The FusionAuth Identity Provider uses the values.

Create a Twitter Identity Provider#
Create the Twitter Identity Provider in FusionAuth. The add menu on the Identity Providers page lists Twitter:

Fill in Consumer key and Consumer secret with the values from the Keys and tokens tab of the Twitter app. Button text is required and defaults to Login with Twitter.
To enable Twitter for an Application or CIMD domain:
-
In the Admin UI, navigate to Settings -> Identity Providers .
-
Click the arrow next to the add button, and select Twitter .
-
Select the Tenant for the Identity Provider, or select
Global identity provider. You can't change the scope later. For more information, see Identity Provider Scope. -
Fill out the form. Your identity provider supplies most of the values. For a description of each field, see Form Fields.
-
On the Applications tab, turn on Enabled for each Application or CIMD domain that uses the Identity Provider.
-
To register new users for the Application with the Application's default roles, turn on Create registration. When Create registration is off, a user needs a registration for the Application before the user can log in through the Identity Provider.
-
Click .
The login page of each enabled Application then shows a login button for the Identity Provider. An Identity Provider with managed domains asks for the user's email address instead of showing a button.

To use Twitter with CIMD clients, an advanced theme needs the 1.70.0 changes to the alternativeLoginsScript helper macro and the OAuth authorize and OAuth register templates. For more information, see the Advanced Theme Upgrade Notes. Available since 1.70.0
Form Fields#
IdAn optional UUID. When you leave out the Id, FusionAuth generates a unique Id.
TenantThe Tenant that this Identity Provider belongs to. The field appears only when you select a specific Tenant on the previous page. When you select Global identity provider on the previous page, the field doesn't appear.
NameA unique name for the Identity Provider. FusionAuth uses the name for display only, and you can change the name later.
Consumer keyThe API key from the Keys and tokens settings of the Twitter app.
Consumer secretThe API secret key from the Keys and tokens settings of the Twitter app.
Callback URLThe callback URL to add to your Twitter configuration.
Button textThe text of the button on the login form. The default value is Login with Twitter.
Linking strategyHow FusionAuth links a Twitter user to a FusionAuth user. For more information, see Linking Strategies.
Available since 1.65.0 You can only change this value when the identity provider is disabled. To change the linking strategy for an identity provider that is already enabled, disable the provider, change the value, and then re-enable the provider.
Reconcile lambdaA lambda that maps custom claims from Twitter to the user.
To create a lambda, navigate to Customizations -> Lambdas .
Enable debug loggingCreates Event Log entries that help you debug integration errors. To read the entries, navigate to System -> Event Log .
Tenants#
The Tenants tab limits the number of links that each user in a Tenant can have to this Identity Provider. Links to other Identity Providers don't count toward the limit. On a global Identity Provider, the tab starts empty. To set a limit for a Tenant, click Add tenant configuration . On a tenant-scoped Identity Provider, the tab lists only the Identity Provider's Tenant.
Limit links per userWhen turned on, FusionAuth enforces Maximum link count for users in the Tenant.
Maximum link countThe maximum number of links that a user can have to this Identity Provider. When a user reaches the limit, FusionAuth rejects a new link. The Link API returns a 400, and the hosted login pages show an error.
For more information, see Identity Providers and Tenants.
Proxy Details#
FusionAuth detects the public URL of the instance at runtime, and sends the URL to Twitter as the callback URL. When FusionAuth runs behind a proxy and the host or protocol behind the proxy differs from the public URL, the proxy must add the X-Forwarded-Host and X-Forwarded-Proto headers.
For example, a proxy that performs SSL acceleration serves a public https URL, while the URL behind the proxy uses http. Most proxies add the X-Forwarded-Proto header in this case, and FusionAuth then sends the correct URL to Twitter.
Building Your Own Integration#
To build your own login experience instead of using the FusionAuth hosted login pages, start the Identity Provider flow in your application, and complete the login with the Login API. The following diagram shows the flow:
Your application starts the Identity Provider login and completes the login with the FusionAuth API.
For the request that completes the login, see the Twitter Identity Provider API.
When your application needs a refresh token after the login, turn on Enable JWT Refresh for the Application. In the Admin UI, navigate to Applications -> Your Application -> Security -> Login API settings .
Related
Learn about the APIs for creating, retrieving, updating and disabling a Twitter/X identity provider.
Learn how to map the data from a Twitter login to a FusionAuth user and registration with a reconcile lambda.
Learn about the APIs for creating, retrieving, updating and disabling an Apple identity provider.
Learn about the APIs for creating, retrieving, updating and disabling an Epic Games identity provider.