HTTP middleware setting the parsed access_token claims in the request context
(next http.Handler)
| 16 | |
| 17 | // HTTP middleware setting the parsed access_token claims in the request context |
| 18 | func 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 |
| 37 | type managementError struct { |
nothing calls this directly
no test coverage detected