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)
| 413 | // (user + scope + bound agent), or a 401 envelope. The scope-aware basis for |
| 414 | // the hard scope ceiling (requireAccountScope / requireAgentAccess). |
| 415 | func (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 |
no test coverage detected