summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorenahum <nahumhbl@gmail.com>2017-05-17 17:33:44 -0400
committerJoram Wilander <jwawilander@gmail.com>2017-05-17 17:33:44 -0400
commit5f9a28ed6f45dd02a0aa2b4220717c29567a7ba8 (patch)
tree4e6fb7a42a00f35023a48768e6c834acd48e7dc5
parentd103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26 (diff)
downloadchat-5f9a28ed6f45dd02a0aa2b4220717c29567a7ba8.tar.gz
chat-5f9a28ed6f45dd02a0aa2b4220717c29567a7ba8.tar.bz2
chat-5f9a28ed6f45dd02a0aa2b4220717c29567a7ba8.zip
Ability to use OAuth login from mobile (#6432)
-rw-r--r--api/oauth.go2
-rw-r--r--api4/oauth.go33
-rw-r--r--app/oauth.go4
3 files changed, 31 insertions, 8 deletions
diff --git a/api/oauth.go b/api/oauth.go
index 6ff04d644..84d30ee61 100644
--- a/api/oauth.go
+++ b/api/oauth.go
@@ -157,7 +157,7 @@ func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
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
return
} else {
diff --git a/api4/oauth.go b/api4/oauth.go
index 33c166da4..626a6065f 100644
--- a/api4/oauth.go
+++ b/api4/oauth.go
@@ -35,6 +35,7 @@ func InitOAuth() {
// 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]+}/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")
// 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 {
redirectUrl = app.GetProtocol(r) + "://" + r.Host + "/claim?email=" + url.QueryEscape(props["email"])
- } else if action == model.OAUTH_ACTION_MOBILE {
- ReturnStatusOK(w)
- return
} else {
session, err := app.DoLogin(w, r, user, "")
if err != nil {
@@ -432,7 +430,12 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
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) {
@@ -450,7 +453,27 @@ func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
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
return
} else {
diff --git a/app/oauth.go b/app/oauth.go
index 03e3c507b..deeb10f17 100644
--- a/app/oauth.go
+++ b/app/oauth.go
@@ -290,9 +290,9 @@ func newSessionUpdateToken(appName string, accessData *model.AccessData, user *m
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["action"] = model.OAUTH_ACTION_LOGIN
+ stateProps["action"] = action
if len(teamId) != 0 {
stateProps["team_id"] = teamId
}