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

Method Validate

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

Source from the content-addressed store, hash-verified

129}
130
131func (auth *BasicAuth) Validate(ctx context.Context, wr http.ResponseWriter, req *http.Request) (string, bool) {
132 hdr := req.Header.Get("Proxy-Authorization")
133 if hdr == "" {
134 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
135 }
136 hdr_parts := strings.SplitN(hdr, " ", 2)
137 if len(hdr_parts) != 2 || strings.ToLower(hdr_parts[0]) != "basic" {
138 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
139 }
140
141 token := hdr_parts[1]
142 data, err := base64.StdEncoding.DecodeString(token)
143 if err != nil {
144 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
145 }
146
147 pair := strings.SplitN(string(data), ":", 2)
148 if len(pair) != 2 {
149 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
150 }
151
152 login := pair[0]
153 password := pair[1]
154
155 pwFile := auth.pw.Load().file
156
157 if pwFile.Match(login, password) {
158 if auth.hiddenDomain != "" &&
159 (matchHiddenDomain(req.Host, auth.hiddenDomain) || matchHiddenDomain(req.URL.Host, auth.hiddenDomain)) {
160 sendAuthTriggeredMsg(wr)
161 return "", false
162 } else {
163 return login, true
164 }
165 }
166 return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next)
167}
168
169func (auth *BasicAuth) Close() error {
170 var err error

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected