MCPcopy
hub / github.com/cloudflare/cloudflared / ValidateAccessTokenQueryMiddleware

Function ValidateAccessTokenQueryMiddleware

management/middleware.go:18–34  ·  view source on GitHub ↗

HTTP middleware setting the parsed access_token claims in the request context

(next http.Handler)

Source from the content-addressed store, hash-verified

16
17// HTTP middleware setting the parsed access_token claims in the request context
18func ValidateAccessTokenQueryMiddleware(next http.Handler) http.Handler {
19 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
20 // Validate access token
21 accessToken := r.URL.Query().Get("access_token")
22 if accessToken == "" {
23 writeHTTPErrorResponse(w, errMissingAccessToken)
24 return
25 }
26 token, err := ParseToken(accessToken)
27 if err != nil {
28 writeHTTPErrorResponse(w, errMissingAccessToken)
29 return
30 }
31 r = r.WithContext(context.WithValue(r.Context(), accessClaimsCtxKey, token))
32 next.ServeHTTP(w, r)
33 })
34}
35
36// Middleware validation error struct for returning to the eyeball
37type managementError struct {

Callers

nothing calls this directly

Calls 5

writeHTTPErrorResponseFunction · 0.85
GetMethod · 0.80
ParseTokenFunction · 0.70
ContextMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected