git.iko.soy/typeable/oauth2-proxy
on master help sign in
[signout] Implement logout endpoint
commit562cc2e466415c0de133417550a55ea9b9cdf16f authorGuillaume Bienkowski <guillaume.bienkowski@braincube.com> dateTue 21 Mar 2017, 17:39 (10 years ago) parent89ba1d8
1 file changed+9
oauthproxy.go+9
oauthproxy.go+9
@@ -47,6 +47,7 @@ type OAuthProxy struct {
4747 RobotsPath string
4848 PingPath string
4949 SignInPath string
50+ SignOutPath string
5051 OAuthStartPath string
5152 OAuthCallbackPath string
5253 AuthOnlyPath string
@@ -183,6 +184,7 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
183184 RobotsPath: "/robots.txt",
184185 PingPath: "/ping",
185186 SignInPath: fmt.Sprintf("%s/sign_in", opts.ProxyPrefix),
187+ SignOutPath: fmt.Sprintf("%s/sign_out", opts.ProxyPrefix),
186188 OAuthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
187189 OAuthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
188190 AuthOnlyPath: fmt.Sprintf("%s/auth", opts.ProxyPrefix),
@@ -420,6 +422,8 @@ func (p *OAuthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
420422 p.serveMux.ServeHTTP(rw, req)
421423 case path == p.SignInPath:
422424 p.SignIn(rw, req)
425+ case path == p.SignOutPath:
426+ p.SignOut(rw, req)
423427 case path == p.OAuthStartPath:
424428 p.OAuthStart(rw, req)
425429 case path == p.OAuthCallbackPath:
@@ -448,6 +452,11 @@ func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
448452 }
449453}
450454
455+func (p *OAuthProxy) SignOut(rw http.ResponseWriter, req *http.Request) {
456+ p.ClearCookie(rw, req)
457+ http.Redirect(rw, req, "/", 302)
458+}
459+
451460func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
452461 redirect, err := p.GetRedirect(req)
453462 if err != nil {