// Proxy authenticates a request, either proxying the request if it is authenticated,
// or starting the authenticate service for validation if not.
Proxy authenticates a request, either proxying the request if it is authenticated,
or starting the authenticate service for validation if not.
// Proxy authenticates a request either proxying the request if it is authenticated // or starting the authenticate service for validation if not .
func (p *Proxy) Proxy(w http.ResponseWriter, r *http.Request) {
	if !p.shouldSkipAuthentication(r) {
		err := p.Authenticate(w, r)
		if err != nil {
			switch err {
			case http.ErrNoCookie, sessions.ErrLifetimeExpired, sessions.ErrInvalidSession:
				log.FromRequest(r).Debug().Err(err).Msg("proxy: starting auth flow")
				p.OAuthStart(w, r)
				return
			default:
				log.FromRequest(r).Error().Err(err).Msg("proxy: unexpected error")
				httputil.ErrorResponse(w, r, "An unexpected error occurred", http.StatusInternalServerError)
				return
			}
		}
		session, err := p.sessionStore.LoadSession(r)
		if err != nil {
			p.sessionStore.ClearSession(w, r)
			return
		}
		authorized, err := p.AuthorizeClient.Authorize(r.Context(), r.Host, session)
		if !authorized || err != nil {
			log.FromRequest(r).Warn().Err(err).Msg("proxy: user unauthorized")
			httputil.ErrorResponse(w, r, "Access unauthorized", http.StatusForbidden)
			return
		}
	}
	route, ok := p.router(r)
	if !ok {
		httputil.ErrorResponse(w, r, "unknown route to proxy", http.StatusNotFound)
		return
	}
	route.ServeHTTP(w, r)
}
func ( p * Proxy ) Proxy ( w http . ResponseWriter , r * http . Request ) { if ! p . shouldSkipAuthentication ( r ) { err := p . Authenticate ( w , r ) if err != nil { switch err { case http . ErrNoCookie , sessions . ErrLifetimeExpired , sessions . ErrInvalidSession : log . FromRequest ( r ) . Debug ( ) . Err ( err ) . Msg ( " " ) p . OAuthStart ( w , r ) return default : log . FromRequest ( r ) . Error ( ) . Err ( err ) . Msg ( " " ) httputil . ErrorResponse ( w , r , " " , http . StatusInternalServerError ) return } } session , err := p . sessionStore . LoadSession ( r ) if err != nil { p . sessionStore . ClearSession ( w , r ) return } authorized , err := p . AuthorizeClient . Authorize ( r . Context ( ) , r . Host , session ) if ! authorized || err != nil { log . FromRequest ( r ) . Warn ( ) . Err ( err ) . Msg ( " " ) httputil . ErrorResponse ( w , r , " " , http . StatusForbidden ) return } } route , ok := p . router ( r ) if ! ok { httputil . ErrorResponse ( w , r , " " , http . StatusNotFound ) return } route . ServeHTTP ( w , r ) }
Proxy authenticates a request, either proxying the request if it is authenticated,
or starting the authenticate service for validation if not.
Proxy authenticates a request either proxying the request if it is authenticated or starting the authenticate service for validation if not .
// If the authenticate is not successful we proceed to start the OAuth Flow with // OAuthStart. If successful, we proceed to proxy to the configured upstream. // remove dupe session call // We have validated the users request and now proxy their request to the provided upstream.