SCIM Group Request Converter Lambda
On this page
A SCIM Group Request Converter lambda converts an incoming SCIM Group request into a FusionAuth group. FusionAuth runs the lambda before FusionAuth creates or updates the group.
When you create a lambda in the Admin UI, FusionAuth provides an empty function for you to implement.
Lambda Structure#
If you create the lambda with the API, the function must have the following signature:
function convert(group, members, options, scimGroup, context) {
// Lambda code goes here
}
The lambda must contain a function named convert that accepts the following parameters:
group: the FusionAuth group. You can modify this object. FusionAuth passes a new, empty group.members: an empty array for the members of the group. You can modify this array. Add one object for each member, with the following properties:members[x].userId: the Id of the FusionAuth user.members[x].data: custom data for the membership. The default lambda stores the SCIM member URI inmembers[x].data.$ref, such ashttps://login.piedpiper.com/api/scim/resource/v2/Users/902c246b-6245-4190-8e05-00816be7344a.
options: the request options. You can modify this object. The object has the following property:options.roleIds: the Ids of the application roles to assign to the group.
scimGroup: the SCIM request. This object is read-only.context: Available since1.64.0the context of the request, including access to secrets. This object is read-only.
The Group API documents the FusionAuth group. The scimGroup object holds the SCIM Group request JSON. See SCIM Group.
Assign the Lambda#
After you create the lambda, assign the lambda to a tenant on the SCIM tab of the tenant configuration.
Default Lambda#
FusionAuth provides a default SCIM Group Request Converter lambda. The default lambda names the group with the SCIM displayName. The lambda adds a member for each SCIM member and stores the member $ref in the member data.
function convert(group, members, options, scimGroup) {
// Un-comment this line to see the scimGroup object printed to the event log
// console.info(JSON.stringify(scimGroup, null, 2));
// Request options
// FusionAuth allows you to assign one or more application roles to a group.
// To use this feature, assign one or more application Ids here.
// options.roleIds = [];
// Set the name of the group using the SCIM Group displayName
group.name = scimGroup.displayName;
// Build a members array with a userId and a $ref in custom data
if (scimGroup.members) {
for (var i = 0; i < scimGroup.members.length; i++) {
members.push({
userId: scimGroup.members[i].value,
data: {
$ref: scimGroup.members[i]['$ref']
}
});
}
}
}Example: Assign Roles by Group Name#
The following lambda extends the default lambda. The lambda makes these changes:
- The lambda looks up the SCIM
displayNamein a map of application role Ids and setsoptions.roleIds. Members of the group receive those roles. A group with no entry in the map gets no roles. Replace eachreplace-with-value with a role Id from your applications. - The lambda adds a
SCIM:prefix to the group name, so a provisioned group can't collide with a group created in FusionAuth. The lambda stores the original name ingroup.data.scimDisplayName. - The lambda skips SCIM members that have no
value.
// application role Ids that members of each SCIM group receive; replace with role Ids from your applications
var roleIdsByGroup = {
'Engineering': ['replace-with-engineering-role-id'],
'Sales Reps': ['replace-with-sales-role-id', 'replace-with-crm-role-id']
};
function convert(group, members, options, scimGroup, context) {
// prefix the name so a SCIM group can't collide with a group created in FusionAuth
group.name = 'SCIM: ' + scimGroup.displayName;
group.data.scimDisplayName = scimGroup.displayName;
options.roleIds = roleIdsByGroup[scimGroup.displayName] || [];
(scimGroup.members || []).forEach(function (member) {
if (!member.value) {
return;
}
members.push({
userId: member.value,
data: {
$ref: member['$ref']
}
});
});
}Pair this lambda with the display name example for the SCIM Group Response Converter, so the SCIM client gets back the group name the client sent.
Related
Learn how to convert a FusionAuth group into the SCIM group response a SCIM client expects.
Learn how to convert an incoming SCIM user request into a FusionAuth user with a lambda.
Learn how to convert a FusionAuth user into the SCIM user response a SCIM client expects.
Learn how to configure Azure AD/Microsoft Entra ID as a SCIM client.