zorn-v / nextcloud-social-login

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

Login failed with custom Oauth2 provider: Can not get identifier from provider #409

Closed nl8590687 closed 1 year ago

nl8590687 commented 1 year ago

Hi,

I meet some trouble when using nextcloud-social-login The function getUserProfile() in file sociallogin/lib/Provider/CustomOAuth2.php need to add userid to get user profile, otherwise will login failed with message "Can not get identifier from provider "

before

if (!isset($response->identifier)) {
            $response->identifier = $response->id
                ?? $response->ID
                ?? $response->data->id
                ?? $response->user_id
                ?? $response->userId
                ?? $response->oauth_user_id
                ?? $response->sub
                ?? null
            ;
        }

after:

  if (!isset($response->identifier)) {
              $response->identifier = $response->id
                  ?? $response->ID
                  ?? $response->data->id
                  ?? $response->user_id
                  ?? $response->userId
->                ?? $response->userid
                  ?? $response->oauth_user_id
                  ?? $response->sub
                  ?? null
              ;
          }

I use an inner oauth2 provider, whose userInfo struct defined as:

type UserInfoResponse struct {
    StatusCode    int    `json:"status_code" form:"status_code"`       // status code for response
    StatusMessage string `json:"status_message" form:"status_message"` // status message for response
    Userid        string `json:"userid" form:"userid"`                 // user ID
    Username      string `json:"username" form:"username"`             // username
    Avatar        string `json:"avatar" form:"avatar"`                 // avatar
    Email         string `json:"email" form:"email"`                   // email
    EmailVerified bool   `json:"email_verified" form:"email_verified"` // has email verified
    PhoneNumber   string `json:"phone_number" form:"phone_number"`     // phone number
    PhoneVerified bool   `json:"phone_verified" form:"phone_verified"` // has phone number verified
    CreateTime    int64  `form:"create_time"`                          // user created time
}
zorn-v commented 1 year ago

Added in v5.4.3