MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / requirePrincipal

Method requirePrincipal

internal/httpapi/httpapi.go:415–430  ·  view source on GitHub ↗

requirePrincipal authenticates the caller and returns the full principal (user + scope + bound agent), or a 401 envelope. The scope-aware basis for the hard scope ceiling (requireAccountScope / requireAgentAccess).

(ctx context.Context)

Source from the content-addressed store, hash-verified

413// (user + scope + bound agent), or a 401 envelope. The scope-aware basis for
414// the hard scope ceiling (requireAccountScope / requireAgentAccess).
415func (s *Server) requirePrincipal(ctx context.Context) (*identity.Principal, error) {
416 // The rate-limit middleware may have already authenticated this request
417 // on the read path; reuse that principal instead of hitting auth twice.
418 if p := principalFromContext(ctx); p != nil {
419 return p, nil
420 }
421 r := RequestFromContext(ctx)
422 if r == nil {
423 return nil, NewError(http.StatusInternalServerError, "internal_error", "authentication unavailable")
424 }
425 p, err := s.resolvePrincipal(r)
426 if err != nil {
427 return nil, NewError(http.StatusUnauthorized, "unauthorized", "authentication required")
428 }
429 return p, nil
430}
431
432// resolvePrincipal runs the injected auth path. It prefers the scope-aware
433// PrincipalAuthenticator; if only the legacy Authenticator is wired it treats

Callers 5

handleGetMyLimitsMethod · 0.95
requireUserMethod · 0.95
resolveOwnedAgentMethod · 0.95
requireAccountScopeMethod · 0.95
requireAgentAccessMethod · 0.95

Calls 4

resolvePrincipalMethod · 0.95
principalFromContextFunction · 0.85
RequestFromContextFunction · 0.85
NewErrorFunction · 0.85

Tested by

no test coverage detected