MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / authChallenge

Function authChallenge

internal/httpapi/middleware.go:73–83  ·  view source on GitHub ↗

authChallenge injects the RFC 6750 §3 WWW-Authenticate header on any 401 response. Every 401 on this Bearer-accepting surface must advertise the scheme so clients know how to retry (and OAuth-bearer failures get the §3.1 error params so MCP clients can trigger the re-flow). The legacy mux set this a

(build func(r *http.Request) string)

Source from the content-addressed store, hash-verified

71// The challenge value comes from the injected builder (agent.API.
72// WWWAuthenticateChallenge), so both surfaces emit identical challenges.
73func authChallenge(build func(r *http.Request) string) func(http.Handler) http.Handler {
74 return func(next http.Handler) http.Handler {
75 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
76 if build == nil {
77 next.ServeHTTP(w, r)
78 return
79 }
80 next.ServeHTTP(&challengeWriter{ResponseWriter: w, r: r, build: build}, r)
81 })
82 }
83}
84
85// challengeWriter sets WWW-Authenticate just before the status line is written,
86// but only when that status is 401. Setting it in WriteHeader (and lazily on a

Callers 1

NewFunction · 0.85

Calls 1

ServeHTTPMethod · 0.45

Tested by

no test coverage detected