MCPcopy Create free account
hub / github.com/chain/Core / Authenticate

Method Authenticate

net/http/authn/authn.go:50–80  ·  view source on GitHub ↗

Authenticate returns the request, with added tokens and/or localhost flags in the context, as appropriate.

(req *http.Request)

Source from the content-addressed store, hash-verified

48// Authenticate returns the request, with added tokens and/or localhost
49// flags in the context, as appropriate.
50func (a *API) Authenticate(req *http.Request) (*http.Request, error) {
51 ctx := certAuthn(req, a.rootCAs)
52
53 token, err := a.tokenAuthn(req)
54 if err == nil && token != "" {
55 // if this request was successfully authenticated with a token, pass the token along
56 ctx = newContextWithToken(ctx, token)
57 }
58
59 local := a.localhostAuthn(req)
60 if local {
61 ctx = newContextWithLocalhost(ctx)
62 }
63
64 // Temporary workaround. Dashboard is always ok.
65 // See loopbackOn comment above.
66 if strings.HasPrefix(req.URL.Path, "/dashboard/") || req.URL.Path == "/dashboard" {
67 return req.WithContext(ctx), nil
68 }
69 if loopbackOn && local {
70 return req.WithContext(ctx), nil
71 }
72
73 // if there is no authentication at all, we return an "unauthenticated" error,
74 // which may be helpful when debugging
75 if len(X509Certs(ctx)) < 1 && err != nil {
76 return req, errors.New("unauthenticated")
77 }
78
79 return req.WithContext(ctx), nil
80}
81
82// checks the request for a valid client cert list.
83// If found, it is added to the request's context.

Callers 1

AuthHandlerFunction · 0.95

Calls 6

tokenAuthnMethod · 0.95
localhostAuthnMethod · 0.95
certAuthnFunction · 0.85
newContextWithTokenFunction · 0.85
newContextWithLocalhostFunction · 0.85
X509CertsFunction · 0.85

Tested by

no test coverage detected