MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / RegisterRoutes

Method RegisterRoutes

pkg/oauth/server.go:242–294  ·  view source on GitHub ↗
(server *web.Server)

Source from the content-addressed store, hash-verified

240}
241
242func (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}

Callers

nothing calls this directly

Calls 15

configFromContextMethod · 0.95
redirectToLoginMethod · 0.95
AuthorizeMethod · 0.95
WithNonceFunction · 0.92
HTTPMiddlewareFunction · 0.92
WithTemplateDataFunction · 0.92
WithAppConfigFunction · 0.92
WithErrorHandlersFunction · 0.92
CSRFFunction · 0.92
PrefixWithRedirectMethod · 0.80
HeaderMethod · 0.80
HandlerMethod · 0.80

Tested by

no test coverage detected