website/docs/users-sources/sources/property-mappings/index.md
Source property mappings allow you to modify or gather extra information from sources.
This page is an overview of how property mappings work. For information about specific protocol, please refer to each protocol page:
If the default source mappings are not enough, or if you need to get additional data from the source, you can create your own custom source property mappings.
Here are the steps:
ldap-displayName-mapping:name.Each source provides the Python expression with additional data. You can import parts of that data into authentik users and groups. Assuming the source provides us with a data Python dictionary, you can write the following:
return {
"name": data.get("displayName"),
}
You can see that the expression returns a Python dictionary. The dictionary keys must match User properties or Group properties. Note that for users, groups and group_attributes cannot be set.
See each source documentation for a reference of the available data. See the authentik expressions documentation for available data and functions.
Note that the list_flatten method is applied for all top-level properties, but not for attributes:
return {
"username": data.get("username"), # list_flatten is automatically applied to top-level attributes
"attributes": {
"phone": list_flatten(data.get("phoneNumber")), # but not for attributes!
},
}
A user or group object is constructed as follows:
None, that attribute is then discarded.username field is not set for user objects, or the name field is not set for group objects, the process is aborted.attributes property is merged with existing data if the object already exists.LDAP and SCIM sources have built-in mechanisms to get groups. This section does not apply to them.
You can write a custom property mapping to set the user's groups:
return {
"groups": data.get("groups", []),
}
The groups attribute is a special attribute that must contain group identifiers. By default, those identifiers are also used as the group name by default, those identifiers are also used as the group name. Each of those identifiers is then given to group property mappings as the group_id variable, if extra processing needs to happen.