laravel-saml2
laravel-saml2 copied to clipboard
User attribute mapping
I've been working to integrate this package and was thinking it would be nice if it supported like a config of mapping of urn:oid values to model attributes automatically which then can be used on the model such as this:
$attributes = $samlUser->mappedAttributes();
$laravelUser->fill($attributes);
The config could look something like this:
return [
'first_name' => [
'urn:oid:2.5.4.42',
'firstName',
],
];
And the Saml2User method:
protected function mappedAttributes(): array
{
$attributes = $this->getAttributes();
$result = collect(config('saml2.attribute_mapping')
->mapWithKeys(function ($map, $attribute) use ($attributes) {
foreach ($map as $key) {
$values = Arr::get($attributes, $key);
if (empty($values) || !is_array($values)) continue;
$value = Arr::first($values);
if (empty($value)) continue;
return [$attribute => $value];
}
return [$attribute => null];
});
}
return $result->all();
}
Good idea!
I think most applications will require extra user attributes & claims (See AAD example https://learn.microsoft.com/en-us/answers/questions/248748/cant39-find-the-34user-attributes-amp-claims34-sec.html#answer-248989), but this package doesnt provide a solution for this.
The alternative is to store this information in another table (The package currently doesnt support using the saml2_tenants.metadata column because the : symbol isnt allowed with their ConsoleHelper::stringToArray encoder/ decoder).
Would you be open to a pull request to add another column to the saml2_tenants table for this, which stores a json column. @dmyers I could get it started, or if you have a solution already we can start from there.
Hello, did you succeed in getting custom attributes? I added custom attributes in my AD "Attributes and Claims", but I can't see them in the ->getAttributes().