diff --git a/utils/api.go b/utils/api.go
index 16caed645c..0312e061c4 100644
--- a/utils/api.go
+++ b/utils/api.go
@@ -111,6 +111,7 @@ func RenderWebError(config *model.Config, w http.ResponseWriter, r *http.Request
fmt.Fprintln(w, `
`)
fmt.Fprintln(w, ``)
fmt.Fprintln(w, `
`+message+`
diff --git a/web/oauth.go b/web/oauth.go
index 2772acfb91..2c0f48ddf8 100644
--- a/web/oauth.go
+++ b/web/oauth.go
@@ -286,12 +286,8 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
}
renderError := func(err *model.AppError) {
- if isMobile {
- if hasRedirectURL {
- utils.RenderMobileError(c.App.Config(), w, err, redirectURL)
- } else {
- w.Write([]byte(err.ToJson()))
- }
+ if isMobile && hasRedirectURL {
+ utils.RenderMobileError(c.App.Config(), w, err, redirectURL)
} else {
utils.RenderWebAppError(c.App.Config(), w, r, err, c.App.AsymmetricSigningKey())
}
diff --git a/web/oauth_test.go b/web/oauth_test.go
index 5fa542a0c7..5c28a7a48d 100644
--- a/web/oauth_test.go
+++ b/web/oauth_test.go
@@ -4,6 +4,7 @@
package web
import (
+ "bytes"
"encoding/base64"
"io"
"io/ioutil"
@@ -17,6 +18,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/einterfaces"
+ "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
)
@@ -522,6 +524,44 @@ func TestOAuthComplete(t *testing.T) {
}
}
+func TestOAuthComplete_ErrorMessages(t *testing.T) {
+ th := Setup(t).InitBasic()
+ defer th.TearDown()
+ c := &Context{
+ App: th.App,
+ Params: &Params{
+ Service: "gitlab",
+ },
+ }
+
+ translationFunc := utils.GetUserTranslations("en")
+ c.App.SetT(translationFunc)
+ buffer := &bytes.Buffer{}
+ c.Logger = mlog.NewTestingLogger(t, buffer)
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.Enable = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
+ provider := &MattermostTestProvider{}
+ einterfaces.RegisterOauthProvider(model.SERVICE_GITLAB, provider)
+
+ responseWriter := httptest.NewRecorder()
+
+ // Renders for web & mobile app with webview
+ request, _ := http.NewRequest(http.MethodGet, th.App.GetSiteURL()+"/signup/gitlab/complete?code=1234", nil)
+
+ completeOAuth(c, responseWriter, request)
+ assert.Contains(t, responseWriter.Body.String(), "")
+
+ // Renders for mobile app with redirect url
+ stateProps := map[string]string{}
+ stateProps["action"] = model.OAUTH_ACTION_MOBILE
+ stateProps["redirect_to"] = th.App.Config().NativeAppSettings.AppCustomURLSchemes[0]
+ state := base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps)))
+ request2, _ := http.NewRequest(http.MethodGet, th.App.GetSiteURL()+"/signup/gitlab/complete?code=1234&state="+url.QueryEscape(state), nil)
+
+ completeOAuth(c, responseWriter, request2)
+ assert.Contains(t, responseWriter.Body.String(), "")
+}
+
func HttpGet(url string, httpClient *http.Client, authToken string, followRedirect bool) (*http.Response, *model.AppError) {
rq, _ := http.NewRequest("GET", url, nil)
rq.Close = true
diff --git a/web/saml.go b/web/saml.go
index e78efb0559..eb52a0a346 100644
--- a/web/saml.go
+++ b/web/saml.go
@@ -111,13 +111,9 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
}
handleError := func(err *model.AppError) {
- if isMobile {
+ if isMobile && hasRedirectURL {
err.Translate(c.App.T)
- if hasRedirectURL {
- utils.RenderMobileError(c.App.Config(), w, err, redirectURL)
- } else {
- w.Write([]byte(err.ToJson()))
- }
+ utils.RenderMobileError(c.App.Config(), w, err, redirectURL)
} else {
c.Err = err
c.Err.StatusCode = http.StatusFound