Documentation
¶
Index ¶
- Variables
- type AccessCheck
- type AccessResult
- type AuthError
- type AuthzError
- type Client
- func (c *Client) BatchCheck(ctx context.Context, reqs []AccessCheck) ([]AccessResult, error)
- func (c *Client) Can(ctx context.Context, action, resourceID string, scope ...string) (bool, error)
- func (c *Client) CheckAccess(ctx context.Context, action, resourceID string, scope ...string) (bool, string, error)
- func (c *Client) CheckAccessAs(ctx context.Context, subjectID, action, resourceID string, scope ...string) (bool, string, error)
- func (c *Client) Login(ctx context.Context, email, password string) (LoginResult, error)
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Refresh(ctx context.Context) error
- func (c *Client) VerifyMfa(ctx context.Context, mfaToken Sensitive, code string) (LoginResult, error)
- type JWKSVerifier
- type LoginResult
- type NetworkError
- type Option
- type Sensitive
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuth = errors.New("axiam: authentication error") ErrAuthz = errors.New("axiam: authorization error") ErrNetwork = errors.New("axiam: network error") )
Sentinel errors for errors.Is-based discrimination convenience (CONTRACT.md §2, D-04). These are never returned directly — only *AuthError/*AuthzError/*NetworkError instances are, each of which implements Is(target) to match the corresponding sentinel.
Functions ¶
This section is empty.
Types ¶
type AccessCheck ¶
type AccessCheck struct {
Action string `json:"action"`
ResourceID string `json:"resource_id"`
Scope string `json:"scope,omitempty"`
// SubjectID is optional and, when set, asks the server to evaluate the
// check for this subject rather than the caller's own session
// (CONTRACT.md §11.2 — declarative authorization helpers pass the
// request's authenticated user_id here so the check runs for the end
// user, not the application's own service-account session). Omitted
// from the wire payload when empty, preserving today's request shape
// for CheckAccess/Can/BatchCheck callers that never set it.
SubjectID string `json:"subject_id,omitempty"`
}
AccessCheck is a single access check request (CONTRACT.md §1). ResourceID is a string (server-side UUID) rather than a typed UUID so callers can pass either a UUID string or, in future, other resource-id encodings without a breaking type change; the server is the source of truth for validation.
type AccessResult ¶
AccessResult is the outcome of a single access check (mirrors CheckAccessResponse).
type AuthError ¶
type AuthError struct {
Message string
}
AuthError represents an authentication failure: wrong credentials, expired session, MFA failure, or a 401 on refresh (CONTRACT.md §2).
type AuthzError ¶
AuthzError represents an authorization failure: the caller is authenticated but lacks permission for the requested operation (CONTRACT.md §2). Action/ResourceID are optional and populated when known from the response body.
func (*AuthzError) Error ¶
func (e *AuthzError) Error() string
func (*AuthzError) Is ¶
func (e *AuthzError) Is(target error) bool
Is reports whether target is the ErrAuthz sentinel, enabling errors.Is(err, ErrAuthz) to match any *AuthzError.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the AXIAM SDK's REST entry point (CONTRACT.md §1-§10). See NewClient.
func NewClient ¶
NewClient constructs a Client. baseURL and tenantSlug are positional and required (D-03): an empty tenantSlug returns an *AuthError — AXIAM is multi-tenant and there is no default tenant, so this can never be a silent default (CONTRACT.md §5, SC#1).
The returned Client always owns a per-instance cookiejar and a TLS-1.3-minimum transport; WithHTTPClient may override the Transport/timeout, but the SDK re-applies its own jar and TLS config over any supplied client afterward (D-09) so neither can be silently dropped or bypassed.
func (*Client) BatchCheck ¶
func (c *Client) BatchCheck(ctx context.Context, reqs []AccessCheck) ([]AccessResult, error)
BatchCheck performs POST /api/v1/authz/check/batch (CONTRACT.md §1), evaluating an ordered list of checks; results are returned in the same order as reqs. Eligible for CF-01's bounded retry (read-only).
func (*Client) Can ¶
Can is an alias for CheckAccess targeting browser/UI scenarios (CONTRACT.md §1 note) — returns only the allowed boolean.
func (*Client) CheckAccess ¶
func (c *Client) CheckAccess(ctx context.Context, action, resourceID string, scope ...string) (bool, string, error)
CheckAccess performs POST /api/v1/authz/check (CONTRACT.md §1), evaluating a single authorization check for the given action/ resourceID/scope. This is a read-only, idempotent operation eligible for CF-01's bounded retry on transient NetworkError.
func (*Client) CheckAccessAs ¶
func (c *Client) CheckAccessAs(ctx context.Context, subjectID, action, resourceID string, scope ...string) (bool, string, error)
CheckAccessAs performs POST /api/v1/authz/check (CONTRACT.md §1) on behalf of subjectID rather than this Client's own session (CONTRACT.md §11.2). This is additive alongside CheckAccess — existing callers/signatures are unchanged — and exists specifically so declarative authorization helpers (middleware.RequireAccess) can evaluate the check for the request's authenticated user_id instead of the application's own (typically service-account) session. A blank subjectID behaves exactly like CheckAccess (the subject_id field is omitted from the wire request).
func (*Client) Login ¶
Login performs POST /api/v1/auth/login (CONTRACT.md §1). On success (no MFA), tokens are already present in the cookie jar and the org_id claim has been resolved+cached. When the server signals MFA is required, returns LoginResult{MFARequired: true, ...} — this is an expected outcome, not an error.
func (*Client) Logout ¶
Logout performs POST /api/v1/auth/logout (CONTRACT.md §1) and clears in-memory token state.
type JWKSVerifier ¶
JWKSVerifier is the public entry point for this SDK's local JWKS verification primitive (CONTRACT.md §10, D-06) — the shared local-verify mechanism consumed by the net/http middleware (package middleware). It is a thin re-export of the internal jwks.Verifier so callers outside this module never need to import an internal/ package directly.
IMPORTANT: JWKSVerifier.Verify validates the token SIGNATURE ONLY — it does NOT check expiry. Callers using this type directly (rather than via middleware.Middleware, which checks expiry for you) MUST compare the returned Claims.Exp against time.Now().Unix() before trusting the token (WR-03).
func NewJWKSVerifier ¶
NewJWKSVerifier constructs a JWKSVerifier bound to {baseURL}/oauth2/jwks (trailing slash on baseURL trimmed before joining). hc may be nil, in which case a default *http.Client is used. The cache is registered but not eagerly populated; the first Verify call triggers the initial fetch.
This is the exported constructor middleware.Middleware examples wire against — see examples/middleware-guard.
type LoginResult ¶
type LoginResult struct {
// MFARequired is true when the server responded with an MFA challenge
// instead of a completed session; call VerifyMfa next with MFAToken.
MFARequired bool
// MFAToken carries the opaque challenge token when MFARequired is
// true. Treated as sensitive (short-lived bearer of "logging in as
// this user").
MFAToken Sensitive
// AvailableMethods lists MFA methods available to satisfy the
// challenge (only populated when MFARequired is true).
AvailableMethods []string
// SessionID is the server-issued session id (only populated on a
// completed, non-MFA-pending login/verify_mfa).
SessionID string
// ExpiresIn is the access token lifetime in seconds, as reported by
// the server (only populated on a completed login/verify_mfa).
ExpiresIn uint64
}
LoginResult is the outcome of Login/VerifyMfa (CF-04). MFA required is an expected outcome, not an error: check MFARequired before assuming the session is established.
type NetworkError ¶
type NetworkError struct {
Message string
// contains filtered or unexported fields
}
NetworkError represents a transport-level failure: connection refused, timeout, TLS error, DNS failure, or a server-side 5xx (CONTRACT.md §2).
cause is unexported and MUST only ever be populated via newNetworkError, which redacts sensitive headers from any wrapped *http.Response BEFORE constructing the error (D-04, Phase 17 CR-04 carry-forward) — never construct a NetworkError directly from an unredacted *http.Response.
func (*NetworkError) Error ¶
func (e *NetworkError) Error() string
func (*NetworkError) Is ¶
func (e *NetworkError) Is(target error) bool
Is reports whether target is the ErrNetwork sentinel, enabling errors.Is(err, ErrNetwork) to match any *NetworkError.
func (*NetworkError) Unwrap ¶
func (e *NetworkError) Unwrap() error
Unwrap exposes the underlying (already-redacted) cause for errors.Is/As and errors.Unwrap chains.
type Option ¶
type Option func(*clientConfig)
Option configures a Client at construction time (D-03).
func WithCustomCA ¶
WithCustomCA adds a PEM-encoded CA certificate to the TLS verification chain (§6). This is the ONLY TLS-related escape hatch — there is no option anywhere in this SDK that disables or weakens certificate verification. Returns a construction-time error via NewClient if pem is not valid PEM.
func WithHTTPClient ¶
WithHTTPClient supplies a base *http.Client whose Transport/Timeout the SDK adopts. D-09: the SDK ALWAYS re-applies its own cookiejar and TLS config over the supplied client afterward — an override can never silently drop the jar (breaking every post-login request) or bypass TLS verification.
func WithLogger ¶
WithLogger supplies an injectable, redaction-aware logger (CF-02). OFF by default (nil logger — the SDK never logs unless a logger is supplied). The SDK never emits raw token values regardless of the logger's configured level (Sensitive redacts itself in any log call).
func WithOrgID ¶
WithOrgID sets the organization UUID the real login/refresh endpoints require (RESEARCH.md Pitfall 3). Mutually exclusive with WithOrgSlug — last call wins.
func WithOrgSlug ¶
WithOrgSlug sets the organization slug the real login/refresh endpoints require (RESEARCH.md Pitfall 3). Mutually exclusive with WithOrgID — last call wins.
func WithTimeout ¶
WithTimeout overrides the default request timeout applied to the SDK's http.Client (CF-03; default 30s).
type Sensitive ¶
type Sensitive string
Sensitive wraps a token-carrying string so it can never accidentally leak via fmt verbs, Go-syntax representation, or JSON encoding (CONTRACT.md §7, D-08). All token-carrying fields (access token, refresh token, MFA challenge token, AMQP signing key) MUST use this type.
The raw value is reachable only via the package-internal expose() accessor — Sensitive deliberately has no public getter.
func (Sensitive) Format ¶
Format implements fmt.Formatter, closing the fmt-verb leak path (%v/%+v/%s/%q/width/precision) that a bare String() method does not fully cover — this is the CR-04 leak class this type exists to prevent.
func (Sensitive) GoString ¶
GoString implements fmt.GoStringer, covering %#v (Go-syntax representation), which bypasses String()/Format() entirely if not implemented.
func (Sensitive) MarshalJSON ¶
MarshalJSON implements json.Marshaler so any struct embedding a Sensitive field serializes the redacted placeholder rather than the raw value.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package amqp implements the AXIAM AMQP event consumer: a closure-handler Consume loop that HMAC-SHA256-verifies every delivery BEFORE the caller's handler ever runs (CONTRACT.md §8, D-07, SC#4).
|
Package amqp implements the AXIAM AMQP event consumer: a closure-handler Consume loop that HMAC-SHA256-verifies every delivery BEFORE the caller's handler ever runs (CONTRACT.md §8, D-07, SC#4). |
|
examples
|
|
|
amqp-consumer
command
Command amqp-consumer demonstrates amqp.Consume with a closure handler that shows the full ack/nack matrix (CONTRACT.md §8, D-07).
|
Command amqp-consumer demonstrates amqp.Consume with a closure handler that shows the full ack/nack matrix (CONTRACT.md §8, D-07). |
|
authz-check
command
Command authz-check demonstrates the REST authorization surface: CheckAccess, Can (the browser/UI alias), and BatchCheck (CONTRACT.md §1).
|
Command authz-check demonstrates the REST authorization surface: CheckAccess, Can (the browser/UI alias), and BatchCheck (CONTRACT.md §1). |
|
grpc-checkaccess
command
Command grpc-checkaccess demonstrates the gRPC authorization transport: CheckAccess and BatchCheck over a lazily-connected *grpc.ClientConn (CONTRACT.md §1, §5, §9).
|
Command grpc-checkaccess demonstrates the gRPC authorization transport: CheckAccess and BatchCheck over a lazily-connected *grpc.ClientConn (CONTRACT.md §1, §5, §9). |
|
login-mfa
command
Command login-mfa demonstrates the two-phase Login/VerifyMfa flow (CONTRACT.md §1, §5).
|
Command login-mfa demonstrates the two-phase Login/VerifyMfa flow (CONTRACT.md §1, §5). |
|
middleware-guard
command
Command middleware-guard demonstrates wrapping a sample net/http route with middleware.Middleware (CONTRACT.md §10, SC#1), plus a second route additionally protected with middleware.RequireAccess (CONTRACT.md §11 declarative authorization helpers).
|
Command middleware-guard demonstrates wrapping a sample net/http route with middleware.Middleware (CONTRACT.md §10, SC#1), plus a second route additionally protected with middleware.RequireAccess (CONTRACT.md §11 declarative authorization helpers). |
|
Package grpc implements the gRPC transport for AuthorizationService (CheckAccess/BatchCheckAccess) with strict TLS and a sync-safe auth/tenant interceptor (CONTRACT.md §5/§6, SC#3).
|
Package grpc implements the gRPC transport for AuthorizationService (CheckAccess/BatchCheckAccess) with strict TLS and a sync-safe auth/tenant interceptor (CONTRACT.md §5/§6, SC#3). |
|
internal
|
|
|
jwks
Package jwks implements local JWKS fetch/cache/verification via lestrrat-go/jwx/v3 (D-06/§10), the shared local-verify primitive consumed by the net/http middleware (Plan 05) and any proactive-refresh check.
|
Package jwks implements local JWKS fetch/cache/verification via lestrrat-go/jwx/v3 (D-06/§10), the shared local-verify primitive consumed by the net/http middleware (Plan 05) and any proactive-refresh check. |
|
refreshguard
Package refreshguard implements the sync.Mutex single-flight refresh guard required by CONTRACT.md §9: exactly one in-flight POST /api/v1/auth/refresh call across any number of concurrent callers observing the same expired access token, with a double-check-after-lock pattern and no retry loop on failure (§9.3).
|
Package refreshguard implements the sync.Mutex single-flight refresh guard required by CONTRACT.md §9: exactly one in-flight POST /api/v1/auth/refresh call across any number of concurrent callers observing the same expired access token, with a double-check-after-lock pattern and no retry loop on failure (§9.3). |
|
Package middleware implements the net/http middleware / route-guard interface (CONTRACT.md §10, D-06).
|
Package middleware implements the net/http middleware / route-guard interface (CONTRACT.md §10, D-06). |