mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-16 18:47:10 +02:00
proxy: add route portal json (#5428)
* proxy: add route portal json * fix 405 issue * add link to issue * Update proxy/portal/filter_test.go Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com> --------- Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
This commit is contained in:
parent
6e1fabec0b
commit
e816cef2a1
10 changed files with 628 additions and 5 deletions
|
@ -40,11 +40,32 @@ func (p *Proxy) registerDashboardHandlers(r *mux.Router, opts *config.Options) *
|
|||
c.Path("/").Handler(httputil.HandlerFunc(p.Callback)).Methods(http.MethodGet)
|
||||
|
||||
// Programmatic API handlers and middleware
|
||||
a := r.PathPrefix(dashboardPath + "/api").Subrouter()
|
||||
// login api handler generates a user-navigable login url to authenticate
|
||||
a.Path("/v1/login").Handler(httputil.HandlerFunc(p.ProgrammaticLogin)).
|
||||
Queries(urlutil.QueryRedirectURI, "").
|
||||
Methods(http.MethodGet)
|
||||
// gorilla mux has a bug that prevents HTTP 405 errors from being returned properly so we do all this manually
|
||||
// https://github.com/gorilla/mux/issues/739
|
||||
r.PathPrefix(dashboardPath + "/api").
|
||||
Handler(httputil.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
|
||||
switch r.URL.Path {
|
||||
// login api handler generates a user-navigable login url to authenticate
|
||||
case dashboardPath + "/api/v1/login":
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
||||
return nil
|
||||
}
|
||||
if !r.URL.Query().Has(urlutil.QueryRedirectURI) {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return nil
|
||||
}
|
||||
return p.ProgrammaticLogin(w, r)
|
||||
case dashboardPath + "/api/v1/routes":
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
||||
return nil
|
||||
}
|
||||
return p.routesPortalJSON(w, r)
|
||||
}
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return nil
|
||||
}))
|
||||
|
||||
return r
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue