diff --git a/ui/src/app/login/components/login.tsx b/ui/src/app/login/components/login.tsx index 8662d4c2f132d..db67ff185cf78 100644 --- a/ui/src/app/login/components/login.tsx +++ b/ui/src/app/login/components/login.tsx @@ -20,7 +20,7 @@ interface State { loginError: string; loginInProgress: boolean; returnUrl: string; - ssoLoginError: string; + hasSsoLoginError: boolean; } export class Login extends React.Component, State> { @@ -31,13 +31,13 @@ export class Login extends React.Component, State> { public static getDerivedStateFromProps(props: RouteComponentProps<{}>): Partial { const search = new URLSearchParams(props.history.location.search); const returnUrl = search.get('return_url') || ''; - const ssoLoginError = search.get('sso_error') || ''; - return {ssoLoginError, returnUrl}; + const hasSsoLoginError = search.get('has_sso_error') === 'true'; + return {hasSsoLoginError, returnUrl}; } constructor(props: RouteComponentProps<{}>) { super(props); - this.state = {authSettings: null, loginError: null, returnUrl: null, ssoLoginError: null, loginInProgress: false}; + this.state = {authSettings: null, loginError: null, returnUrl: null, hasSsoLoginError: false, loginInProgress: false}; } public async componentDidMount() { @@ -69,7 +69,7 @@ export class Login extends React.Component, State> { )} - {this.state.ssoLoginError &&
{this.state.ssoLoginError}
} + {this.state.hasSsoLoginError &&
Login failed.
} {authSettings && !authSettings.userLoginsDisabled && (
or diff --git a/util/dex/dex.go b/util/dex/dex.go index 735b7cbb72976..3f109b225cfc6 100644 --- a/util/dex/dex.go +++ b/util/dex/dex.go @@ -3,20 +3,18 @@ package dex import ( "bytes" "fmt" - "html" "io/ioutil" "net/http" "net/http/httputil" "net/url" "path" - "regexp" "strconv" + log "github.com/sirupsen/logrus" + "github.com/argoproj/argo-cd/v2/util/errors" ) -var messageRe = regexp.MustCompile(`

(.*)([\s\S]*?)<\/p>`) - func decorateDirector(director func(req *http.Request), target *url.URL) func(req *http.Request) { return func(req *http.Request) { director(req) @@ -44,16 +42,10 @@ func NewDexHTTPReverseProxy(serverAddr string, baseHRef string) func(writer http if err != nil { return err } - var message string - matches := messageRe.FindSubmatch(b) - if len(matches) > 1 { - message = html.UnescapeString(string(matches[1])) - } else { - message = "Unknown error" - } + log.Errorf("received error from dex: %s", string(b)) resp.ContentLength = 0 resp.Header.Set("Content-Length", strconv.Itoa(0)) - resp.Header.Set("Location", fmt.Sprintf("%s?sso_error=%s", path.Join(baseHRef, "login"), url.QueryEscape(message))) + resp.Header.Set("Location", fmt.Sprintf("%s?has_sso_error=true", path.Join(baseHRef, "login"))) resp.StatusCode = http.StatusSeeOther resp.Body = ioutil.NopCloser(bytes.NewReader(make([]byte, 0))) return nil diff --git a/util/dex/dex_test.go b/util/dex/dex_test.go index ffe1fa7862878..42d84465f1b65 100644 --- a/util/dex/dex_test.go +++ b/util/dex/dex_test.go @@ -309,7 +309,7 @@ func Test_DexReverseProxy(t *testing.T) { assert.Equal(t, http.StatusSeeOther, resp.StatusCode) location, _ := resp.Location() fmt.Printf("%s %s\n", resp.Status, location.RequestURI()) - assert.True(t, strings.HasPrefix(location.RequestURI(), "/login?sso_error")) + assert.True(t, strings.HasPrefix(location.RequestURI(), "/login?has_sso_error=true")) }) t.Run("Invalid URL for Dex reverse proxy", func(t *testing.T) {