flipboxfactory / saml-sp

SAML Service Provider (SP) Plugin for Craft CMS
https://saml-sp.flipboxfactory.com/
Other
19 stars 5 forks source link

Custom User Fields Mapping Issue During Login #5

Closed AANP-ITSupport closed 6 years ago

AANP-ITSupport commented 6 years ago

I created a custom User Field in Craft CMS, called memberType.

After a little debugging of /services/Login.php, and some major confusion, I now understand that this PHP function – property_exists, is returning false for these custom User Fields since they are dynamically added to the model. Even though I can get and set these fields from $user->memberType, for example. Therefore, the simple mapping logic doesn’t apply.

Because property_exists is returning false, it falls into the “look for a callable” section .

So, I thought I would attempt to create a callable, but when I add this to the responseAttributeMap it fails with “Constant expression contains invalid operations”. It sounds to me like this property is not allowing functions to be added to the array, but the examples given seem to be doing just that?

My knowledge of PHP is about as basic as you can get. So I’m sure I’m missing something simple here.

custom_user_fields_loginphp

dsmrt commented 6 years ago

Yep ... looks like that callable section is getting skipped over. I'll get a patch going for this.

dsmrt commented 6 years ago

Fixed in 1.0.0-beta.9. I still need to add some documentation on this but the callback will pass the user then the attribute. For example, your configs/saml-sp.php can look like the following:

<?php

return [
    'responseAttributeMap' => [
        \LightSaml\ClaimTypes::EMAIL_ADDRESS => 'email',
        \LightSaml\ClaimTypes::GIVEN_NAME    => 'firstName',
        \LightSaml\ClaimTypes::SURNAME       => function(\craft\elements\User $user,
                                                         \LightSaml\Model\Assertion\Attribute $attribute) {
            $user->lastName = $attribute->getFirstAttributeValue();
        }
    ],
];