-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Issue #351 - forward dex error message to login page #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,13 @@ import ( | |
| "golang.org/x/oauth2" | ||
| "google.golang.org/grpc" | ||
|
|
||
| "io/ioutil" | ||
| "strconv" | ||
|
|
||
| "regexp" | ||
|
|
||
| "html" | ||
|
|
||
| "github.com/argoproj/argo-cd/common" | ||
| "github.com/argoproj/argo-cd/errors" | ||
| "github.com/argoproj/argo-cd/util/cache" | ||
|
|
@@ -43,9 +50,36 @@ type DexAPIClient struct { | |
| // ArgoCD API server wants to proxy requests at /api/dex, then the dex config yaml issuer URL should | ||
| // also be /api/dex (e.g. issuer: https://argocd.example.com/api/dex) | ||
| func NewDexHTTPReverseProxy() func(writer http.ResponseWriter, request *http.Request) { | ||
| messageRe, err := regexp.Compile(`<p>(.*)([\s\S]*?)<\/p>`) | ||
| errors.CheckError(err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets move the regexp.Compile into a package level var
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| target, err := url.Parse(DexReverseProxyAddr) | ||
| errors.CheckError(err) | ||
| proxy := httputil.NewSingleHostReverseProxy(target) | ||
| proxy.ModifyResponse = func(resp *http.Response) error { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! didn't know they had a ModifyResponse function. |
||
| if resp.StatusCode == 500 { | ||
| b, err := ioutil.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = resp.Body.Close() | ||
| 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" | ||
| } | ||
| resp.ContentLength = 0 | ||
| resp.Header.Set("Content-Length", strconv.Itoa(0)) | ||
| resp.Header.Set("Location", fmt.Sprintf("/login?sso_error=%s", url.QueryEscape(message))) | ||
| resp.StatusCode = http.StatusSeeOther | ||
| return nil | ||
| } | ||
| return nil | ||
| } | ||
| return func(w http.ResponseWriter, r *http.Request) { | ||
| proxy.ServeHTTP(w, r) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please put standard lib imports at top
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done