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:

A FusionAuth login page with a Login with Twitter button.
A FusionAuth login page with a Login with Twitter button.

The following diagram shows a login through Twitter on the FusionAuth hosted login pages:

Identity ProviderFusionAuthYour ApplicationUser/BrowserIdentity ProviderFusionAuthYour ApplicationUser/BrowserClick LoginRedirect to the FusionAuth login pageClick the Identity Provider buttonRedirect to the Identity ProviderLog inRedirect to FusionAuth with the login resultFollow the redirect to the FusionAuth callback URLRequest the user's tokens or profileReturn the tokens or profileReconcile, link, and create the user and registration as neededRedirect to your application with an authorization codeFollow the redirectExchange the authorization code for tokensReturn FusionAuth tokens
Identity ProviderFusionAuthYour ApplicationUser/BrowserIdentity ProviderFusionAuthYour ApplicationUser/BrowserClick LoginRedirect to the FusionAuth login pageClick the Identity Provider buttonRedirect to the Identity ProviderLog inRedirect to FusionAuth with the login resultFollow the redirect to the FusionAuth callback URLRequest the user's tokens or profileReturn the tokens or profileReconcile, link, and create the user and registration as neededRedirect to your application with an authorization codeFollow the redirectExchange the authorization code for tokensReturn FusionAuth tokens

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 Twitter Developer Portal page to create an app.
The Twitter Developer Portal page to create an app.

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:

The Twitter user authentication settings, with labels for the callback URI and the email request.
The Twitter user authentication settings, with labels for the callback URI and the email request.

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.

The Twitter Keys and tokens section.
The Twitter Keys and tokens section.

Create a Twitter Identity Provider#

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

The add menu on the Identity Providers page, with Twitter highlighted.
The add menu on the Identity Providers page, with Twitter highlighted.

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:

  1. In the Admin UI, navigate to Settings -> Identity Providers .

  2. Click the arrow next to the add button, and select Twitter .

  3. 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.

  4. Fill out the form. Your identity provider supplies most of the values. For a description of each field, see Form Fields.

  5. On the Applications tab, turn on Enabled for each Application or CIMD domain that uses the Identity Provider.

  6. 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.

  7. 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.

The form to configure a Twitter Identity Provider in the Admin UI.
The form to configure a Twitter Identity Provider in the Admin UI.
Note

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#

Id
  • Optional
  • Available since 1.61.0

An optional UUID. When you leave out the Id, FusionAuth generates a unique Id.

Tenant
  • Optional
  • Available since 1.62.0

The 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.

Name
  • Required
  • Available since 1.61.0

A unique name for the Identity Provider. FusionAuth uses the name for display only, and you can change the name later.

Consumer key
  • Required

The API key from the Keys and tokens settings of the Twitter app.

Consumer secret
  • Required

The API secret key from the Keys and tokens settings of the Twitter app.

Callback URL
  • Available since 1.6.0

The callback URL to add to your Twitter configuration.

Button text
  • Required

The text of the button on the login form. The default value is Login with Twitter.

Linking strategy
  • Optional

How 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 lambda
  • Optional
  • Available since 1.17.0

A lambda that maps custom claims from Twitter to the user.

To create a lambda, navigate to Customizations -> Lambdas .

Enable debug logging
  • Optional
  • Defaults to false

Creates 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 user
  • Optional
  • Defaults to false
  • Available since 1.32.0

When turned on, FusionAuth enforces Maximum link count for users in the Tenant.

Maximum link count
  • Optional
  • Available since 1.32.0

The 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:

ProviderFusionAuthAppUser/BrowserProviderFusionAuthAppUser/BrowserUser Is Logged In And App Can ProceedDelivering Data And FunctionalityView Initial PageClick LoginDisplays Login PageIncluding Link To 'Login With Provider'Clicks On 'Login With Provider'Redirect To Provider Authorization URLEnters CredentialsValidate CredentialsRedirect to App With Authorization CodeRequests Page, Has Authorization CodeCalls Complete LoginWith Code And Redirect URIExchanges Code AndRedirect URI For Provider TokenReturns Provider TokenStores Provider Token, Calls Lambda, Creates User And Registrations (If Needed), Generates FusionAuth TokensReturn FusionAuth TokensCreate Session OrOtherwise Log User In
ProviderFusionAuthAppUser/BrowserProviderFusionAuthAppUser/BrowserUser Is Logged In And App Can ProceedDelivering Data And FunctionalityView Initial PageClick LoginDisplays Login PageIncluding Link To 'Login With Provider'Clicks On 'Login With Provider'Redirect To Provider Authorization URLEnters CredentialsValidate CredentialsRedirect to App With Authorization CodeRequests Page, Has Authorization CodeCalls Complete LoginWith Code And Redirect URIExchanges Code AndRedirect URI For Provider TokenReturns Provider TokenStores Provider Token, Calls Lambda, Creates User And Registrations (If Needed), Generates FusionAuth TokensReturn FusionAuth TokensCreate Session OrOtherwise Log User In

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 .