[MM-28125] einterface/oauthprovide: return parsing errors (#15426)
* einterface/oauthprovide: return parsing errors * Update app/oauth.go * reflect review comments * fix var name error Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
90738de75f
Коммит
c05ee81c9f
34
app/oauth.go
34
app/oauth.go
@@ -574,19 +574,18 @@ func (a *App) LoginByOAuth(service string, userData io.Reader, teamId string) (*
|
||||
return nil, model.NewAppError("LoginByOAuth", "api.user.login_by_oauth.parse.app_error",
|
||||
map[string]interface{}{"Service": service}, "", http.StatusBadRequest)
|
||||
}
|
||||
authUser := provider.GetUserFromJson(bytes.NewReader(buf.Bytes()))
|
||||
|
||||
authData := ""
|
||||
if authUser.AuthData != nil {
|
||||
authData = *authUser.AuthData
|
||||
authUser, err1 := provider.GetUserFromJson(bytes.NewReader(buf.Bytes()))
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("LoginByOAuth", "api.user.login_by_oauth.parse.app_error",
|
||||
map[string]interface{}{"Service": service}, err1.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(authData) == 0 {
|
||||
if *authUser.AuthData == "" {
|
||||
return nil, model.NewAppError("LoginByOAuth", "api.user.login_by_oauth.parse.app_error",
|
||||
map[string]interface{}{"Service": service}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
user, err := a.GetUserByAuth(&authData, service)
|
||||
user, err := a.GetUserByAuth(model.NewString(*authUser.AuthData), service)
|
||||
if err != nil {
|
||||
if err.Id == store.MISSING_AUTH_ACCOUNT_ERROR {
|
||||
user, err = a.CreateOAuthUser(service, bytes.NewReader(buf.Bytes()), teamId)
|
||||
@@ -622,23 +621,22 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.unavailable.app_error",
|
||||
map[string]interface{}{"Service": strings.Title(service)}, "", http.StatusNotImplemented)
|
||||
}
|
||||
ssoUser := provider.GetUserFromJson(userData)
|
||||
ssoEmail := ssoUser.Email
|
||||
|
||||
authData := ""
|
||||
if ssoUser.AuthData != nil {
|
||||
authData = *ssoUser.AuthData
|
||||
if email == "" {
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.blank_email.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(authData) == 0 {
|
||||
ssoUser, err1 := provider.GetUserFromJson(userData)
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.parse.app_error",
|
||||
map[string]interface{}{"Service": service}, err1.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if *ssoUser.AuthData == "" {
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.parse.app_error",
|
||||
map[string]interface{}{"Service": service}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(email) == 0 {
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.blank_email.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
user, err := a.Srv().Store.User().GetByEmail(email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -648,7 +646,7 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err = a.Srv().Store.User().UpdateAuthData(user.Id, service, &authData, ssoEmail, true); err != nil {
|
||||
if _, err = a.Srv().Store.User().UpdateAuthData(user.Id, service, model.NewString(*ssoUser.AuthData), ssoUser.Email, true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
13
app/user.go
13
app/user.go
@@ -328,10 +328,9 @@ func (a *App) CreateOAuthUser(service string, userData io.Reader, teamId string)
|
||||
if provider == nil {
|
||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.not_available.app_error", map[string]interface{}{"Service": strings.Title(service)}, "", http.StatusNotImplemented)
|
||||
}
|
||||
user := provider.GetUserFromJson(userData)
|
||||
|
||||
if user == nil {
|
||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]interface{}{"Service": service}, "", http.StatusInternalServerError)
|
||||
user, err1 := provider.GetUserFromJson(userData)
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]interface{}{"Service": service}, err1.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
suchan := make(chan store.StoreResult, 1)
|
||||
@@ -1857,9 +1856,9 @@ func (a *App) AutocompleteUsersInTeam(teamId string, term string, options *model
|
||||
}
|
||||
|
||||
func (a *App) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OauthProvider, service string) *model.AppError {
|
||||
oauthUser := provider.GetUserFromJson(userData)
|
||||
if oauthUser == nil {
|
||||
return model.NewAppError("UpdateOAuthUserAttrs", "api.user.update_oauth_user_attrs.get_user.app_error", map[string]interface{}{"Service": service}, "", http.StatusBadRequest)
|
||||
oauthUser, err1 := provider.GetUserFromJson(userData)
|
||||
if err1 != nil {
|
||||
return model.NewAppError("UpdateOAuthUserAttrs", "api.user.update_oauth_user_attrs.get_user.app_error", map[string]interface{}{"Service": service}, err1.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
userAttrsChanged := false
|
||||
|
||||
Ссылка в новой задаче
Block a user