> For the complete documentation index, see [llms.txt](/docs/llms.txt)

# Twitter Reconcile Lambda | FusionAuth Docs

An overview of the Twitter Reconcile lambda.

# Twitter Reconcile Lambda

[Edit on GitHub](https://github.com/FusionAuth/fusionauth-site/blob/main/astro/src/content/docs/extend/code/lambdas/reconcile/twitter-reconcile.mdx)

[View Markdown](/docs/extend/code/lambdas/reconcile/twitter-reconcile.md)

When a Twitter identity provider is used to complete a federated login request, FusionAuth will use the [configured linking strategy](/docs/lifecycle/authenticate-users/identity-providers/#linking-strategies) to reconcile the user. FusionAuth will attempt to match the user information returned from the Twitter identity provider to an existing user account or create a new one.

You may optionally utilize a lambda to customize the user and user registration during the authentication event.

When you create a new lambda using the FusionAuth administrative user interface, you will be provided an empty function to implement.

Starting in version 1.65.0, you can use [attribute mappings](/docs/lifecycle/authenticate-users/identity-providers/#attribute-mappings) to map IdP claims directly to FusionAuth user and registration fields without writing a lambda. Reconcile lambdas and attribute mappings are mutually exclusive. Attempting to configure both on a given IdP results in a validation error.

## Lambda Structure[#](#lambda-structure)

If you are using the API to create the lambda you will need to ensure your function has the following signature:

```javascript
function reconcile(user, registration, twitterUser, context) {
  // Lambda code goes here
}
```

This lambda must contain a function named `reconcile` that accepts the following parameters:

*   `user` - the FusionAuth User object. You can modify this object. However, the **email** and **username** attributes may not be modified after the user has been linked.
*   `registration` - the FusionAuth UserRegistration object. You can modify this object.

*   `twitterUser` - the JSON user object returned by the Twitter Verify Credentials API. This object is read-only.
*   `context` - Available since 1.64.0 - an object containing the context of the request, including access to [secrets](/docs/extend/code/lambdas#secrets). This object is read-only.

The two FusionAuth objects are well documented in the [User API](/docs/apis/users) and [Registration API](/docs/apis/registrations) documentation. The `twitterUser` may contain various user claims to utilize during the reconcile process.

## Assigning The Lambda[#](#assigning-the-lambda)

Once a lambda is created, you may assign it to the Twitter identity provider in the IdP configuration.

Navigate to Settings -> Identity Providers and select your existing Twitter configuration or click Add provider and select Twitter if it has not yet been configured.

## Example Lambda[#](#example-lambda)

There is not a default Twitter reconcile lambda provided by FusionAuth. The following is an example lambda you can use as a starting point.

```javascript
// This is the default Twitter reconcile, modify this to your liking.
function reconcile(user, registration, twitterUser) {
  // Un-comment this line to see the twitterUser object printed to the event log
  // console.info(JSON.stringify(twitterUser, null, 2));

  // Set name if available in the response
  if (twitterUser.name) {
    user.fullName = twitterUser.name;
  }

  // https://developer.twitter.com/en/docs/accounts-and-users/user-profile-images-and-banners.html
  if (twitterUser.profile_image_url_https) {
    // Remove the _normal suffix to get the original size.
    user.imageUrl = twitterUser.profile_image_url_https.replace('_normal.png', '.png');
  }

  // Set twitter screen_name in registration.
  // - This is just for display purposes, this value cannot be used to uniquely identify
  //   the user in FusionAuth.
  registration.username = twitterUser.screen_name;
}
```