Skip to content
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

connector: fix path that connectors listen on #522

Merged
merged 1 commit into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions connector/connector_ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ func (c *LDAPConnector) LoginURL(sessionKey, prompt string) (string, error) {
return path.Join(c.namespace.Path, "login") + "?" + enc, nil
}

func (c *LDAPConnector) Register(mux *http.ServeMux, errorURL url.URL) {
route := path.Join(c.namespace.Path, "login")
mux.Handle(route, handlePasswordLogin(c.loginFunc, c.loginTpl, c, route, errorURL))
func (c *LDAPConnector) Handler(errorURL url.URL) http.Handler {
route := path.Join(c.namespace.Path, "/login")
return handlePasswordLogin(c.loginFunc, c.loginTpl, c, route, errorURL)
}

func (c *LDAPConnector) Sync() chan struct{} {
Expand Down
6 changes: 3 additions & 3 deletions connector/connector_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ func (c *LocalConnector) LoginURL(sessionKey, prompt string) (string, error) {
return path.Join(c.namespace.Path, "login") + "?" + enc, nil
}

func (c *LocalConnector) Register(mux *http.ServeMux, errorURL url.URL) {
route := c.namespace.Path + "/login"
mux.Handle(route, handlePasswordLogin(c.loginFunc, c.loginTpl, c.idp, route, errorURL))
func (c *LocalConnector) Handler(errorURL url.URL) http.Handler {
route := path.Join(c.namespace.Path, "/login")
return handlePasswordLogin(c.loginFunc, c.loginTpl, c.idp, route, errorURL)
}

func (c *LocalConnector) Sync() chan struct{} {
Expand Down
4 changes: 2 additions & 2 deletions connector/connector_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (c *OAuth2Connector) LoginURL(sessionKey, prompt string) (string, error) {
return c.conn.Client().AuthCodeURL(sessionKey, oauth2.GrantTypeAuthCode, prompt), nil
}

func (c *OAuth2Connector) Register(mux *http.ServeMux, errorURL url.URL) {
mux.Handle(c.cbURL.Path, c.handleCallbackFunc(c.loginFunc, errorURL))
func (c *OAuth2Connector) Handler(errorURL url.URL) http.Handler {
return c.handleCallbackFunc(c.loginFunc, errorURL)
}

func (c *OAuth2Connector) handleCallbackFunc(lf oidc.LoginFunc, errorURL url.URL) http.HandlerFunc {
Expand Down
4 changes: 2 additions & 2 deletions connector/connector_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (c *OIDCConnector) LoginURL(sessionKey, prompt string) (string, error) {
return oac.AuthCodeURL(sessionKey, "", prompt), nil
}

func (c *OIDCConnector) Register(mux *http.ServeMux, errorURL url.URL) {
mux.Handle(c.cbURL.Path, c.handleCallbackFunc(c.loginFunc, errorURL))
func (c *OIDCConnector) Handler(errorURL url.URL) http.Handler {
return c.handleCallbackFunc(c.loginFunc, errorURL)
}

func (c *OIDCConnector) Sync() chan struct{} {
Expand Down
8 changes: 4 additions & 4 deletions connector/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type Connector interface {
// and OAuth2 prompt type.
LoginURL(sessionKey, prompt string) (string, error)

// Register allows connectors to register a callback handler with the
// Handler allows connectors to register a callback handler with the
// dex server.
//
// Connectors should register with a path that extends the namespace
// URL provided when the Connector is instantiated.
Register(mux *http.ServeMux, errorURL url.URL)
// Connectors will handle any path that extends the namespace URL provided
// when the Connector is instantiated.
Handler(errorURL url.URL) http.Handler

// Sync triggers any long-running tasks needed to maintain the
// Connector's operation. For example, this would encompass
Expand Down
4 changes: 3 additions & 1 deletion server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (f *fakeConnector) LoginURL(sessionKey, prompt string) (string, error) {
return f.loginURL, nil
}

func (f *fakeConnector) Register(mux *http.ServeMux, errorURL url.URL) {}
func (f *fakeConnector) Handler(errorURL url.URL) http.Handler {
return http.HandlerFunc(http.NotFound)
}

func (f *fakeConnector) Sync() chan struct{} {
return nil
Expand Down
4 changes: 3 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ func (s *Server) HTTPHandler() http.Handler {
if err != nil {
log.Fatal(err)
}
idpc.Register(mux, *errorURL)
// 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))
}

apiBasePath := path.Join(httpPathAPI, APIVersion)
Expand Down