zorn-v / nextcloud-social-login

GNU Affero General Public License v3.0
199 stars 138 forks source link

Parsing of user givenName from Keycloack not working #274

Closed mmaridev closed 3 years ago

mmaridev commented 3 years ago

Even if the user displayName is defined in Keycloack (and passed as name in the response), the plugin always fallback to set displayName=uid. Tried to fix but with no luck.

zorn-v commented 3 years ago

Which version of social login app you tried ? As you can see, if provider return name claim in id_token https://github.com/zorn-v/nextcloud-social-login/blob/c8e940b5651ff418128cb72c2b784347dd10aaae/lib/Provider/CustomOpenIDConnect.php#L36 or in response by user info url https://github.com/zorn-v/nextcloud-social-login/blob/c8e940b5651ff418128cb72c2b784347dd10aaae/lib/Provider/CustomOpenIDConnect.php#L58 displayName should be filled.

Can you dump response from keycloak ?

mmaridev commented 3 years ago

Can you suggest a clean way to dump the response from keycloak?

zorn-v commented 3 years ago

Try like this https://github.com/zorn-v/nextcloud-social-login/issues/268#issuecomment-847263180 https://github.com/zorn-v/nextcloud-social-login/issues/268#issuecomment-847489998

mmaridev commented 3 years ago
Hybridauth\Data\Collection Object
(
    [collection:protected] => stdClass Object
        (
            [exp] => 1622476999
            [iat] => 1622476939
            [auth_time] => 1622476714
            [jti] => omitted
            [iss] => http://mycloack.co/auth/realms/master
            [aud] => nextcloud
            [sub] => omitted
            [typ] => ID
            [azp] => nextcloud
            [session_state] => omitted
            [at_hash] => omitted
            [acr] => 0
            [email_verified] => 1
            [name] => Test Marinello Cloack
            [preferred_username] => test@marinello.bz.it
            [given_name] => Test
            [family_name] => Marinello Cloack
            [email] => test@marinello.bz.it
        )

)
Hybridauth\Data\Collection Object
(
    [collection:protected] => stdClass Object
        (
            [sub] => bb7a9b4c-f0fc-497c-8eb0-098d3eb19e4c
            [email_verified] => 1
            [name] => Test Marinello Cloack
            [preferred_username] => test@marinello.bz.it
            [given_name] => Test
            [family_name] => Marinello Cloack
            [email] => test@marinello.bz.it
        )

)

seems to work properly but the "Full name" filed in Nextcloud is always equal to the username

mmaridev commented 3 years ago

Replacing https://github.com/zorn-v/nextcloud-social-login/blob/c8e940b5651ff418128cb72c2b784347dd10aaae/lib/Provider/CustomOpenIDConnect.php#L36 with

$userProfile->displayName = $data->get('name');

sets the "Full name" correctly

zorn-v commented 3 years ago

Very strange as preferred_username is returned. Display name should be test@marinello.bz.it in your case, but not UID. Anyway I change priority for preferred_username not so long ago, so revert it then.

battosai30 commented 3 years ago

Hi, I had the same issue but precisely in the second part of the script :

$userInfoUrl = trim($this->config->get('endpoints')['user_info_url']);
        if (!empty($userInfoUrl)) {
            $profile = new Data\Collection( $this->apiRequest($userInfoUrl) );

if (empty($userProfile->identifier)) {
                $userProfile->identifier = $profile->get('sub');
            }
            $userProfile->displayName = $profile->get('preferred_username') ?: $profile->get('nickname') ?: $profile->get('name');
            $userProfile->photoURL = $profile->get('picture') ?: $profile->get('avatar');
            if (preg_match('#<img.+src=["\'](.+?)["\']#', $userProfile->photoURL, $m)) {
                $userProfile->photoURL = $m[1];
            }
            $userProfile->email = $profile->get('email');
            if (empty($userProfile->data['groups']) && null !== $groups = $this->getGroups($profile)) {
                $userProfile->data['groups'] = $groups;
            }
        }

As my Keycloak provides userinfo, "name" is overrided by "preferred_username". It's not really an issue I guess but If anyone else has the same problem, you can suppress user info url in parameters or edit the code to priorise "name"