MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / AuthOnly

Method AuthOnly

oauthproxy.go:1018–1037  ·  view source on GitHub ↗

AuthOnly checks whether the user is currently logged in (both authentication and optional authorization).

(rw http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

1016// AuthOnly checks whether the user is currently logged in (both authentication
1017// and optional authorization).
1018func (p *OAuthProxy) AuthOnly(rw http.ResponseWriter, req *http.Request) {
1019 session, err := p.getAuthenticatedSession(rw, req)
1020 if err != nil {
1021 http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
1022 return
1023 }
1024
1025 // Unauthorized cases need to return 403 to prevent infinite redirects with
1026 // subrequest architectures
1027 if !authOnlyAuthorize(req, session) {
1028 http.Error(rw, http.StatusText(http.StatusForbidden), http.StatusForbidden)
1029 return
1030 }
1031
1032 // we are authenticated
1033 p.addHeadersForProxying(rw, session)
1034 p.headersChain.Then(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
1035 rw.WriteHeader(http.StatusAccepted)
1036 })).ServeHTTP(rw, req)
1037}
1038
1039// Proxy proxies the user request if the user is authenticated else it prompts
1040// them to authenticate

Callers

nothing calls this directly

Calls 6

addHeadersForProxyingMethod · 0.95
authOnlyAuthorizeFunction · 0.85
WriteHeaderMethod · 0.80
ErrorMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected