Commit f17c15c9 authored by Emil Velikov's avatar Emil Velikov Committed by Christopher Speller

Simplify oauth (#8972)

* Remove unused OauthProvider::GetIdentifier
Signed-off-by: default avatarEmil Velikov <emil.velikov@collabora.com>

* Reuse gitlab's getAuthData() instead of open-coding it
Signed-off-by: default avatarEmil Velikov <emil.velikov@collabora.com>

* Remove OauthProvider::GetAuthDataFromJson interface

The data is already available via GetUserFromJson().AuthData
Signed-off-by: default avatarEmil Velikov <emil.velikov@collabora.com>
parent 85aa3d66
......@@ -1127,15 +1127,8 @@ func closeBody(r *http.Response) {
type MattermostTestProvider struct {
}
func (m *MattermostTestProvider) GetIdentifier() string {
return model.SERVICE_GITLAB
}
func (m *MattermostTestProvider) GetUserFromJson(data io.Reader) *model.User {
return model.UserFromJson(data)
}
func (m *MattermostTestProvider) GetAuthDataFromJson(data io.Reader) string {
authData := model.UserFromJson(data)
return authData.Email
user := model.UserFromJson(data)
user.AuthData = &user.Email
return user
}
......@@ -457,7 +457,13 @@ func (a *App) LoginByOAuth(service string, userData io.Reader, teamId string) (*
return nil, model.NewAppError("LoginByOAuth", "api.user.login_by_oauth.not_available.app_error",
map[string]interface{}{"Service": strings.Title(service)}, "", http.StatusNotImplemented)
} else {
authData = provider.GetAuthDataFromJson(bytes.NewReader(buf.Bytes()))
authUser := provider.GetUserFromJson(bytes.NewReader(buf.Bytes()))
if authUser.AuthData != nil {
authData = *authUser.AuthData
} else {
authData = ""
}
}
if len(authData) == 0 {
......
......@@ -10,9 +10,7 @@ import (
)
type OauthProvider interface {
GetIdentifier() string
GetUserFromJson(data io.Reader) *model.User
GetAuthDataFromJson(data io.Reader) string
}
var oauthProviders = make(map[string]OauthProvider)
......
......@@ -47,7 +47,7 @@ func userFromGitLabUser(glu *GitLabUser) *model.User {
user.FirstName = glu.Name
}
user.Email = glu.Email
userId := strconv.FormatInt(glu.Id, 10)
userId := glu.getAuthData()
user.AuthData = &userId
user.AuthService = model.USER_AUTH_SERVICE_GITLAB
......@@ -90,10 +90,6 @@ func (glu *GitLabUser) getAuthData() string {
return strconv.FormatInt(glu.Id, 10)
}
func (m *GitLabProvider) GetIdentifier() string {
return model.USER_AUTH_SERVICE_GITLAB
}
func (m *GitLabProvider) GetUserFromJson(data io.Reader) *model.User {
glu := gitLabUserFromJson(data)
if glu.IsValid() {
......@@ -102,13 +98,3 @@ func (m *GitLabProvider) GetUserFromJson(data io.Reader) *model.User {
return &model.User{}
}
func (m *GitLabProvider) GetAuthDataFromJson(data io.Reader) string {
glu := gitLabUserFromJson(data)
if glu.IsValid() {
return glu.getAuthData()
}
return ""
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment