MCPcopy Create free account
hub / github.com/discourse/discourse-auth-proxy / checkAuthorizationHeader

Function checkAuthorizationHeader

main.go:100–129  ·  view source on GitHub ↗
(handler http.Handler, r *http.Request, w http.ResponseWriter)

Source from the content-addressed store, hash-verified

98}
99
100func checkAuthorizationHeader(handler http.Handler, r *http.Request, w http.ResponseWriter) bool {
101 if config.BasicAuth == "" {
102 return false
103 }
104
105 auth_header := r.Header.Get("Authorization")
106 if len(auth_header) < 6 {
107 return false
108 }
109
110 if auth_header[0:6] == "Basic " {
111 b_creds, _ := base64.StdEncoding.DecodeString(auth_header[6:])
112 creds := string(b_creds)
113 if creds == config.BasicAuth {
114 colon_idx := strings.Index(creds, ":")
115 if colon_idx == -1 {
116 return false
117 }
118 username := creds[0:colon_idx]
119 r.Header.Set(config.UsernameHeader, username)
120 r.Header.Del("Authorization")
121 handler.ServeHTTP(w, r)
122 return true
123 } else {
124 logger.Printf("rejected basic auth creds: authorization header: %s", auth_header)
125 }
126 }
127
128 return false
129}
130
131func allowedByWhiteList(c *Config, p string) bool {
132 if c.Whitelist == "" && c.WhitelistPrefix == "" {

Callers 1

authProxyHandlerFunction · 0.85

Calls 1

PrintfMethod · 0.80

Tested by

no test coverage detected