(server *web.Server)
| 240 | } |
| 241 | |
| 242 | func (s *server) RegisterRoutes(server *web.Server) { |
| 243 | router := server.PrefixWithRedirect(s.config.Mount).Subrouter() |
| 244 | router.Use( |
| 245 | func(next http.Handler) http.Handler { |
| 246 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 247 | r, nonce := webui.WithNonce(r) |
| 248 | cspString := s.generateCSP(s.configFromContext(r.Context()), nonce) |
| 249 | w.Header().Set("Content-Security-Policy", cspString) |
| 250 | next.ServeHTTP(w, r) |
| 251 | }) |
| 252 | }, |
| 253 | ratelimit.HTTPMiddleware(s.c.RateLimiter(), "http:oauth"), |
| 254 | func(next http.Handler) http.Handler { |
| 255 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 256 | config := s.configFromContext(r.Context()) |
| 257 | r = webui.WithTemplateData(r, config.UI.TemplateData) |
| 258 | frontendConfig := config.UI.FrontendConfig |
| 259 | frontendConfig.Language = config.UI.TemplateData.Language |
| 260 | r = webui.WithAppConfig(r, struct { |
| 261 | FrontendConfig |
| 262 | }{ |
| 263 | FrontendConfig: frontendConfig, |
| 264 | }) |
| 265 | next.ServeHTTP(w, r) |
| 266 | }) |
| 267 | }, |
| 268 | webhandlers.WithErrorHandlers(map[string]http.Handler{ |
| 269 | "text/html": webui.Template, |
| 270 | }), |
| 271 | ) |
| 272 | |
| 273 | csrfMiddleware := webmiddleware.CSRF( |
| 274 | s.config.CSRFAuthKey, |
| 275 | csrf.CookieName("_csrf"), |
| 276 | csrf.FieldName("_csrf"), |
| 277 | csrf.Path("/"), |
| 278 | ) |
| 279 | |
| 280 | page := router.NewRoute().Subrouter() |
| 281 | page.Use(mux.MiddlewareFunc(csrfMiddleware)) |
| 282 | |
| 283 | // The logout route is currently in use by existing OAuth clients. As part of |
| 284 | // the public API it should not be removed in this major. |
| 285 | page.Path("/logout").HandlerFunc(s.ClientLogout).Methods(http.MethodGet) |
| 286 | |
| 287 | authorizeHandler := s.redirectToLogin(s.Authorize(webui.Template)) |
| 288 | page.Path("/authorize").Handler(authorizeHandler).Methods(http.MethodGet, http.MethodPost) |
| 289 | |
| 290 | router.Path("/local-callback").HandlerFunc(s.redirectToLocal).Methods(http.MethodGet) |
| 291 | |
| 292 | // No CSRF here: |
| 293 | router.Path("/token").HandlerFunc(s.Token).Methods(http.MethodPost) |
| 294 | } |
nothing calls this directly
no test coverage detected