Ability to use OAuth login from mobile (#6432)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
d103ed6ca9
Коммит
5f9a28ed6f
@@ -157,7 +157,7 @@ func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if authUrl, err := app.GetOAuthLoginEndpoint(service, teamId, redirectTo, loginHint); err != nil {
|
if authUrl, err := app.GetOAuthLoginEndpoint(service, teamId, model.OAUTH_ACTION_LOGIN, redirectTo, loginHint); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ func InitOAuth() {
|
|||||||
// API version independent OAuth as a client endpoints
|
// API version independent OAuth as a client endpoints
|
||||||
BaseRoutes.Root.Handle("/oauth/{service:[A-Za-z0-9]+}/complete", ApiHandler(completeOAuth)).Methods("GET")
|
BaseRoutes.Root.Handle("/oauth/{service:[A-Za-z0-9]+}/complete", ApiHandler(completeOAuth)).Methods("GET")
|
||||||
BaseRoutes.Root.Handle("/oauth/{service:[A-Za-z0-9]+}/login", ApiHandler(loginWithOAuth)).Methods("GET")
|
BaseRoutes.Root.Handle("/oauth/{service:[A-Za-z0-9]+}/login", ApiHandler(loginWithOAuth)).Methods("GET")
|
||||||
|
BaseRoutes.Root.Handle("/oauth/{service:[A-Za-z0-9]+}/mobile_login", ApiHandler(mobileLoginWithOAuth)).Methods("GET")
|
||||||
BaseRoutes.Root.Handle("/oauth/{service:[A-Za-z0-9]+}/signup", ApiHandler(signupWithOAuth)).Methods("GET")
|
BaseRoutes.Root.Handle("/oauth/{service:[A-Za-z0-9]+}/signup", ApiHandler(signupWithOAuth)).Methods("GET")
|
||||||
|
|
||||||
// Old endpoints for backwards compatibility, needed to not break SSO for any old setups
|
// Old endpoints for backwards compatibility, needed to not break SSO for any old setups
|
||||||
@@ -417,9 +418,6 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
} else if action == model.OAUTH_ACTION_SSO_TO_EMAIL {
|
} else if action == model.OAUTH_ACTION_SSO_TO_EMAIL {
|
||||||
|
|
||||||
redirectUrl = app.GetProtocol(r) + "://" + r.Host + "/claim?email=" + url.QueryEscape(props["email"])
|
redirectUrl = app.GetProtocol(r) + "://" + r.Host + "/claim?email=" + url.QueryEscape(props["email"])
|
||||||
} else if action == model.OAUTH_ACTION_MOBILE {
|
|
||||||
ReturnStatusOK(w)
|
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
session, err := app.DoLogin(w, r, user, "")
|
session, err := app.DoLogin(w, r, user, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -432,7 +430,12 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
redirectUrl = c.GetSiteURLHeader()
|
redirectUrl = c.GetSiteURLHeader()
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, redirectUrl, http.StatusTemporaryRedirect)
|
if action == model.OAUTH_ACTION_MOBILE {
|
||||||
|
ReturnStatusOK(w)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, redirectUrl, http.StatusTemporaryRedirect)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -450,7 +453,27 @@ func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if authUrl, err := app.GetOAuthLoginEndpoint(c.Params.Service, teamId, redirectTo, loginHint); err != nil {
|
if authUrl, err := app.GetOAuthLoginEndpoint(c.Params.Service, teamId, model.OAUTH_ACTION_LOGIN, redirectTo, loginHint); err != nil {
|
||||||
|
c.Err = err
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, authUrl, http.StatusFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mobileLoginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
c.RequireService()
|
||||||
|
if c.Err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
teamId, err := app.GetTeamIdFromQuery(r.URL.Query())
|
||||||
|
if err != nil {
|
||||||
|
c.Err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if authUrl, err := app.GetOAuthLoginEndpoint(c.Params.Service, teamId, model.OAUTH_ACTION_MOBILE, "", ""); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -290,9 +290,9 @@ func newSessionUpdateToken(appName string, accessData *model.AccessData, user *m
|
|||||||
return accessRsp, nil
|
return accessRsp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOAuthLoginEndpoint(service, teamId, redirectTo, loginHint string) (string, *model.AppError) {
|
func GetOAuthLoginEndpoint(service, teamId, action, redirectTo, loginHint string) (string, *model.AppError) {
|
||||||
stateProps := map[string]string{}
|
stateProps := map[string]string{}
|
||||||
stateProps["action"] = model.OAUTH_ACTION_LOGIN
|
stateProps["action"] = action
|
||||||
if len(teamId) != 0 {
|
if len(teamId) != 0 {
|
||||||
stateProps["team_id"] = teamId
|
stateProps["team_id"] = teamId
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user