diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-08-02 12:53:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-02 12:53:01 -0700 |
commit | 873e4f49038746b71ab9997fc10c89192ec1cd16 (patch) | |
tree | cd4e2232792f2c4ff82941a3a6297d78c94555bb /api4/oauth.go | |
parent | 76bfd279b34f960149dba15424593dfd5fbfb956 (diff) | |
parent | fa3dd6a84bb51e8a5c3d3183bdb692386bb77c5a (diff) | |
download | chat-873e4f49038746b71ab9997fc10c89192ec1cd16.tar.gz chat-873e4f49038746b71ab9997fc10c89192ec1cd16.tar.bz2 chat-873e4f49038746b71ab9997fc10c89192ec1cd16.zip |
Merge pull request #7085 from saturninoabril/merge-4.0.2
Merge 4.0.2
Diffstat (limited to 'api4/oauth.go')
-rw-r--r-- | api4/oauth.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/api4/oauth.go b/api4/oauth.go index 05a38d206..c1aa49df4 100644 --- a/api4/oauth.go +++ b/api4/oauth.go @@ -403,10 +403,20 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) { uri := c.GetSiteURLHeader() + "/signup/" + service + "/complete" body, teamId, props, err := app.AuthorizeOAuthUser(w, r, service, code, state, uri) + + action := "" + if props != nil { + action = props["action"] + } + if err != nil { err.Translate(c.T) l4g.Error(err.Error()) - http.Redirect(w, r, c.GetSiteURLHeader()+"/error?message="+err.Message, http.StatusTemporaryRedirect) + if action == model.OAUTH_ACTION_MOBILE { + w.Write([]byte(err.ToJson())) + } else { + http.Redirect(w, r, c.GetSiteURLHeader()+"/error?message="+err.Message, http.StatusTemporaryRedirect) + } return } @@ -414,12 +424,14 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) { if err != nil { err.Translate(c.T) l4g.Error(err.Error()) - http.Redirect(w, r, c.GetSiteURLHeader()+"/error?message="+err.Message, http.StatusTemporaryRedirect) + if action == model.OAUTH_ACTION_MOBILE { + w.Write([]byte(err.ToJson())) + } else { + http.Redirect(w, r, c.GetSiteURLHeader()+"/error?message="+err.Message, http.StatusTemporaryRedirect) + } return } - action := props["action"] - var redirectUrl string if action == model.OAUTH_ACTION_EMAIL_TO_SSO { redirectUrl = c.GetSiteURLHeader() + "/login?extra=signin_change" @@ -429,7 +441,11 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) { } else { session, err := app.DoLogin(w, r, user, "") if err != nil { + err.Translate(c.T) c.Err = err + if action == model.OAUTH_ACTION_MOBILE { + w.Write([]byte(err.ToJson())) + } return } |