Steam Reconcile Lambda
On this page
When a Steam identity provider is used to complete a federated login request, FusionAuth will use the configured linking strategy to reconcile the user. FusionAuth will attempt to match the user information returned from the Steam 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 Admin UI, you will be provided an empty function to implement.
Starting in version 1.65.0, you can use 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#
When you create the lambda with the API, give the function the following signature:
function reconcile(user, registration, userInfo, 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, you can't change the email or username attributes after FusionAuth links the user.registration: the FusionAuth UserRegistration object. You can modify this object.
userInfo: the response from the SteamGetPlayerSummariesAPI. This object is read-only. For a full list of fields, see the GetPlayerSummaries reference.context: Available since1.64.0an object containing the context of the request, including access to secrets. This object is read-only.
The User API and Registration API documentation describe the user and registration objects.
The userInfo object holds a response.players array with one player. FusionAuth sets the username from personaname. Steam doesn't return an email address. A player with a private profile returns fewer fields, so realname and loccountrycode can be missing.
Example Lambda#
The following lambda stores the Steam Id and profile URL in user.data.steam. The lambda sets the user's image to the full-size avatar on every login, so the image stays current. When the profile includes a real name, the lambda uses the real name as the full name of a user who has none.
// stores the Steam profile on the user and keeps the avatar current
function reconcile(user, registration, userInfo, context) {
var player = userInfo.response.players[0];
user.data = user.data || {};
user.data.steam = {
steamId: player.steamid,
profileUrl: player.profileurl
};
if (player.avatarfull) {
user.imageUrl = player.avatarfull;
}
// private profiles leave out realname and loccountrycode
if (player.realname && !user.fullName) {
user.fullName = player.realname;
}
if (player.loccountrycode) {
user.data.steam.countryCode = player.loccountrycode;
}
}Assigning The Lambda#
After you create the lambda, assign the lambda to the Steam identity provider.
Navigate to Settings -> Identity Providers . Select your existing Steam configuration. If you haven't configured Steam yet, click Add provider and select Steam.
Related
Learn how to map the data from a Nintendo login to a FusionAuth user and registration with a reconcile lambda.
Learn how to map the data from a Sony PlayStation Network login to a FusionAuth user and registration with a reconcile lambda.
Learn how to map the data from an Xbox login to a FusionAuth user and registration with a reconcile lambda.
Learn how to map the data from an Apple login to a FusionAuth user and registration with a reconcile lambda.