@@ -150,7 +150,7 @@ func (p *OauthProxy) getUserInfo(token string) (string, error) {
151func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
151func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
152 domain := strings.Split(req.Host, ":")[0]
152 domain := strings.Split(req.Host, ":")[0]
153− if *cookieDomain != "" {
153+ if *cookieDomain != "" && strings.HasSuffix(domain, *cookieDomain) {
154 domain = *cookieDomain
154 domain = *cookieDomain
156 cookie := &http.Cookie{
156 cookie := &http.Cookie{
@@ -165,9 +165,9 @@ func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
167func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) {
167func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) {
169 domain := strings.Split(req.Host, ":")[0] // strip the port (if any)
169 domain := strings.Split(req.Host, ":")[0] // strip the port (if any)
170− if *cookieDomain != "" {
170+ if *cookieDomain != "" && strings.HasSuffix(domain, *cookieDomain) {
171 domain = *cookieDomain
171 domain = *cookieDomain
173 cookie := &http.Cookie{
173 cookie := &http.Cookie{
@@ -182,7 +182,6 @@ func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val st
182 http.SetCookie(rw, cookie)
182 http.SetCookie(rw, cookie)
186func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
185func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
187 log.Printf("ErrorPage %d %s %s", code, title, message)
186 log.Printf("ErrorPage %d %s %s", code, title, message)
188 rw.WriteHeader(code)
187 rw.WriteHeader(code)
@@ -202,14 +201,52 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
202 p.ClearCookie(rw, req)
201 p.ClearCookie(rw, req)
203 rw.WriteHeader(code)
202 rw.WriteHeader(code)
204 templates := getTemplates()
203 templates := getTemplates()
206+ SignInMessage string
205− t := struct{ SignInMessage string }{SignInMessage: p.SignInMessage}
209+ SignInMessage: p.SignInMessage,
210+ Htpasswd: p.HtpasswdFile != nil,
206 templates.ExecuteTemplate(rw, "sign_in.html", t)
212 templates.ExecuteTemplate(rw, "sign_in.html", t)
215+func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool){
216+ if req.Method != "POST" || p.HtpasswdFile == nil{
219+ user := req.FormValue("username")
220+ passwd := req.FormValue("password")
225+ if p.HtpasswdFile.Validate(user, passwd) {
226+ log.Printf("authenticated %s via manual sign in", user)
209func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
232func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
210 // check if this is a redirect back at the end of oauth
233 // check if this is a redirect back at the end of oauth
234+ remoteIP := req.Header.Get("X-Real-IP")
236+ remoteIP = req.RemoteAddr
238+ log.Printf("%s %s %s", remoteIP, req.Method, req.URL.Path)
211 if req.URL.Path == signInPath {
242 if req.URL.Path == signInPath {
243+ user, ok = p.ManualSignIn(rw, req)
245+ p.SetCookie(rw, req, user)
246+ http.Redirect(rw, req, "/", 302)
212− p.SignInPage(rw, req, 200)
248+ p.SignInPage(rw, req, 200)
215 if req.URL.Path == oauthStartPath {
252 if req.URL.Path == oauthStartPath {
@@ -260,20 +297,22 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
263− cookie, err := req.Cookie(p.CookieKey)
301+ cookie, err := req.Cookie(p.CookieKey)
267− if err == nil {
302+ if err == nil {
268− email, ok = validateCookie(cookie, p.CookieSeed)
304+ email, ok = validateCookie(cookie, p.CookieSeed)
269− user = strings.Split(email, "@")[0]
305+ user = strings.Split(email, "@")[0]
273 user, ok = p.CheckBasicAuth(req)
310 user, ok = p.CheckBasicAuth(req)
311+ // if we want to promote basic auth requests to cookie'd requests, we could do that here
312+ // not sure that would be ideal in all circumstances though
274− if ok {
313+ // if ok {
275− p.SetCookie(rw, req, user)
314+ // p.SetCookie(rw, req, user)
@@ -308,6 +347,7 @@ func (p *OauthProxy) CheckBasicAuth(req *http.Request) (string, bool) {
308 return "", false
347 return "", false
310 if p.HtpasswdFile.Validate(pair[0], pair[1]) {
349 if p.HtpasswdFile.Validate(pair[0], pair[1]) {
350+ log.Printf("authenticated %s via basic auth", pair[0])
311 return pair[0], true
351 return pair[0], true
313 return "", false
353 return "", false