diff --git a/examples/app/main.go b/examples/app/main.go index 3344dde5..1f2c62c0 100644 --- a/examples/app/main.go +++ b/examples/app/main.go @@ -16,6 +16,7 @@ import ( "net/http" "net/url" "os" + "path" "strings" "time" @@ -181,7 +182,7 @@ func NewClientHandler(c *oidc.Client, issuer string, cbURL url.URL) http.Handler } resendURL := *issuerURL - resendURL.Path = "/resend-verify-email" + resendURL.Path = path.Join(resendURL.Path, "/resend-verify-email") mux.HandleFunc("/resend", handleResendFunc(c, *issuerURL, resendURL, cbURL)) return mux diff --git a/server/register.go b/server/register.go index 013c0b22..c73ef252 100644 --- a/server/register.go +++ b/server/register.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "net/url" + "path" "strings" "github.com/coreos/dex/connector" @@ -336,7 +337,7 @@ func getConnectorForUserByEmail(ur user.UserRepo, email string) (string, error) func newLoginURLFromSession(issuer url.URL, ses *session.Session, register bool, connectorFilter []string, msgCode string) *url.URL { loginURL := issuer v := loginURL.Query() - loginURL.Path = httpPathAuth + loginURL.Path = path.Join(loginURL.Path, httpPathAuth) v.Set("redirect_uri", ses.RedirectURL.String()) v.Set("state", ses.ClientState) v.Set("client_id", ses.ClientID) diff --git a/server/server.go b/server/server.go index 1e0590ea..49611149 100644 --- a/server/server.go +++ b/server/server.go @@ -8,6 +8,7 @@ import ( "net/url" "path" "sort" + "strings" "time" "github.com/coreos/go-oidc/jose" @@ -215,7 +216,13 @@ func (s *Server) HTTPHandler() http.Handler { clock := clockwork.NewRealClock() mux := http.NewServeMux() handle := func(urlPath string, h http.Handler) { - mux.Handle(path.Join(s.IssuerURL.Path, urlPath), h) + p := path.Join(s.IssuerURL.Path, urlPath) + // path.Join always trims trailing slashes (https://play.golang.org/p/GRr0jDd9P7). + // If path being registered has a trailing slash, add it back on. + if strings.HasSuffix(urlPath, "/") { + p = p + "/" + } + mux.Handle(p, h) } handleFunc := func(urlPath string, hf http.HandlerFunc) { handle(urlPath, hf) @@ -277,7 +284,7 @@ func (s *Server) HTTPHandler() http.Handler { } // NOTE(ericchiang): This path MUST end in a "/" in order to indicate a // path prefix rather than an absolute path. - mux.Handle(path.Join(httpPathAuth, idpc.ID())+"/", idpc.Handler(*errorURL)) + handle(path.Join(httpPathAuth, idpc.ID())+"/", idpc.Handler(*errorURL)) } apiBasePath := path.Join(httpPathAPI, APIVersion) diff --git a/static/html/reset-password.html b/static/html/reset-password.html index 898b3255..b692489e 100644 --- a/static/html/reset-password.html +++ b/static/html/reset-password.html @@ -15,7 +15,7 @@ {{ end }} {{ else }}

Reset your password

-
+