From 8702ad2e52824bc184df9f9f33da4a8c5d7fe628 Mon Sep 17 00:00:00 2001 From: Jason Swank Date: Tue, 14 Oct 2014 16:22:38 -0400 Subject: [PATCH 1/2] Add /ping endpoint --- README.md | 1 + oauthproxy.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 7d0be15..5cc19bb 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ The environment variables `google_auth_client_id`, `google_auth_secret` and `goo Google auth proxy responds directly to the following endpoints. All other endpoints will be authenticated. +* /ping - returns an 200 OK response * /oauth2/sign_in - the login page, which also doubles as a sign out page (it clears cookies) * /oauth2/start - a URL that will redirect to start the oauth cycle * /oauth2/callback - the URL used at the end of the oauth cycle diff --git a/oauthproxy.go b/oauthproxy.go index 64fa96d..a9a03d3 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -16,6 +16,7 @@ import ( "github.com/bitly/go-simplejson" ) +const pingPath = "/ping" const signInPath = "/oauth2/sign_in" const oauthStartPath = "/oauth2/start" const oauthCallbackPath = "/oauth2/callback" @@ -192,6 +193,11 @@ func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val st http.SetCookie(rw, cookie) } +func (p *OauthProxy) PingPage(rw http.ResponseWriter) { + rw.WriteHeader(http.StatusOK) + fmt.Fprintf(rw, "pong") +} + func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) { log.Printf("ErrorPage %d %s %s", code, title, message) rw.WriteHeader(code) @@ -267,6 +273,11 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { var ok bool var user string + if req.URL.Path == pingPath { + p.PingPage(rw) + return + } + if req.URL.Path == signInPath { redirect, err := p.GetRedirect(req) if err != nil { From 1e29aa1c122fe01bb9436d7ffa6bdd17d5fb8357 Mon Sep 17 00:00:00 2001 From: Jason Swank Date: Tue, 14 Oct 2014 17:05:59 -0400 Subject: [PATCH 2/2] Make /ping endpoint respond with "OK" --- oauthproxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauthproxy.go b/oauthproxy.go index a9a03d3..87a29b2 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -195,7 +195,7 @@ func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val st func (p *OauthProxy) PingPage(rw http.ResponseWriter) { rw.WriteHeader(http.StatusOK) - fmt.Fprintf(rw, "pong") + fmt.Fprintf(rw, "OK") } func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {