git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #30 from sonatype/master

Add /ping endpoint

commitcfad6acf8f4c664303dab3f6b04f973242626879 authorJehiah Czebotar <jehiah@gmail.com> dateFri 17 Oct 2014, 04:00 (12 years ago) parent1c0989f1e29aa1
2 files changed+12
README.md+1 oauthproxy.go+11
README.md+1
@@ -110,6 +110,7 @@ The environment variables `google_auth_client_id`, `google_auth_secret` and `goo
110110
111111Google auth proxy responds directly to the following endpoints. All other endpoints will be authenticated.
112112
113+* /ping - returns an 200 OK response
113114* /oauth2/sign_in - the login page, which also doubles as a sign out page (it clears cookies)
114115* /oauth2/start - a URL that will redirect to start the oauth cycle
115116* /oauth2/callback - the URL used at the end of the oauth cycle
oauthproxy.go+11
@@ -16,6 +16,7 @@ import (
1616 "github.com/bitly/go-simplejson"
1717)
1818
19+const pingPath = "/ping"
1920const signInPath = "/oauth2/sign_in"
2021const oauthStartPath = "/oauth2/start"
2122const oauthCallbackPath = "/oauth2/callback"
@@ -192,6 +193,11 @@ func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val st
192193 http.SetCookie(rw, cookie)
193194}
194195
196+func (p *OauthProxy) PingPage(rw http.ResponseWriter) {
197+ rw.WriteHeader(http.StatusOK)
198+ fmt.Fprintf(rw, "OK")
199+}
200+
195201func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
196202 log.Printf("ErrorPage %d %s %s", code, title, message)
197203 rw.WriteHeader(code)
@@ -267,6 +273,11 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
267273 var ok bool
268274 var user string
269275
276+ if req.URL.Path == pingPath {
277+ p.PingPage(rw)
278+ return
279+ }
280+
270281 if req.URL.Path == signInPath {
271282 redirect, err := p.GetRedirect(req)
272283 if err != nil {