Skip to content

Commit

Permalink
Merge pull request #560 from ericchiang/fix-user-api
Browse files Browse the repository at this point in the history
server: fix the path registration for user APIs at non-root URLs
  • Loading branch information
ericchiang authored Aug 19, 2016
2 parents b33227b + b466ae7 commit 7525e56
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ func (s *Server) HTTPHandler() http.Handler {

clock := clockwork.NewRealClock()
mux := http.NewServeMux()

// Handler methods which register handlers at prefixed paths.
handle := func(urlPath string, h http.Handler) {
p := path.Join(s.IssuerURL.Path, urlPath)
// path.Join always trims trailing slashes (https://play.golang.org/p/GRr0jDd9P7).
Expand All @@ -227,6 +229,14 @@ func (s *Server) HTTPHandler() http.Handler {
handleFunc := func(urlPath string, hf http.HandlerFunc) {
handle(urlPath, hf)
}
handleStripPrefix := func(urlPath string, h http.Handler) {
if s.IssuerURL.Path != "" {
handle(urlPath, http.StripPrefix(s.IssuerURL.Path, h))
} else {
handle(urlPath, h)
}
}

handleFunc(httpPathDiscovery, handleDiscoveryFunc(s.ProviderConfig()))
handleFunc(httpPathAuth, handleAuthFunc(s, s.Connectors, s.LoginTemplate, s.EnableRegistration))
handleFunc(httpPathOOB, handleOOBFunc(s, s.OOBTemplate))
Expand Down Expand Up @@ -293,7 +303,7 @@ func (s *Server) HTTPHandler() http.Handler {
usersAPI := usersapi.NewUsersAPI(s.UserManager, s.ClientManager, s.RefreshTokenRepo, s.UserEmailer, s.localConnectorID)
handler := NewUserMgmtServer(usersAPI, s.JWTVerifierFactory(), s.UserManager, s.ClientManager).HTTPHandler()

handle(apiBasePath+"/", handler)
handleStripPrefix(apiBasePath+"/", handler)

return http.Handler(mux)
}
Expand Down

0 comments on commit 7525e56

Please sign in to comment.