@@ -33,6 +33,7 @@ type OAuthProxy struct {
3333 SignInPath string
3434 OAuthStartPath string
3535 OAuthCallbackPath string
36+ AuthOnlyPath string
3637
3738 redirectURL *url.URL // the url to receive requests at
3839 provider providers.Provider
@@ -156,6 +157,7 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
156157 SignInPath: fmt.Sprintf("%s/sign_in", opts.ProxyPrefix),
157158 OAuthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
158159 OAuthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
160+ AuthOnlyPath: fmt.Sprintf("%s/auth", opts.ProxyPrefix),
159161
160162 ProxyPrefix: opts.ProxyPrefix,
161163 provider: opts.provider,
@@ -390,6 +392,8 @@ func (p *OAuthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
390392 p.OAuthStart(rw, req)
391393 case path == p.OAuthCallbackPath:
392394 p.OAuthCallback(rw, req)
395+ case path == p.AuthOnlyPath:
396+ p.AuthenticateOnly(rw, req)
393397 default:
394398 p.Proxy(rw, req)
395399 }
@@ -465,7 +469,28 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
465469 }
466470}
467471
472+func (p *OAuthProxy) AuthenticateOnly(rw http.ResponseWriter, req *http.Request) {
473+ status := p.Authenticate(rw, req)
474+ if status == http.StatusAccepted {
475+ rw.WriteHeader(http.StatusAccepted)
476+ } else {
477+ http.Error(rw, "unauthorized request", http.StatusUnauthorized)
478+ }
479+}
480+
468481func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
482+ status := p.Authenticate(rw, req)
483+ if status == http.StatusInternalServerError {
484+ p.ErrorPage(rw, http.StatusInternalServerError,
485+ "Internal Error", "Internal Error")
486+ } else if status == http.StatusForbidden {
487+ p.SignInPage(rw, req, http.StatusForbidden)
488+ } else {
489+ p.serveMux.ServeHTTP(rw, req)
490+ }
491+}
492+
493+func (p *OAuthProxy) Authenticate(rw http.ResponseWriter, req *http.Request) int {
469494 var saveSession, clearSession, revalidated bool
470495 remoteAddr := getRemoteAddr(req)
471496
@@ -514,8 +539,7 @@ func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
514539 err := p.SaveSession(rw, req, session)
515540 if err != nil {
516541 log.Printf("%s %s", remoteAddr, err)
517− p.ErrorPage(rw, 500, "Internal Error", "Internal Error")
518− return
542+ return http.StatusInternalServerError
519543 }
520544 }
521545
@@ -531,8 +555,7 @@ func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
531555 }
532556
533557 if session == nil {
534− p.SignInPage(rw, req, 403)
535− return
558+ return http.StatusForbidden
536559 }
537560
538561 // At this point, the user is authenticated. proxy normally
@@ -551,8 +574,7 @@ func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
551574 } else {
552575 rw.Header().Set("GAP-Auth", session.Email)
553576 }
554−
555− p.serveMux.ServeHTTP(rw, req)
577+ return http.StatusAccepted
556578}
557579
558580func (p *OAuthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {