(ctx context.Context, wr http.ResponseWriter, req *http.Request)
| 129 | } |
| 130 | |
| 131 | func (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 | |
| 169 | func (auth *BasicAuth) Close() error { |
| 170 | var err error |
nothing calls this directly
no test coverage detected