zorn-v / nextcloud-social-login

GNU Affero General Public License v3.0
198 stars 137 forks source link

Provider API returned an unexpected response (Wordpress miniOrange OAuth 2.0 Server) #269

Closed vdietmar closed 3 years ago

vdietmar commented 3 years ago

Hi,

I am using Wordpress as a OAuth server (Plugin "miniOrange OAuth 2.0 Server/Provider"). I can't get it working though initially since Nextcloud Social Login returns "Provider API returned an unexpected response".

Debugging this unveils that miniOrange returns two tags "ID" and "username". Both are not considered valid by Social Login "CustomOAuth2.php" provider:

        if (!isset($response->identifier) && isset($response->id)) {
            $response->identifier = $response->id;
        }
        if (!isset($response->identifier) && isset($response->data->id)) {
            $response->identifier = $response->data->id;
        }
        if (!isset($response->identifier) && isset($response->user_id)) {
            $response->identifier = $response->user_id;
        }

Which then seems to lead to:

        if (!$data->exists('identifier')) {
            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
        }

When I add this, all is good:

        if (!isset($response->identifier) && isset($response->username)) {
            $response->identifier = $response->username;
        }

My conclusion is that Social Login should add more flexibility to what OAuth response tags are considered as "identifier". This could be done by a simple config setting, for example.

zorn-v commented 3 years ago

Username is not correct for user id. In your case it maybe so, but there are systems where two different users has same username. I'll add "ID" in oauth check.

UspenskiyAN commented 3 years ago

I have similar problem with my IdentityServer4 instance. In IS4 user id is GUID, so there's no sense to use it. In my case i use

    if (!isset($response->identifier) && isset($response->preferred_username)) {
            $response->identifier = $response->preferred_username;
        }

preffered_username is a login, so it's also unique. Maybe it makes sense to add to settings a field like "Custom user id fieldname" and use it in CustomOAuth2.php?

zorn-v commented 3 years ago

preffered_username is a login

Are you sure ? There is no some settings in user profile which changed "preferred_username" to some user defined ?

zorn-v commented 3 years ago

Maybe it makes sense to add to settings a field like "Custom user id fieldname" and use it in CustomOAuth2.php?

No. Discussed many times.

vdietmar commented 3 years ago

Ok. I respect this decision and continue to tweak the plugin:) At the very least, this can serve as explanation for other users.