{"modulePath":"github.com/GoCodeAlone/workflow-plugin-auth","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package agentidentity\n\nPackage agentidentity implements opt-in, tenant-scoped service grants. Hosts supply durable adapters and Workflow's managed issuer; no human sessions or issuer/private keys are created by this package.\n\n## Constants\n\n```go\nconst (\n\tPagesRead            = \"admin:multisite.pages:read\"\n\tHistoryRead          = \"admin:multisite.pages:history:read\"\n\tPagesUpdate          = \"admin:multisite.pages:update\"\n\tPreviewRead          = \"admin:multisite.preview:read\"\n\tMaxGrantLifetime     = 30 * 24 * time.Hour\n\tMaxTokenLifetime     = 15 * time.Minute\n\tMaxAssertionLifetime = time.Minute\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrDenied      = errors.New(\"agent access denied\")\n\tErrUnavailable = errors.New(\"agent access unavailable\")\n\tErrConflict    = errors.New(\"agent grant conflict\")\n)\n```\n\n## Functions\n\n```go\nfunc ValidateGrantForStorage(g Grant) error\n```\nValidateGrantForStorage checks the structural grant and resource bounds. It permits expired or revoked rows so durable adapters can load historical state; it does not authorize access, apply the host policy, or approve a new grant. Create adapters must additionally require Version 1 and !Revoked.\n\n## Types\n\n```go\ntype AssertionUse struct {\n\tGrantID      string\n\tGrantVersion int64\n\tJTIHash      string\n\tExpiresAt    time.Time\n\tNow          time.Time\n}\n```\n\n```go\ntype Audit struct {\n\tAt           time.Time `json:\"at\"`\n\tOperation    string    `json:\"operation\"`\n\tDecision     string    `json:\"decision\"`\n\tReason       string    `json:\"reason\"`\n\tSubject      string    `json:\"subject,omitempty\"`\n\tGrantID      string    `json:\"grant_id,omitempty\"`\n\tGrantVersion int64     `json:\"grant_version,omitempty\"`\n\tTenantID     int64     `json:\"tenant_id,omitempty\"`\n\tOwnerID      string    `json:\"owner_id,omitempty\"`\n\tPageID       string    `json:\"page_id,omitempty\"`\n\tScope        string    `json:\"scope,omitempty\"`\n\tJTIHash      string    `json:\"jti_hash,omitempty\"`\n}\n```\nAudit contains fixed reason codes and verified metadata, never raw tokens, assertions, keys, headers, bodies, arbitrary error strings or human emails.\n\n```go\ntype Auditor interface {\n\tRecord(context.Context, Audit) error\n}\n```\n\n```go\ntype ExchangeRequest struct {\n\tGrantID   string\n\tAssertion string\n\tAudience  string\n\tScopes    []string\n}\n```\n\n```go\ntype Grant struct {\n\tID              string           `json:\"id\"`\n\tSubject         string           `json:\"subject\"`\n\tAssertionIssuer string           `json:\"assertion_issuer\"`\n\tKeyID           string           `json:\"key_id\"`\n\tPublicKey       *ecdsa.PublicKey `json:\"-\"`\n\tVersion         int64            `json:\"version\"`\n\tTenantID        int64            `json:\"tenant_id\"`\n\tApprovedBy      string           `json:\"approved_by\"`\n\tCreatedAt       time.Time        `json:\"created_at\"`\n\tExpiresAt       time.Time        `json:\"expires_at\"`\n\tRevoked         bool             `json:\"revoked\"`\n\tAPIAudience     string           `json:\"api_audience\"`\n\tScopes          []string         `json:\"scopes\"`\n\tUpdatePageIDs   []string         `json:\"update_page_ids,omitempty\"`\n\tPreview         *PreviewGrant    `json:\"preview,omitempty\"`\n}\n```\nGrant is a host-owned durable row. Rotation and any permission edit MUST increment Version atomically; revocation must not delete the audit record. The public assertion key is not issuer key material or a human credential.\n\n```go\ntype GrantManager interface {\n\tCreateGrant(context.Context, Grant) error\n\tRevokeGrant(context.Context, string, int64, string, time.Time) error\n\tListGrants(context.Context, Owner) ([]Grant, error)\n}\n```\n\n```go\ntype IssueRequest struct {\n\tSubject, Audience, GrantID string\n\tGrantVersion, TenantID     int64\n\tScopes                     []string\n\tIssuedAt, ExpiresAt        time.Time\n}\n```\n\n```go\ntype Issuer interface {\n\tIssueAgentToken(context.Context, IssueRequest) (string, error)\n}\n```\nIssuer is an adapter to Workflow M2M IssueManagedToken with managed-only issuance and an explicitly configured stable ES256 key. Hosts map this typed request; never implement this with a human cookie/HMAC or generic OAuth route.\n\n```go\ntype IssuerFunc func(context.Context, IssueRequest) (string, error)\n```\n\n```go\nfunc (f IssuerFunc) IssueAgentToken(ctx context.Context, r IssueRequest) (string, error)\n```\n\n```go\ntype ManagementOptions struct {\n\tPath        string\n\tOwnerOrigin string\n\tPagePath    string\n\tOwners      OwnerPolicy\n\t// Tenants supplies immutable owner-UI declarations when Policy is wrapped\n\t// by a host's current preview gate. It confers no authority: every visible\n\t// proposal must also pass the service's required Policy and OwnerPolicy.\n\t// If omitted, the UI uses Policy directly when it is a *TenantPolicy.\n\tTenants *TenantPolicy\n}\n```\n\n```go\ntype Options struct {\n\tIssuerURL     string\n\tTokenEndpoint string\n\tIssuerKeys    map[string]*ecdsa.PublicKey\n\tStore         Store\n\tIssuer        Issuer\n\tPolicy        Policy\n\tAudit         Auditor\n\t// Clock is for deterministic tests; production hosts normally omit it.\n\tClock func() time.Time\n}\n```\n\n```go\ntype Owner struct{ ID string }\n```\n\n```go\ntype OwnerPolicy interface {\n\tResolveOwner(*http.Request) (Owner, error)\n\tAuthorizeOwner(context.Context, Owner, string, Grant) error\n}\n```\nOwnerPolicy must resolve a verified HUMAN owner and explicitly authorize the proposed tenant/resource/field ceiling. Request JSON never supplies identity. A service principal must not be projected into this resolver.\n\n```go\ntype Policy interface {\n\tAllowGrant(context.Context, Grant) error\n\tAllowResource(context.Context, Grant, Resource) error\n}\n```\nPolicy is the consuming app's exact tenant/resource allowlist. It is required even for already persisted grants: the library does not know which tenant is live or which routes exist. It must reject live tenants and privileged routes for the preview assistant. An omitted policy never grants access.\n\n```go\ntype PreviewGrant struct {\n\tAudience string `json:\"audience\"`\n\tOrigin   string `json:\"origin\"`\n\t// Paths are exact canonical request targets, optionally including a finite\n\t// literal query. A bare path never grants its query variants.\n\tPaths []string `json:\"paths\"`\n}\n```\n\n```go\ntype Principal struct {\n\tSubject, GrantID, JTIHash string\n\tGrantVersion, TenantID    int64\n\tScopes                    []string\n}\n```\n\n```go\ntype Resource struct {\n\tTenantID                int64\n\tAudience, Scope, PageID string\n\tFields                  []string\n\tExpectedVersion         uint64\n\tRootPage                bool\n\tHasCanonicalBlocks      bool\n\tMethod, Origin, Path    string\n\t// Query is the raw canonical query of a preview request only. Path stays\n\t// the matched path; API/history query authorization remains host-owned.\n\tQuery string\n}\n```\nResource must be built from the matched route/current saved row by the host, never copied unverified from JSON or X-Tenant/actor headers. All writes are body\\_html-only root-page CAS; canonical blocks are refused.\n\n```go\ntype Service struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewService(o Options) (*Service, error)\n```\n\n```go\nfunc (s *Service) Authorize(ctx context.Context, raw string, r Resource) (Principal, error)\n```\n\n```go\nfunc (s *Service) Exchange(ctx context.Context, in ExchangeRequest) (TokenResponse, error)\n```\n\n```go\nfunc (s *Service) ExchangeHandler() http.Handler\n```\nExchangeHandler handles only the exact configured RFC7523 token endpoint. There is no client-secret, cookie, human-session or refresh-token fallback. The TLS/reverse-proxy gate is host-owned and MUST reject untrusted forwarding metadata. Do not mount Workflow's generic OAuth issuer beside this handler.\n\n```go\nfunc (s *Service) ManagementHandler(o ManagementOptions) (http.Handler, error)\n```\nManagementHandler owns reusable registration/list/revocation behavior. Mount only behind existing HUMAN owner authorization and CSRF protection. Its typed resolver/policy cannot be replaced with a service principal. Hosts are responsible for a durable transaction plus audit/outbox for management mutations; no rollback can safely erase an already applied revoke.\n\n```go\ntype Store interface {\n\tGetGrant(context.Context, string) (Grant, error)\n\tConsumeAssertion(context.Context, AssertionUse) (bool, error)\n\tIsTokenRevoked(context.Context, string) (bool, error)\n}\n```\nStore methods MUST use durable state. ConsumeAssertion atomically checks the current grant version, enabled/expiry state AND inserts its globally unique assertion identity hash (issuer/subject/key/JTI binding). Uniqueness MUST NOT be partitioned by grant/version: one assertion cannot be reused on another tenant grant or after a permission edit. Return false for replay or changed/ revoked grants. Create and Revoke must be transactional and never alter a human identity/factor/bootstrap record. No in-memory production fallback is supplied.\n\n```go\ntype TenantConfig struct {\n\tTenantID      int64         `json:\"tenant_id\"`\n\tAPIAudience   string        `json:\"api_audience\"`\n\tPagesPath     string        `json:\"pages_path\"`\n\tHistoryPath   string        `json:\"history_path\"`\n\tScopes        []string      `json:\"scopes\"`\n\tUpdatePageIDs []string      `json:\"update_page_ids\"`\n\tPreview       *PreviewGrant `json:\"preview,omitempty\"`\n}\n```\nTenantConfig is declarative per-preview configuration, independent of keys and grants. Adding a tenant requires a configuration entry and owner-approved grant, not a source fork, implicit enrollment or shared personal credential.\n\n```go\ntype TenantPolicy struct {\n\t// contains filtered or unexported fields\n}\n```\nTenantPolicy is an immutable allowlist of explicit preview tenants. Never include a live tenant in this configuration. It matches real host routes, field/page ceilings and protected preview origins; it confers no credential.\n\n```go\nfunc NewTenantPolicy(config []TenantConfig) (*TenantPolicy, error)\n```\n\n```go\nfunc (p *TenantPolicy) AllowGrant(_ context.Context, g Grant) error\n```\n\n```go\nfunc (p *TenantPolicy) AllowResource(ctx context.Context, g Grant, r Resource) error\n```\n\n```go\ntype TokenResponse struct {\n\tAccessToken string `json:\"access_token\"`\n\tTokenType   string `json:\"token_type\"`\n\tExpiresIn   int64  `json:\"expires_in\"`\n\tScope       string `json:\"scope\"`\n}\n```\n\n","path":"github.com/GoCodeAlone/workflow-plugin-auth/agentidentity","name":"agentidentity","synopsis":"Package agentidentity implements opt-in, tenant-scoped service grants.","isRedistributable":true}
