{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package lookup\n\nPackage lookup owns every database read and write the security package needs. pkg/security itself contains no SQL: it calls the store interfaces defined here.\n\nEach store has a procedure implementation (stored procedures, the Postgres default) and a direct implementation (tables through a dialect-driven query builder). Which one runs is decided per operation by Config.EffectiveMode.\n\n## Constants\n\n```go\nconst (\n\tDialectPostgres = \"postgres\"\n\tDialectSQLite   = \"sqlite\"\n\tDialectMySQL    = \"mysql\"\n\tDialectMSSQL    = \"mssql\"\n)\n```\nDialect names understood by Config.Dialect. The dialect package (step 2) owns the implementations; the names are defined here so Config can be validated without it.\n\n## Variables\n\n```go\nvar (\n\t// ErrRefreshInvalid: the refresh token is unknown, expired or revoked.\n\tErrRefreshInvalid = errors.New(\"invalid refresh token\")\n\t// ErrRefreshReused: a refresh token that was already rotated was presented again. The\n\t// store has revoked the whole token family.\n\tErrRefreshReused = errors.New(\"refresh token reuse detected\")\n\t// ErrDevicePending, ErrDeviceSlowDown, ErrDeviceDenied and ErrDeviceExpired are the RFC 8628\n\t// polling outcomes other than success.\n\tErrDevicePending  = errors.New(\"authorization pending\")\n\tErrDeviceSlowDown = errors.New(\"slow down\")\n\tErrDeviceDenied   = errors.New(\"access denied\")\n\tErrDeviceExpired  = errors.New(\"device code expired\")\n\t// ErrNotFound: the requested record does not exist or has expired.\n\tErrNotFound = errors.New(\"not found\")\n)\n```\nErrors returned by OAuthGrantStore. Callers compare with errors.Is.\n\n```go\nvar (\n\tErrUsernameExists = errors.New(\"username already exists\")\n\tErrEmailExists    = errors.New(\"email already exists\")\n)\n```\nRegistration conflicts reported by AuthStore.Register in direct mode.\n\n```go\nvar (\n\tUsersID               = col(EntityUsers, \"id\")\n\tUsersUsername         = col(EntityUsers, \"username\")\n\tUsersEmail            = col(EntityUsers, \"email\")\n\tUsersPassword         = col(EntityUsers, \"password\")\n\tUsersUserLevel        = col(EntityUsers, \"user_level\")\n\tUsersRoles            = col(EntityUsers, \"roles\")\n\tUsersIsActive         = col(EntityUsers, \"is_active\")\n\tUsersCreatedAt        = col(EntityUsers, \"created_at\")\n\tUsersUpdatedAt        = col(EntityUsers, \"updated_at\")\n\tUsersLastLoginAt      = col(EntityUsers, \"last_login_at\")\n\tUsersProgramUserID    = col(EntityUsers, \"program_user_id\")\n\tUsersProgramUserTable = col(EntityUsers, \"program_user_table\")\n\tUsersRemoteID         = col(EntityUsers, \"remote_id\")\n\tUsersAuthProvider     = col(EntityUsers, \"auth_provider\")\n\tUsersTOTPSecret       = col(EntityUsers, \"totp_secret\")\n\tUsersTOTPEnabled      = col(EntityUsers, \"totp_enabled\")\n\tUsersTOTPEnabledAt    = col(EntityUsers, \"totp_enabled_at\")\n\n\tSessionsID             = col(EntityUserSessions, \"id\")\n\tSessionsToken          = col(EntityUserSessions, \"session_token\")\n\tSessionsUserID         = col(EntityUserSessions, \"user_id\")\n\tSessionsExpiresAt      = col(EntityUserSessions, \"expires_at\")\n\tSessionsCreatedAt      = col(EntityUserSessions, \"created_at\")\n\tSessionsLastActivityAt = col(EntityUserSessions, \"last_activity_at\")\n\tSessionsIPAddress      = col(EntityUserSessions, \"ip_address\")\n\tSessionsUserAgent      = col(EntityUserSessions, \"user_agent\")\n\tSessionsAccessToken    = col(EntityUserSessions, \"access_token\")\n\tSessionsRefreshToken   = col(EntityUserSessions, \"refresh_token\")\n\tSessionsTokenType      = col(EntityUserSessions, \"token_type\")\n\tSessionsAuthProvider   = col(EntityUserSessions, \"auth_provider\")\n\n\tBlacklistID        = col(EntityTokenBlacklist, \"id\")\n\tBlacklistToken     = col(EntityTokenBlacklist, \"token\")\n\tBlacklistUserID    = col(EntityTokenBlacklist, \"user_id\")\n\tBlacklistExpiresAt = col(EntityTokenBlacklist, \"expires_at\")\n\tBlacklistCreatedAt = col(EntityTokenBlacklist, \"created_at\")\n\n\tBackupCodesID        = col(EntityUserTOTPBackupCodes, \"id\")\n\tBackupCodesUserID    = col(EntityUserTOTPBackupCodes, \"user_id\")\n\tBackupCodesCodeHash  = col(EntityUserTOTPBackupCodes, \"code_hash\")\n\tBackupCodesUsed      = col(EntityUserTOTPBackupCodes, \"used\")\n\tBackupCodesUsedAt    = col(EntityUserTOTPBackupCodes, \"used_at\")\n\tBackupCodesCreatedAt = col(EntityUserTOTPBackupCodes, \"created_at\")\n\n\tPasskeyID              = col(EntityUserPasskeyCredentials, \"id\")\n\tPasskeyUserID          = col(EntityUserPasskeyCredentials, \"user_id\")\n\tPasskeyCredentialID    = col(EntityUserPasskeyCredentials, \"credential_id\")\n\tPasskeyPublicKey       = col(EntityUserPasskeyCredentials, \"public_key\")\n\tPasskeyAttestationType = col(EntityUserPasskeyCredentials, \"attestation_type\")\n\tPasskeyAAGUID          = col(EntityUserPasskeyCredentials, \"aaguid\")\n\tPasskeySignCount       = col(EntityUserPasskeyCredentials, \"sign_count\")\n\tPasskeyCloneWarning    = col(EntityUserPasskeyCredentials, \"clone_warning\")\n\tPasskeyTransports      = col(EntityUserPasskeyCredentials, \"transports\")\n\tPasskeyBackupEligible  = col(EntityUserPasskeyCredentials, \"backup_eligible\")\n\tPasskeyBackupState     = col(EntityUserPasskeyCredentials, \"backup_state\")\n\tPasskeyName            = col(EntityUserPasskeyCredentials, \"name\")\n\tPasskeyCreatedAt       = col(EntityUserPasskeyCredentials, \"created_at\")\n\tPasskeyLastUsedAt      = col(EntityUserPasskeyCredentials, \"last_used_at\")\n\n\tResetsID        = col(EntityUserPasswordResets, \"id\")\n\tResetsUserID    = col(EntityUserPasswordResets, \"user_id\")\n\tResetsTokenHash = col(EntityUserPasswordResets, \"token_hash\")\n\tResetsExpiresAt = col(EntityUserPasswordResets, \"expires_at\")\n\tResetsCreatedAt = col(EntityUserPasswordResets, \"created_at\")\n\tResetsUsed      = col(EntityUserPasswordResets, \"used\")\n\tResetsUsedAt    = col(EntityUserPasswordResets, \"used_at\")\n\n\tOAuthClientsID                      = col(EntityOAuthClients, \"id\")\n\tOAuthClientsClientID                = col(EntityOAuthClients, \"client_id\")\n\tOAuthClientsRedirectURIs            = col(EntityOAuthClients, \"redirect_uris\")\n\tOAuthClientsClientName              = col(EntityOAuthClients, \"client_name\")\n\tOAuthClientsGrantTypes              = col(EntityOAuthClients, \"grant_types\")\n\tOAuthClientsAllowedScopes           = col(EntityOAuthClients, \"allowed_scopes\")\n\tOAuthClientsClientSecretHash        = col(EntityOAuthClients, \"client_secret_hash\")\n\tOAuthClientsTokenEndpointAuthMethod = col(EntityOAuthClients, \"token_endpoint_auth_method\")\n\tOAuthClientsIsActive                = col(EntityOAuthClients, \"is_active\")\n\tOAuthClientsMetadata                = col(EntityOAuthClients, \"metadata\")\n\tOAuthClientsCreatedAt               = col(EntityOAuthClients, \"created_at\")\n\n\tOAuthCodesID                  = col(EntityOAuthCodes, \"id\")\n\tOAuthCodesCode                = col(EntityOAuthCodes, \"code\")\n\tOAuthCodesClientID            = col(EntityOAuthCodes, \"client_id\")\n\tOAuthCodesRedirectURI         = col(EntityOAuthCodes, \"redirect_uri\")\n\tOAuthCodesClientState         = col(EntityOAuthCodes, \"client_state\")\n\tOAuthCodesCodeChallenge       = col(EntityOAuthCodes, \"code_challenge\")\n\tOAuthCodesCodeChallengeMethod = col(EntityOAuthCodes, \"code_challenge_method\")\n\tOAuthCodesSessionToken        = col(EntityOAuthCodes, \"session_token\")\n\tOAuthCodesRefreshToken        = col(EntityOAuthCodes, \"refresh_token\")\n\tOAuthCodesScopes              = col(EntityOAuthCodes, \"scopes\")\n\tOAuthCodesExpiresAt           = col(EntityOAuthCodes, \"expires_at\")\n\tOAuthCodesCreatedAt           = col(EntityOAuthCodes, \"created_at\")\n\tOAuthCodesExtra               = col(EntityOAuthCodes, \"extra\")\n\n\tOAuthConsentsID        = col(EntityOAuthConsents, \"id\")\n\tOAuthConsentsUserID    = col(EntityOAuthConsents, \"user_id\")\n\tOAuthConsentsClientID  = col(EntityOAuthConsents, \"client_id\")\n\tOAuthConsentsScopes    = col(EntityOAuthConsents, \"scopes\")\n\tOAuthConsentsCreatedAt = col(EntityOAuthConsents, \"created_at\")\n\tOAuthConsentsExpiresAt = col(EntityOAuthConsents, \"expires_at\")\n\n\tOAuthRefreshID           = col(EntityOAuthRefreshTokens, \"id\")\n\tOAuthRefreshTokenHash    = col(EntityOAuthRefreshTokens, \"token_hash\")\n\tOAuthRefreshFamilyID     = col(EntityOAuthRefreshTokens, \"family_id\")\n\tOAuthRefreshClientID     = col(EntityOAuthRefreshTokens, \"client_id\")\n\tOAuthRefreshUserID       = col(EntityOAuthRefreshTokens, \"user_id\")\n\tOAuthRefreshSessionToken = col(EntityOAuthRefreshTokens, \"session_token\")\n\tOAuthRefreshScopes       = col(EntityOAuthRefreshTokens, \"scopes\")\n\tOAuthRefreshExtra        = col(EntityOAuthRefreshTokens, \"extra\")\n\tOAuthRefreshCreatedAt    = col(EntityOAuthRefreshTokens, \"created_at\")\n\tOAuthRefreshExpiresAt    = col(EntityOAuthRefreshTokens, \"expires_at\")\n\tOAuthRefreshUsedAt       = col(EntityOAuthRefreshTokens, \"used_at\")\n\tOAuthRefreshRevokedAt    = col(EntityOAuthRefreshTokens, \"revoked_at\")\n\n\tOAuthDeviceID           = col(EntityOAuthDeviceCodes, \"id\")\n\tOAuthDeviceHash         = col(EntityOAuthDeviceCodes, \"device_hash\")\n\tOAuthDeviceUserCode     = col(EntityOAuthDeviceCodes, \"user_code\")\n\tOAuthDeviceClientID     = col(EntityOAuthDeviceCodes, \"client_id\")\n\tOAuthDeviceScopes       = col(EntityOAuthDeviceCodes, \"scopes\")\n\tOAuthDeviceStatus       = col(EntityOAuthDeviceCodes, \"status\")\n\tOAuthDeviceUserID       = col(EntityOAuthDeviceCodes, \"user_id\")\n\tOAuthDeviceSessionToken = col(EntityOAuthDeviceCodes, \"session_token\")\n\tOAuthDeviceInterval     = col(EntityOAuthDeviceCodes, \"poll_interval\")\n\tOAuthDeviceCreatedAt    = col(EntityOAuthDeviceCodes, \"created_at\")\n\tOAuthDeviceExpiresAt    = col(EntityOAuthDeviceCodes, \"expires_at\")\n\tOAuthDeviceLastPolledAt = col(EntityOAuthDeviceCodes, \"last_polled_at\")\n\n\tOAuthPARID         = col(EntityOAuthPARRequests, \"id\")\n\tOAuthPARRequestURI = col(EntityOAuthPARRequests, \"request_uri\")\n\tOAuthPARClientID   = col(EntityOAuthPARRequests, \"client_id\")\n\tOAuthPARParams     = col(EntityOAuthPARRequests, \"params\")\n\tOAuthPARCreatedAt  = col(EntityOAuthPARRequests, \"created_at\")\n\tOAuthPARExpiresAt  = col(EntityOAuthPARRequests, \"expires_at\")\n\n\tOAuthJTIID        = col(EntityOAuthJTI, \"id\")\n\tOAuthJTIKey       = col(EntityOAuthJTI, \"jti_key\")\n\tOAuthJTIExpiresAt = col(EntityOAuthJTI, \"expires_at\")\n\n\tKeysID         = col(EntityUserKeys, \"id\")\n\tKeysUserID     = col(EntityUserKeys, \"user_id\")\n\tKeysKeyType    = col(EntityUserKeys, \"key_type\")\n\tKeysKeyHash    = col(EntityUserKeys, \"key_hash\")\n\tKeysName       = col(EntityUserKeys, \"name\")\n\tKeysScopes     = col(EntityUserKeys, \"scopes\")\n\tKeysMeta       = col(EntityUserKeys, \"meta\")\n\tKeysExpiresAt  = col(EntityUserKeys, \"expires_at\")\n\tKeysCreatedAt  = col(EntityUserKeys, \"created_at\")\n\tKeysLastUsedAt = col(EntityUserKeys, \"last_used_at\")\n\tKeysIsActive   = col(EntityUserKeys, \"is_active\")\n\n\tGroupMembersGroupID = col(EntitySecGroupMembers, \"group_id\")\n\tGroupMembersUserID  = col(EntitySecGroupMembers, \"user_id\")\n\n\tColRulesID           = col(EntitySecColumnRules, \"id\")\n\tColRulesUserID       = col(EntitySecColumnRules, \"user_id\")\n\tColRulesGroupID      = col(EntitySecColumnRules, \"group_id\")\n\tColRulesSchemaName   = col(EntitySecColumnRules, \"schema_name\")\n\tColRulesTableName    = col(EntitySecColumnRules, \"table_name\")\n\tColRulesColumnPath   = col(EntitySecColumnRules, \"column_path\")\n\tColRulesAccessType   = col(EntitySecColumnRules, \"access_type\")\n\tColRulesMaskStart    = col(EntitySecColumnRules, \"mask_start\")\n\tColRulesMaskEnd      = col(EntitySecColumnRules, \"mask_end\")\n\tColRulesMaskInvert   = col(EntitySecColumnRules, \"mask_invert\")\n\tColRulesMaskChar     = col(EntitySecColumnRules, \"mask_char\")\n\tColRulesExtraFilters = col(EntitySecColumnRules, \"extra_filters\")\n\tColRulesIsActive     = col(EntitySecColumnRules, \"is_active\")\n\n\tRowRulesID         = col(EntitySecRowRules, \"id\")\n\tRowRulesUserID     = col(EntitySecRowRules, \"user_id\")\n\tRowRulesGroupID    = col(EntitySecRowRules, \"group_id\")\n\tRowRulesSchemaName = col(EntitySecRowRules, \"schema_name\")\n\tRowRulesTableName  = col(EntitySecRowRules, \"table_name\")\n\tRowRulesTemplate   = col(EntitySecRowRules, \"template\")\n\tRowRulesHasBlock   = col(EntitySecRowRules, \"has_block\")\n\tRowRulesIsActive   = col(EntitySecRowRules, \"is_active\")\n)\n```\nLogical columns. The names are the default physical column names.\n\n```go\nvar ErrInvalidAPIKey = errors.New(\"invalid api key\")\n```\nErrInvalidAPIKey is the single error LoginAPIKey returns for unknown, expired, inactive and wrong-type keys, so callers cannot tell them apart.\n\n## Functions\n\n```go\nfunc ApplyTxSettings(ctx context.Context, tx common.Database, settings map[string]string) error\n```\nApplyTxSettings sets each entry as a transaction-local setting on tx, in name order. Postgres only; any other driver with a non-empty map is an error so a missing RLS stamp fails closed.\n\n```go\nfunc FirstColumn(e Entity) string\n```\nFirstColumn returns the name of the first logical column of an entity (used by the direct backend for existence checks).\n\n```go\nfunc FromDatabase(db common.Database) (*sql.DB, string, error)\n```\nFromDatabase extracts the \\*sql.DB and the dialect name from an application's common.Database (bun, gorm or pgsql adapter), so callers do not have to dig the connection out or set Config.Dialect by hand. The returned name is the adapter's normalised DriverName (\"postgres\", \"sqlite\", \"mssql\", \"mysql\") and is empty when the adapter reports a driver the dialect registry does not know; set Config.Dialect explicitly in that case.\n\nTransaction adapters do not expose a \\*sql.DB and are rejected.\n\n## Types\n\n```go\ntype AuthStore interface {\n\tLogin(ctx context.Context, req sectypes.LoginRequest) (*sectypes.LoginResponse, error)\n\tRegister(ctx context.Context, req sectypes.RegisterRequest) (*sectypes.LoginResponse, error)\n\tLogout(ctx context.Context, req sectypes.LogoutRequest) error\n\t// Session resolves a session token to its user. reference says where the token came\n\t// from (\"authenticate\", \"cookie\", \"refresh\"); the procedure backend passes it through.\n\tSession(ctx context.Context, token, reference string) (*sectypes.UserContext, error)\n\t// TouchSession records last activity for a session token. user is the context the\n\t// session resolved to; the procedure backend passes it to the update procedure.\n\tTouchSession(ctx context.Context, token string, user *sectypes.UserContext) error\n\tRefresh(ctx context.Context, refreshToken string) (*sectypes.LoginResponse, error)\n\t// LoginAPIKey logs in with a raw header/generic API key. Unknown, expired, inactive and\n\t// wrong-type keys all return the same error.\n\tLoginAPIKey(ctx context.Context, rawKey string, claims map[string]any) (*sectypes.LoginResponse, error)\n\tJWTLogin(ctx context.Context, req sectypes.LoginRequest) (*sectypes.LoginResponse, error)\n\tJWTLogout(ctx context.Context, req sectypes.LogoutRequest) error\n\tResetRequest(ctx context.Context, req sectypes.PasswordResetRequest) (*sectypes.PasswordResetResponse, error)\n\tResetComplete(ctx context.Context, req sectypes.PasswordResetCompleteRequest) error\n}\n```\nAuthStore covers sessions, login, registration and password reset.\n\n```go\ntype Column struct {\n\tEntity Entity\n\tName   string\n}\n```\nColumn is a typed key naming one logical column of an entity. The physical column name is looked up in the Schema, so every column of every entity is configurable.\n\n```go\nfunc (c Column) String() string\n```\n\n```go\ntype Config struct {\n\t// Dialect names a registered dialect (\"postgres\", \"sqlite\", \"mysql\", \"mssql\", or one added\n\t// with dialect.Register). Empty = detect from the driver.\n\tDialect string\n\t// Mode is the default mode for every operation. See ModeDefault.\n\tMode Mode\n\t// Overrides sets the mode per operation, e.g. direct for OpSession, procedure for OpLogin.\n\tOverrides map[Op]Mode\n\t// Procs overrides procedure names; empty fields keep the default.\n\tProcs ProcNames\n\t// Schema overrides table and column names; missing entries keep the default.\n\tSchema Schema\n}\n```\nConfig selects dialect, mode and naming. The zero value is valid: dialect detected from the driver, default mode per dialect, default procedure/table/column names.\n\n```go\nfunc (c Config) EffectiveMode(op Op, dialect string) (Mode, error)\n```\nEffectiveMode resolves the mode for one operation: a per-operation override wins over Config.Mode, and ModeDefault is replaced by the dialect default. The result is ModeProcedure, ModeDirect or ModeAuto; ModeAuto only survives on Postgres, where the caller must probe the procedure. dialect is the resolved dialect name.\n\n```go\nfunc (c Config) Resolve() (*Resolved, error)\n```\nResolve merges c with the defaults and validates the result.\n\n```go\nfunc (c Config) ResolveDialect(db *sql.DB) (dialect.Dialect, error)\n```\nResolveDialect returns the dialect for db: the configured one, or detected from the driver.\n\n```go\ntype Consent struct {\n\tUserID    int       `json:\"user_id\"`\n\tClientID  string    `json:\"client_id\"`\n\tScopes    []string  `json:\"scopes\"`\n\tExpiresAt time.Time `json:\"expires_at\"`\n}\n```\nConsent records that a user allowed a client to act with Scopes.\n\n```go\ntype DeviceCode struct {\n\tDeviceHash   string       `json:\"device_hash\"`\n\tUserCode     string       `json:\"user_code\"`\n\tClientID     string       `json:\"client_id\"`\n\tScopes       []string     `json:\"scopes,omitempty\"`\n\tStatus       DeviceStatus `json:\"status\"`\n\tUserID       int          `json:\"user_id,omitempty\"`\n\tSessionToken string       `json:\"session_token,omitempty\"`\n\tInterval     int          `json:\"interval\"` // minimum seconds between polls\n\tExpiresAt    time.Time    `json:\"expires_at\"`\n}\n```\nDeviceCode is a pending RFC 8628 device authorization. DeviceHash is the SHA-256 hash of the device\\_code returned to the device; UserCode is stored as typed by the user (normalised).\n\n```go\ntype DeviceStatus string\n```\nDeviceStatus is the state of an RFC 8628 device authorization.\n\n```go\nconst (\n\tDevicePending  DeviceStatus = \"pending\"\n\tDeviceApproved DeviceStatus = \"approved\"\n\tDeviceDenied   DeviceStatus = \"denied\"\n)\n```\n\n```go\ntype Entity string\n```\nEntity identifies one table the direct backend reads or writes.\n\n```go\nconst (\n\tEntityUsers                  Entity = \"users\"\n\tEntityUserSessions           Entity = \"user_sessions\"\n\tEntityTokenBlacklist         Entity = \"token_blacklist\"\n\tEntityUserTOTPBackupCodes    Entity = \"user_totp_backup_codes\"\n\tEntityUserPasskeyCredentials Entity = \"user_passkey_credentials\" //nolint:gosec // table name, not a credential\n\tEntityUserPasswordResets     Entity = \"user_password_resets\"\n\tEntityOAuthClients           Entity = \"oauth_clients\"\n\tEntityOAuthCodes             Entity = \"oauth_codes\"\n\tEntityOAuthConsents          Entity = \"oauth_consents\"\n\tEntityOAuthRefreshTokens     Entity = \"oauth_refresh_tokens\" //nolint:gosec // table name, not a credential\n\tEntityOAuthDeviceCodes       Entity = \"oauth_device_codes\"\n\tEntityOAuthPARRequests       Entity = \"oauth_par_requests\"\n\tEntityOAuthJTI               Entity = \"oauth_jti\"\n\tEntityUserKeys               Entity = \"user_keys\"\n\tEntitySecGroupMembers        Entity = \"sec_group_members\"\n\tEntitySecColumnRules         Entity = \"sec_column_rules\"\n\tEntitySecRowRules            Entity = \"sec_row_rules\"\n)\n```\n\n```go\ntype KeyStore interface {\n\tCreate(ctx context.Context, req sectypes.CreateKeyRequest, keyHash string) (*sectypes.UserKey, error)\n\tList(ctx context.Context, userID int, keyType sectypes.KeyType) ([]sectypes.UserKey, error)\n\t// Delete soft-deletes a key after verifying ownership and returns its hash so callers can\n\t// invalidate caches. The hash is empty when the backend cannot report it.\n\tDelete(ctx context.Context, userID int, keyID int64) (keyHash string, err error)\n\tValidate(ctx context.Context, keyHash string, keyType sectypes.KeyType) (*sectypes.UserKey, error)\n}\n```\nKeyStore persists per-user auth keys. Hashing and raw-key generation happen in Go, so the store only sees key hashes.\n\n```go\ntype Mode string\n```\nMode selects how a store talks to the database.\n\n```go\nconst (\n\t// ModeDefault (the zero value) resolves to ModeProcedure on Postgres and ModeDirect elsewhere.\n\tModeDefault Mode = \"\"\n\t// ModeProcedure always calls the configured stored procedure; a missing procedure is an error.\n\tModeProcedure Mode = \"procedure\"\n\t// ModeDirect always works on the tables through the dialect builder.\n\tModeDirect Mode = \"direct\"\n\t// ModeAuto probes the procedure once per operation on Postgres (cached) and uses it when\n\t// present, otherwise direct. Other dialects resolve to ModeDirect.\n\tModeAuto Mode = \"auto\"\n)\n```\n\n```go\ntype OAuthClientStore interface {\n\tRegisterClient(ctx context.Context, client *sectypes.OAuthServerClient) (*sectypes.OAuthServerClient, error)\n\tGetClient(ctx context.Context, clientID string) (*sectypes.OAuthServerClient, error)\n\tSaveCode(ctx context.Context, code *sectypes.OAuthCode) error\n\t// ExchangeCode atomically consumes an authorization code.\n\tExchangeCode(ctx context.Context, code string) (*sectypes.OAuthCode, error)\n\tIntrospect(ctx context.Context, token string) (*sectypes.OAuthTokenInfo, error)\n\tRevoke(ctx context.Context, token string) error\n\t// UpdateClient rewrites the registration fields of an existing client (RFC 7592).\n\tUpdateClient(ctx context.Context, client *sectypes.OAuthServerClient) error\n\t// DeleteClient deactivates a client.\n\tDeleteClient(ctx context.Context, clientID string) error\n}\n```\nOAuthClientStore persists the OAuth2 authorization server state (RFC 7591 clients, authorization codes, token introspection and revocation).\n\n```go\ntype OAuthGrantStore interface {\n\t// SaveConsent replaces the consent of (UserID, ClientID).\n\tSaveConsent(ctx context.Context, c Consent) error\n\t// GetConsent returns the unexpired consent or ErrNotFound.\n\tGetConsent(ctx context.Context, userID int, clientID string) (*Consent, error)\n\tRevokeConsent(ctx context.Context, userID int, clientID string) error\n\n\tSaveRefresh(ctx context.Context, t RefreshToken) error\n\t// RotateRefresh atomically consumes the token with hash oldHash and stores next in the same\n\t// family. It returns the consumed token. An unknown, expired or revoked token is\n\t// ErrRefreshInvalid. A token that was already consumed revokes its family and returns the\n\t// token together with ErrRefreshReused so the caller can end the session.\n\tRotateRefresh(ctx context.Context, oldHash string, next RefreshToken) (*RefreshToken, error)\n\t// PeekRefresh returns the token without consuming it. Unknown, expired and revoked tokens are\n\t// ErrRefreshInvalid; an already rotated token is returned so RotateRefresh can report its reuse.\n\tPeekRefresh(ctx context.Context, hash string) (*RefreshToken, error)\n\tRevokeRefreshFamily(ctx context.Context, familyID string) error\n\t// RevokeRefreshBySession revokes every refresh token bound to a session token.\n\tRevokeRefreshBySession(ctx context.Context, sessionToken string) error\n\n\tCreateDevice(ctx context.Context, d DeviceCode) error\n\t// DeviceByUserCode returns the unexpired pending device authorization or ErrNotFound.\n\tDeviceByUserCode(ctx context.Context, userCode string) (*DeviceCode, error)\n\t// DeviceDecide approves or denies the device authorization of userCode.\n\tDeviceDecide(ctx context.Context, userCode string, approve bool, userID int, sessionToken string) error\n\t// DevicePoll implements the token endpoint side: it enforces the poll interval and returns\n\t// one of ErrDevicePending, ErrDeviceSlowDown, ErrDeviceDenied, ErrDeviceExpired or, once\n\t// approved, the record (consumed: it cannot be polled again).\n\tDevicePoll(ctx context.Context, deviceHash string) (*DeviceCode, error)\n\n\tSavePushedRequest(ctx context.Context, r PushedRequest) error\n\t// ConsumePushedRequest returns and deletes the request or ErrNotFound.\n\tConsumePushedRequest(ctx context.Context, requestURI string) (*PushedRequest, error)\n\n\t// SeenJTI records key until expires and reports whether it was already recorded. It is the\n\t// replay cache for DPoP proofs and client assertions.\n\tSeenJTI(ctx context.Context, key string, expires time.Time) (bool, error)\n}\n```\nOAuthGrantStore persists the OAuth2 authorization server state that is not a client, a code or a session: consents, refresh tokens, device codes, pushed requests and the replay cache.\n\n```go\ntype OAuthRefreshSession struct {\n\tUserID      int       `json:\"user_id\"`\n\tAccessToken string    `json:\"access_token\"`\n\tTokenType   string    `json:\"token_type\"`\n\tExpiry      time.Time `json:\"expiry\"`\n}\n```\nOAuthRefreshSession is the stored token state needed to refresh an OAuth2 login.\n\n```go\ntype OAuthSession struct {\n\tSessionToken string\n\tUserID       int\n\tAccessToken  string\n\tRefreshToken string\n\tTokenType    string\n\tExpiresAt    time.Time\n\tProvider     string\n}\n```\nOAuthSession is the session row written after an OAuth2 client login.\n\n```go\ntype OAuthUserStore interface {\n\tGetOrCreateUser(ctx context.Context, user *sectypes.UserContext, provider string) (int, error)\n\tCreateSession(ctx context.Context, session OAuthSession) error\n\tGetByRefreshToken(ctx context.Context, refreshToken string) (*OAuthRefreshSession, error)\n\tUpdateRefreshToken(ctx context.Context, userID int, oldRefreshToken, newSessionToken, newAccessToken, newRefreshToken string, expiresAt time.Time) error\n\tGetUser(ctx context.Context, userID int) (*sectypes.UserContext, error)\n}\n```\nOAuthUserStore persists users and sessions created through OAuth2 client login.\n\n```go\ntype Op string\n```\nOp names one store operation so its mode can be overridden individually.\n\n```go\nconst (\n\tOpLogin         Op = \"login\"\n\tOpRegister      Op = \"register\"\n\tOpLogout        Op = \"logout\"\n\tOpSession       Op = \"session\"\n\tOpTouchSession  Op = \"touch_session\"\n\tOpRefresh       Op = \"refresh\"\n\tOpLoginAPIKey   Op = \"login_api_key\" //nolint:gosec // operation name, not a credential\n\tOpJWTLogin      Op = \"jwt_login\"\n\tOpJWTLogout     Op = \"jwt_logout\"\n\tOpResetRequest  Op = \"reset_request\"\n\tOpResetComplete Op = \"reset_complete\"\n\n\tOpKeyCreate   Op = \"key_create\"\n\tOpKeyList     Op = \"key_list\"\n\tOpKeyDelete   Op = \"key_delete\"\n\tOpKeyValidate Op = \"key_validate\"\n\n\tOpOAuthRegisterClient Op = \"oauth_register_client\"\n\tOpOAuthGetClient      Op = \"oauth_get_client\"\n\tOpOAuthSaveCode       Op = \"oauth_save_code\"\n\tOpOAuthExchangeCode   Op = \"oauth_exchange_code\"\n\tOpOAuthIntrospect     Op = \"oauth_introspect\"\n\tOpOAuthRevoke         Op = \"oauth_revoke\"\n\tOpOAuthUpdateClient   Op = \"oauth_update_client\"\n\tOpOAuthDeleteClient   Op = \"oauth_delete_client\"\n\n\tOpOAuthGetOrCreateUser    Op = \"oauth_get_or_create_user\"\n\tOpOAuthCreateSession      Op = \"oauth_create_session\"\n\tOpOAuthGetRefreshToken    Op = \"oauth_get_refresh_token\"    //nolint:gosec // operation name, not a credential\n\tOpOAuthUpdateRefreshToken Op = \"oauth_update_refresh_token\" //nolint:gosec // operation name, not a credential\n\tOpOAuthGetUser            Op = \"oauth_get_user\"\n\n\tOpOAuthSaveConsent         Op = \"oauth_save_consent\"\n\tOpOAuthGetConsent          Op = \"oauth_get_consent\"\n\tOpOAuthRevokeConsent       Op = \"oauth_revoke_consent\"\n\tOpOAuthSaveRefresh         Op = \"oauth_save_refresh\"           //nolint:gosec // operation name, not a credential\n\tOpOAuthRotateRefresh       Op = \"oauth_rotate_refresh\"         //nolint:gosec // operation name, not a credential\n\tOpOAuthPeekRefresh         Op = \"oauth_peek_refresh\"           //nolint:gosec // operation name, not a credential\n\tOpOAuthRevokeRefreshFamily Op = \"oauth_revoke_refresh_family\"  //nolint:gosec // operation name, not a credential\n\tOpOAuthRevokeRefreshByUser Op = \"oauth_revoke_refresh_session\" //nolint:gosec // operation name, not a credential\n\tOpOAuthCreateDevice        Op = \"oauth_create_device\"\n\tOpOAuthDeviceByUserCode    Op = \"oauth_device_by_user_code\"\n\tOpOAuthDeviceDecide        Op = \"oauth_device_decide\"\n\tOpOAuthDevicePoll          Op = \"oauth_device_poll\"\n\tOpOAuthSavePAR             Op = \"oauth_save_par\"\n\tOpOAuthConsumePAR          Op = \"oauth_consume_par\"\n\tOpOAuthSeenJTI             Op = \"oauth_seen_jti\"\n\n\tOpPasskeyStore         Op = \"passkey_store\"\n\tOpPasskeyGet           Op = \"passkey_get\"\n\tOpPasskeyUpdateCounter Op = \"passkey_update_counter\"\n\tOpPasskeyList          Op = \"passkey_list\"\n\tOpPasskeyDelete        Op = \"passkey_delete\"\n\tOpPasskeyRename        Op = \"passkey_rename\"\n\tOpPasskeyByUsername    Op = \"passkey_by_username\" //nolint:gosec // operation name, not a credential\n\tOpPasskeyLogin         Op = \"passkey_login\"\n\n\tOpTOTPEnable             Op = \"totp_enable\"\n\tOpTOTPDisable            Op = \"totp_disable\"\n\tOpTOTPStatus             Op = \"totp_status\"\n\tOpTOTPSecret             Op = \"totp_secret\"\n\tOpTOTPRegenerateBackup   Op = \"totp_regenerate_backup\"\n\tOpTOTPValidateBackupCode Op = \"totp_validate_backup_code\"\n\n\tOpColumnSecurity Op = \"column_security\"\n\tOpRowSecurity    Op = \"row_security\"\n)\n```\n\n```go\nfunc AllOps() []Op\n```\nAllOps lists every operation, so callers can resolve or validate modes up front.\n\n```go\ntype PasskeyCredentialRecord struct {\n\tUserID          int\n\tCredentialID    string // base64\n\tPublicKey       string // base64\n\tAttestationType string\n\tSignCount       uint32\n\tTransports      []string\n\tBackupEligible  bool\n\tBackupState     bool\n\tName            string\n}\n```\nPasskeyCredentialRecord is a credential as persisted: byte fields are base64 text.\n\n```go\ntype PasskeyCredentialRef struct {\n\tCredentialID string   `json:\"credential_id\"`\n\tTransports   []string `json:\"transports\"`\n}\n```\nPasskeyCredentialRef is a credential id and transports, as returned for a username lookup.\n\n```go\ntype PasskeyStore interface {\n\tStore(ctx context.Context, rec PasskeyCredentialRecord) (int64, error)\n\t// Get returns the owner and signature counter of a credential.\n\tGet(ctx context.Context, credentialID string) (userID int, signCount uint32, err error)\n\tUpdateCounter(ctx context.Context, credentialID string, newCounter uint32) (cloneWarning bool, err error)\n\tList(ctx context.Context, userID int) ([]sectypes.PasskeyCredential, error)\n\tDelete(ctx context.Context, userID int, credentialID string) error\n\tRename(ctx context.Context, userID int, credentialID, name string) error\n\tByUsername(ctx context.Context, username string) (userID int, creds []PasskeyCredentialRef, err error)\n\tLogin(ctx context.Context, userID int, claims map[string]any) (*sectypes.LoginResponse, error)\n}\n```\nPasskeyStore persists WebAuthn credentials.\n\n```go\ntype PolicyStore interface {\n\tColumnSecurity(ctx context.Context, userID int, schema, table string) ([]sectypes.ColumnSecurity, error)\n\tRowSecurity(ctx context.Context, userRef any, schema, table string) (sectypes.RowSecurity, error)\n}\n```\nPolicyStore loads column and row security rules. No rules is an empty result, never an error; failures are errors so callers fail closed.\n\n```go\ntype ProcNames struct {\n\n\t// Auth procedures (DatabaseAuthenticator)\n\tLogin         string // default: \"resolvespec_login\"\n\tRegister      string // default: \"resolvespec_register\"\n\tLogout        string // default: \"resolvespec_logout\"\n\tSession       string // default: \"resolvespec_session\"\n\tSessionUpdate string // default: \"resolvespec_session_update\"\n\tRefreshToken  string // default: \"resolvespec_refresh_token\"\n\tLoginAPIKey   string // default: \"resolvespec_login_api_key\"\n\n\t// JWT procedures (JWTAuthenticator)\n\tJWTLogin  string // default: \"resolvespec_jwt_login\"\n\tJWTLogout string // default: \"resolvespec_jwt_logout\"\n\n\t// Security policy procedures\n\tColumnSecurity string // default: \"resolvespec_column_security\"\n\tRowSecurity    string // default: \"resolvespec_row_security\"\n\n\t// TOTP procedures (DatabaseTwoFactorProvider)\n\tTOTPEnable             string // default: \"resolvespec_totp_enable\"\n\tTOTPDisable            string // default: \"resolvespec_totp_disable\"\n\tTOTPGetStatus          string // default: \"resolvespec_totp_get_status\"\n\tTOTPGetSecret          string // default: \"resolvespec_totp_get_secret\"\n\tTOTPRegenerateBackup   string // default: \"resolvespec_totp_regenerate_backup_codes\"\n\tTOTPValidateBackupCode string // default: \"resolvespec_totp_validate_backup_code\"\n\n\t// Passkey procedures (DatabasePasskeyProvider)\n\tPasskeyStoreCredential    string // default: \"resolvespec_passkey_store_credential\"\n\tPasskeyGetCredsByUsername string // default: \"resolvespec_passkey_get_credentials_by_username\"\n\tPasskeyGetCredential      string // default: \"resolvespec_passkey_get_credential\"\n\tPasskeyUpdateCounter      string // default: \"resolvespec_passkey_update_counter\"\n\tPasskeyGetUserCredentials string // default: \"resolvespec_passkey_get_user_credentials\"\n\tPasskeyDeleteCredential   string // default: \"resolvespec_passkey_delete_credential\"\n\tPasskeyUpdateName         string // default: \"resolvespec_passkey_update_name\"\n\tPasskeyLogin              string // default: \"resolvespec_passkey_login\"\n\n\t// Password reset procedures (DatabaseAuthenticator)\n\tPasswordResetRequest  string // default: \"resolvespec_password_reset_request\"\n\tPasswordResetComplete string // default: \"resolvespec_password_reset\"\n\n\t// OAuth2 procedures (DatabaseAuthenticator OAuth2 methods)\n\tOAuthGetOrCreateUser    string // default: \"resolvespec_oauth_getorcreateuser\"\n\tOAuthCreateSession      string // default: \"resolvespec_oauth_createsession\"\n\tOAuthGetRefreshToken    string // default: \"resolvespec_oauth_getrefreshtoken\"\n\tOAuthUpdateRefreshToken string // default: \"resolvespec_oauth_updaterefreshtoken\"\n\tOAuthGetUser            string // default: \"resolvespec_oauth_getuser\"\n\n\t// OAuth2 server procedures (OAuthServer persistence)\n\tOAuthRegisterClient string // default: \"resolvespec_oauth_register_client\"\n\tOAuthGetClient      string // default: \"resolvespec_oauth_get_client\"\n\tOAuthSaveCode       string // default: \"resolvespec_oauth_save_code\"\n\tOAuthExchangeCode   string // default: \"resolvespec_oauth_exchange_code\"\n\tOAuthIntrospect     string // default: \"resolvespec_oauth_introspect\"\n\tOAuthRevoke         string // default: \"resolvespec_oauth_revoke\"\n\tOAuthUpdateClient   string // default: \"resolvespec_oauth_update_client\"\n\tOAuthDeleteClient   string // default: \"resolvespec_oauth_delete_client\"\n\n\t// OAuth2 server grant procedures (consents, refresh tokens, device codes, PAR, replay cache).\n\t// Each takes a jsonb request and returns (p_success, p_error, p_data).\n\tOAuthSaveConsent         string // default: \"resolvespec_oauth_save_consent\"\n\tOAuthGetConsent          string // default: \"resolvespec_oauth_get_consent\"\n\tOAuthRevokeConsent       string // default: \"resolvespec_oauth_revoke_consent\"\n\tOAuthSaveRefresh         string // default: \"resolvespec_oauth_save_refresh\"\n\tOAuthRotateRefresh       string // default: \"resolvespec_oauth_rotate_refresh\"\n\tOAuthPeekRefresh         string // default: \"resolvespec_oauth_peek_refresh\"\n\tOAuthRevokeRefreshFamily string // default: \"resolvespec_oauth_revoke_refresh_family\"\n\tOAuthRevokeRefreshByUser string // default: \"resolvespec_oauth_revoke_refresh_session\"\n\tOAuthCreateDevice        string // default: \"resolvespec_oauth_create_device\"\n\tOAuthDeviceByUserCode    string // default: \"resolvespec_oauth_device_by_user_code\"\n\tOAuthDeviceDecide        string // default: \"resolvespec_oauth_device_decide\"\n\tOAuthDevicePoll          string // default: \"resolvespec_oauth_device_poll\"\n\tOAuthSavePAR             string // default: \"resolvespec_oauth_save_par\"\n\tOAuthConsumePAR          string // default: \"resolvespec_oauth_consume_par\"\n\tOAuthSeenJTI             string // default: \"resolvespec_oauth_seen_jti\"\n\n\t// Keystore procedures (KeyStore)\n\tKeystoreGetUserKeys string // default: \"resolvespec_keystore_get_user_keys\"\n\tKeystoreCreateKey   string // default: \"resolvespec_keystore_create_key\"\n\tKeystoreDeleteKey   string // default: \"resolvespec_keystore_delete_key\"\n\tKeystoreValidateKey string // default: \"resolvespec_keystore_validate_key\"\n}\n```\nProcNames holds the stored procedure (function) names used by the procedure backend. It replaces security.SQLNames and security.KeyStoreSQLNames. Zero fields mean \"default\" when merged with DefaultProcNames.\n\n```go\nfunc DefaultProcNames() ProcNames\n```\nDefaultProcNames returns the default resolvespec\\_\\* procedure names.\n\n```go\nfunc (p ProcNames) Merge(override ProcNames) ProcNames\n```\nMerge returns a copy of p with every non-empty field of override applied.\n\n```go\nfunc (p ProcNames) Validate() error\n```\nValidate checks that every name is a safe (optionally schema-qualified) identifier.\n\n```go\ntype Provider struct {\n\tAuth        AuthStore\n\tKeys        KeyStore\n\tOAuthClient OAuthClientStore\n\tOAuthUser   OAuthUserStore\n\tOAuthGrant  OAuthGrantStore\n\tPasskey     PasskeyStore\n\tTOTP        TOTPStore\n\tPolicy      PolicyStore\n}\n```\nProvider bundles every store. Security constructors take a Provider.\n\n```go\ntype PushedRequest struct {\n\tRequestURI string            `json:\"request_uri\"`\n\tClientID   string            `json:\"client_id\"`\n\tParams     map[string]string `json:\"params\"`\n\tExpiresAt  time.Time         `json:\"expires_at\"`\n}\n```\nPushedRequest is an RFC 9126 pushed authorization request.\n\n```go\ntype RefreshToken struct {\n\tTokenHash    string         `json:\"token_hash\"`\n\tFamilyID     string         `json:\"family_id\"`\n\tClientID     string         `json:\"client_id\"`\n\tUserID       int            `json:\"user_id\"`\n\tSessionToken string         `json:\"session_token\"`\n\tScopes       []string       `json:\"scopes,omitempty\"`\n\tExtra        map[string]any `json:\"extra,omitempty\"` // nonce, auth_time, acr, sid, dpop_jkt, resource\n\tExpiresAt    time.Time      `json:\"expires_at\"`\n}\n```\nRefreshToken is a server-managed refresh token. Only the SHA-256 hash of the raw token is stored.\n\n```go\ntype Resolved struct {\n\tConfig\n\tProcs  ProcNames\n\tSchema Schema\n}\n```\nResolved is a Config merged with defaults and validated.\n\n```go\ntype Schema map[Entity]Table\n```\nSchema maps every entity to its physical table and columns. The zero value is valid and means \"all defaults\"; use DefaultSchema for the explicit baseline.\n\n```go\nfunc DefaultSchema() Schema\n```\nDefaultSchema returns the baseline schema: every entity and column under its default name.\n\n```go\nfunc (s Schema) Col(c Column) string\n```\nCol returns the physical column name for a logical column (unquoted).\n\n```go\nfunc (s Schema) Merge(override Schema) Schema\n```\nMerge returns a copy of s with every non-empty field of override applied. Unknown entities or columns in override are kept so Validate can report them.\n\n```go\nfunc (s Schema) SchemaName(e Entity) string\n```\nSchemaName returns the optional schema qualifier of an entity.\n\n```go\nfunc (s Schema) TableName(e Entity) string\n```\nTableName returns the physical table name of an entity (unqualified, unquoted).\n\n```go\nfunc (s Schema) Validate() error\n```\nValidate checks that the schema only names known entities and columns and that every identifier is safe. It is meant to run on the merged (default + override) schema.\n\n```go\ntype TOTPStore interface {\n\tEnable(ctx context.Context, userID int, secret string, hashedCodes []string) error\n\tDisable(ctx context.Context, userID int) error\n\tStatus(ctx context.Context, userID int) (bool, error)\n\tSecret(ctx context.Context, userID int) (string, error)\n\tRegenerateBackupCodes(ctx context.Context, userID int, hashedCodes []string) error\n\tValidateBackupCode(ctx context.Context, userID int, codeHash string) (bool, error)\n}\n```\nTOTPStore persists two-factor state. Backup codes arrive already hashed.\n\n```go\ntype Table struct {\n\t// Schema optionally qualifies the table (schema.table). Empty = unqualified.\n\tSchema string\n\t// Name is the physical table name. Empty = default (the entity name).\n\tName string\n\t// Columns maps logical column name -\u003e physical column name. Missing = default.\n\tColumns map[string]string\n}\n```\nTable maps one entity to a physical table and its columns.\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/security/lookup","name":"lookup","synopsis":"Package lookup owns every database read and write the security package needs.","isRedistributable":true}
