writeAuthError writes a 401 response with an RFC 6750 §3 WWW-Authenticate challenge. Every 401 on an endpoint that accepts Bearer auth MUST advertise the Bearer scheme so clients know how to retry (§3, first paragraph). When the failing credential WAS an OAuth bearer (sentinel err wrap or `ate2a_`
(w http.ResponseWriter, r *http.Request, err error)
| 829 | // metadata document lands, add `resource_metadata="<url>"` here so MCP |
| 830 | // clients can auto-discover the authorization server. |
| 831 | func (a *API) writeAuthError(w http.ResponseWriter, r *http.Request, err error) { |
| 832 | w.Header().Set("WWW-Authenticate", a.authChallenge(r, err)) |
| 833 | http.Error(w, "authentication required", http.StatusUnauthorized) |
| 834 | } |
| 835 | |
| 836 | // authChallenge builds the RFC 6750 §3 WWW-Authenticate value for a 401 on a |
| 837 | // Bearer-accepting endpoint, given the request and the auth error that caused |
no test coverage detected