MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / Validate

Method Validate

auth/hmac.go:103–137  ·  view source on GitHub ↗
(ctx context.Context, wr http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

101}
102
103func (auth *HMACAuth) Validate(ctx context.Context, wr http.ResponseWriter, req *http.Request) (string, bool) {
104 hdr := req.Header.Get("Proxy-Authorization")
105 if hdr == "" {
106 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
107 }
108 hdr_parts := strings.SplitN(hdr, " ", 2)
109 if len(hdr_parts) != 2 || strings.ToLower(hdr_parts[0]) != "basic" {
110 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
111 }
112
113 token := hdr_parts[1]
114 data, err := base64.StdEncoding.DecodeString(token)
115 if err != nil {
116 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
117 }
118
119 pair := strings.SplitN(string(data), ":", 2)
120 if len(pair) != 2 {
121 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
122 }
123
124 login := pair[0]
125 password := pair[1]
126
127 if VerifyHMACLoginAndPassword(auth.secret, login, password) {
128 if auth.hiddenDomain != "" &&
129 (matchHiddenDomain(req.Host, auth.hiddenDomain) || matchHiddenDomain(req.URL.Host, auth.hiddenDomain)) {
130 sendAuthTriggeredMsg(wr)
131 return "", false
132 } else {
133 return login, true
134 }
135 }
136 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
137}
138
139func (auth *HMACAuth) Close() error {
140 var err error

Callers

nothing calls this directly

Calls 5

requireBasicAuthFunction · 0.85
matchHiddenDomainFunction · 0.85
sendAuthTriggeredMsgFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected