Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalizeUserAttributeMap Array - correct way to use #254

Open
ztdan4ik opened this issue Nov 28, 2018 · 2 comments
Open

normalizeUserAttributeMap Array - correct way to use #254

ztdan4ik opened this issue Nov 28, 2018 · 2 comments
Labels
type:docs Documentation

Comments

@ztdan4ik
Copy link

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.

@cebe
Copy link
Member

cebe commented Nov 29, 2018

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.

@ztdan4ik
Copy link
Author

ztdan4ik commented Nov 29, 2018

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.

@cebe cebe added the type:docs Documentation label Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs Documentation
Projects
None yet
Development

No branches or pull requests

2 participants