yii2-authclient icon indicating copy to clipboard operation
yii2-authclient copied to clipboard

normalizeUserAttributeMap Array - correct way to use

Open ztdan4ik opened this issue 7 years ago • 2 comments

Hello!

I have a question/suggestion/problem - depends on your answer.

BaseClient.php has normalizeUserAttributeMap attribute with description where saying that we can pass an array for normalize attribute. Can you give more detailed information for what it can be used?

In my understanding, for example:

'normalizeUserAttributeMap' => [
    'email' => ['email', 'name'],
]

If email found - using it, if not - trying to use name attribute.

In real - if one of attribute from array not found it's $isFound = false; here https://github.com/yiisoft/yii2-authclient/blob/master/src/BaseClient.php#L359 and in result I don't have any data in attribute.

Please, if my understanding is not right - explain what for array can be used. And second - can we make opportunities for normalize attribute in that way how I understanding now?

Thanks for your time in advance.

P.S. I know that I can use function instead of array but I think if else in each client config is not pretty nice.

ztdan4ik avatar Nov 28 '18 12:11 ztdan4ik

If email found - using it, if not - trying to use name attribute.

this is not how it works, it will try to find $attributes['email']['name'], similar to ArrayHelper::get() https://www.yiiframework.com/doc/api/2.0/yii-helpers-basearrayhelper#getValue()-detail

Not sure why this code does not use arrayhelper, could be refactored.

cebe avatar Nov 29 '18 12:11 cebe

it will try to find $attributes['email']['name']

Oh, alright. I got it. Think this information will not be superfluous in the doc.

What about my proposing to get attribute by priority? I think it will helpful. For example: Facebook returning email if user specified it, but user can be registered in facebook with phone number and in this way api will not return email.

I proposing make such of constructors:

it will try to find $attributes['email']['name']

['email' => ['name']]

to get attribute by priority

['email','name']

Thanks.

ztdan4ik avatar Nov 29 '18 13:11 ztdan4ik