MCPcopy Create free account
hub / github.com/SpectoLabs/hoverfly / RequireTokenAuthentication

Method RequireTokenAuthentication

core/handlers/auth_handler.go:47–64  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)

Source from the content-addressed store, hash-verified

45}
46
47func (a *AuthHandler) RequireTokenAuthentication(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
48 // if auth is disabled - do not check token
49 if !a.Enabled {
50 next(w, req)
51 return
52 }
53
54 if authorizationValue := req.Header.Get("Authorization"); authorizationValue != "" {
55 // Should be a bearer token
56 if len(authorizationValue) > 6 && strings.ToUpper(authorizationValue[0:7]) == "BEARER " {
57 if authentication.IsJwtTokenValid(authorizationValue[7:], a.AB, a.SecretKey, a.JWTExpirationDelta) {
58 next(w, req)
59 }
60 }
61 }
62
63 WriteErrorResponse(w, "", http.StatusUnauthorized)
64}
65
66type AllUsersResponse struct {
67 Users []backends.User `json:"users"`

Callers

nothing calls this directly

Calls 3

IsJwtTokenValidFunction · 0.92
WriteErrorResponseFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected