Sony PlayStation Network Reconcile Lambda

On this page

When a Sony PlayStation Network 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 Sony PlayStation Network 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 Sony PlayStation Network token information API. This object is read-only.
  • context: Available since 1.64.0 an 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 fields such as online_id, user_uuid, country_code, language_code, and is_sub_account. FusionAuth uses online_id as the username. FusionAuth reads the email address from a separate account request, so userInfo doesn't include the email address.

Example Lambda#

The following lambda stores the online Id, account UUID, and country in user.data.psn. When the user has no preferred language, the lambda copies the PlayStation language to the user. PlayStation sub accounts belong to children, so the lambda gives a sub account the restricted role. Add the restricted role to your application before you use the lambda.

A lambda that copies the PlayStation Network account to the user.
// stores the PSN account and gives sub accounts a restricted role
function reconcile(user, registration, userInfo, context) {
  user.data = user.data || {};
  user.data.psn = {
    onlineId: userInfo.online_id,
    accountUuid: userInfo.user_uuid,
    country: userInfo.country_code,
    subAccount: userInfo.is_sub_account === true
  };
  if (userInfo.language_code && !(user.preferredLanguages && user.preferredLanguages.length)) {
    user.preferredLanguages = [userInfo.language_code];
  }
  if (!registration) {
    return;
  }
  // PlayStation sub accounts belong to children and stay sub accounts until a parent upgrades them
  var roles = (registration.roles || []).filter(function (role) {
    return role !== 'restricted';
  });
  if (userInfo.is_sub_account === true) {
    roles.push('restricted');
  }
  registration.roles = roles;
}

Assigning The Lambda#

After you create the lambda, assign the lambda to the Sony PlayStation Network identity provider.

Navigate to Settings -> Identity Providers . Select your existing Sony PlayStation Network configuration. If you haven't configured Sony PlayStation Network yet, click Add provider and select Sony PlayStation Network.