Twitter Reconcile Lambda

Twitter Reconcile lambda

This lambda reconciles a user in conjunction with a Twitter IdP.

When you create a new lambda using the FusionAuth UI we will provide you an empty function for you to implement.

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

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

This lambda must contain a function named reconcile that takes three parameters. The parameters that the lambda is passed are:

  • user - the FusionAuth User object. You can modify this, except the email or username attribute may not be modified after the user has been linked.
  • registration - the FusionAuth UserRegistration object. You can modify this.
  • twitterUser - the JSON user object returned by the Twitter Verify Credentials API. This is read-only.

The two FusionAuth objects are well documented here in the User API and Registration API documentation. The twitterUser may contain various user claims to utilize during the reconcile process.

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

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

// 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;
}