sectypes

package
v1.3.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashKey

func HashKey(raw string) string

HashKey returns the lowercase hex SHA-256 digest of a raw key. It is the value stored in UserKey.KeyHash; every keystore implementation uses it to hash raw keys before storage or lookup.

func MergeJSON

func MergeJSON(dst any, data string) error

MergeJSON applies a metadata/extra JSON document onto dst. Empty input is a no-op.

func SplitJSON

func SplitJSON(v any, columns []string) (string, error)

SplitJSON returns the JSON form of v without the keys in columns. It is the value stored in a metadata/extra column; an empty object is returned as "".

Types

type ColumnSecurity

type ColumnSecurity struct {
	Schema       string            `json:"schema"`
	Tablename    string            `json:"tablename"`
	Path         []string          `json:"path"`
	ExtraFilters map[string]string `json:"extra_filters"`
	UserID       int               `json:"user_id"`
	Accesstype   string            `json:"accesstype"`
	MaskStart    int               `json:"mask_start"`
	MaskEnd      int               `json:"mask_end"`
	MaskInvert   bool              `json:"mask_invert"`
	MaskChar     string            `json:"mask_char"`
	Control      string            `json:"control"`
	ID           int               `json:"id"`
}

type CreateKeyRequest

type CreateKeyRequest struct {
	UserID    int
	KeyType   KeyType
	Name      string
	Scopes    []string
	Meta      map[string]any
	ExpiresAt *time.Time
}

CreateKeyRequest specifies the parameters for a new key.

type CreateKeyResponse

type CreateKeyResponse struct {
	Key    UserKey
	RawKey string // crypto/rand 32 bytes, base64url-encoded
}

CreateKeyResponse is returned exactly once when a key is created. The caller is responsible for persisting RawKey; it is not stored anywhere.

type KeyType

type KeyType string

KeyType identifies the category of an auth key.

const (
	// KeyTypeJWTSecret is a per-user JWT signing secret for token generation.
	KeyTypeJWTSecret KeyType = "jwt_secret"
	// KeyTypeHeaderAPI is a static API key sent via a request header.
	KeyTypeHeaderAPI KeyType = "header_api"
	// KeyTypeOAuth2 holds OAuth2 client credentials (client_id / client_secret).
	KeyTypeOAuth2 KeyType = "oauth2"
	// KeyTypeGenericAPI is a generic application API key.
	KeyTypeGenericAPI KeyType = "api"
)

type LoginRequest

type LoginRequest struct {
	Username      string         `json:"username"`
	Password      string         `json:"password"`
	TwoFactorCode string         `json:"two_factor_code,omitempty"` // TOTP or backup code
	Claims        map[string]any `json:"claims"`                    // Additional login data
	Meta          map[string]any `json:"meta"`                      // Additional metadata to be set on user context
}

LoginRequest contains credentials for login

type LoginResponse

type LoginResponse struct {
	Token              string           `json:"token"`
	RefreshToken       string           `json:"refresh_token"`
	User               *UserContext     `json:"user"`
	ExpiresIn          int64            `json:"expires_in"`                 // Token expiration in seconds
	Requires2FA        bool             `json:"requires_2fa"`               // True if 2FA code is required
	TwoFactorSetupData *TwoFactorSecret `json:"two_factor_setup,omitempty"` // Present when setting up 2FA
	Meta               map[string]any   `json:"meta"`                       // Additional metadata to be set on user context
}

LoginResponse contains the result of a login attempt

type LogoutRequest

type LogoutRequest struct {
	Token  string `json:"token"`
	UserID int    `json:"user_id"`
}

LogoutRequest contains information for logout

type OAuthCode

type OAuthCode struct {
	Code                string    `json:"code"`
	ClientID            string    `json:"client_id"`
	RedirectURI         string    `json:"redirect_uri"`
	ClientState         string    `json:"client_state,omitempty"`
	CodeChallenge       string    `json:"code_challenge"`
	CodeChallengeMethod string    `json:"code_challenge_method"`
	SessionToken        string    `json:"session_token"`
	RefreshToken        string    `json:"refresh_token,omitempty"`
	Scopes              []string  `json:"scopes,omitempty"`
	ExpiresAt           time.Time `json:"expires_at"`

	UserID       int            `json:"user_id,omitempty"`
	Nonce        string         `json:"nonce,omitempty"`
	AuthTime     int64          `json:"auth_time,omitempty"`
	ACR          string         `json:"acr,omitempty"`
	AMR          []string       `json:"amr,omitempty"`
	SessionID    string         `json:"sid,omitempty"`
	Claims       map[string]any `json:"claims,omitempty"`
	Resource     []string       `json:"resource,omitempty"`
	DPoPJKT      string         `json:"dpop_jkt,omitempty"`
	ResponseType string         `json:"response_type,omitempty"`
	ConsentedAt  int64          `json:"consented_at,omitempty"`
}

OAuthCode is a short-lived authorization code.

func (*OAuthCode) ApplyCodeExtra

func (c *OAuthCode) ApplyCodeExtra(data string) error

ApplyCodeExtra merges the oauth_codes.extra column into c.

func (*OAuthCode) CodeExtraJSON

func (c *OAuthCode) CodeExtraJSON() (string, error)

CodeExtraJSON returns the value of the oauth_codes.extra column.

type OAuthServerClient

type OAuthServerClient struct {
	ClientID                string   `json:"client_id"`
	RedirectURIs            []string `json:"redirect_uris"`
	ClientName              string   `json:"client_name,omitempty"`
	GrantTypes              []string `json:"grant_types"`
	AllowedScopes           []string `json:"allowed_scopes,omitempty"`
	ClientSecretHash        string   `json:"client_secret_hash,omitempty"`
	TokenEndpointAuthMethod string   `json:"token_endpoint_auth_method,omitempty"`

	ResponseTypes               []string        `json:"response_types,omitempty"`
	ClientURI                   string          `json:"client_uri,omitempty"`
	LogoURI                     string          `json:"logo_uri,omitempty"`
	Contacts                    []string        `json:"contacts,omitempty"`
	PostLogoutRedirectURIs      []string        `json:"post_logout_redirect_uris,omitempty"`
	BackchannelLogoutURI        string          `json:"backchannel_logout_uri,omitempty"`
	JWKS                        json.RawMessage `json:"jwks,omitempty"`
	JWKSURI                     string          `json:"jwks_uri,omitempty"`
	IDTokenSignedResponseAlg    string          `json:"id_token_signed_response_alg,omitempty"`
	UserinfoSignedResponseAlg   string          `json:"userinfo_signed_response_alg,omitempty"`
	TokenEndpointAuthSigningAlg string          `json:"token_endpoint_auth_signing_alg,omitempty"`
	RequireConsent              bool            `json:"require_consent,omitempty"`
	FirstParty                  bool            `json:"first_party,omitempty"`
	RequirePAR                  bool            `json:"require_pushed_authorization_requests,omitempty"`
	DPoPBoundAccessTokens       bool            `json:"dpop_bound_access_tokens,omitempty"`
	RegistrationAccessTokenHash string          `json:"registration_access_token_hash,omitempty"`
	ClientSecretExpiresAt       int64           `json:"client_secret_expires_at,omitempty"`
	ClientIDIssuedAt            int64           `json:"client_id_issued_at,omitempty"`
}

OAuthServerClient is a persisted RFC 7591 registered OAuth2 client.

func (*OAuthServerClient) ApplyClientMetadata

func (c *OAuthServerClient) ApplyClientMetadata(data string) error

ApplyClientMetadata merges the oauth_clients.metadata column into c.

func (*OAuthServerClient) ClientMetadataJSON

func (c *OAuthServerClient) ClientMetadataJSON() (string, error)

ClientMetadataJSON returns the value of the oauth_clients.metadata column.

type OAuthTokenInfo

type OAuthTokenInfo struct {
	Active    bool     `json:"active"`
	Sub       string   `json:"sub,omitempty"`
	Username  string   `json:"username,omitempty"`
	Email     string   `json:"email,omitempty"`
	UserLevel int      `json:"user_level,omitempty"`
	Roles     []string `json:"roles,omitempty"`
	Exp       int64    `json:"exp,omitempty"`
	Iat       int64    `json:"iat,omitempty"`

	// Filled in by the OAuth server, not by the stores.
	Scope     string         `json:"scope,omitempty"`
	ClientID  string         `json:"client_id,omitempty"`
	TokenType string         `json:"token_type,omitempty"`
	Iss       string         `json:"iss,omitempty"`
	Aud       []string       `json:"aud,omitempty"`
	Jti       string         `json:"jti,omitempty"`
	Cnf       map[string]any `json:"cnf,omitempty"`
}

OAuthTokenInfo is the RFC 7662 token introspection response.

type PasskeyAuthenticationOptions

type PasskeyAuthenticationOptions struct {
	Challenge        []byte                        `json:"challenge"`
	Timeout          int64                         `json:"timeout,omitempty"`
	RelyingPartyID   string                        `json:"rpId,omitempty"`
	AllowCredentials []PasskeyCredentialDescriptor `json:"allowCredentials,omitempty"`
	UserVerification string                        `json:"userVerification,omitempty"` // required, preferred, discouraged
	Extensions       map[string]any                `json:"extensions,omitempty"`
}

PasskeyAuthenticationOptions contains options for beginning passkey authentication

type PasskeyAuthenticationResponse

type PasskeyAuthenticationResponse struct {
	ID                     string                                `json:"id"`    // Base64URL encoded credential ID
	RawID                  []byte                                `json:"rawId"` // Raw credential ID
	Type                   string                                `json:"type"`  // "public-key"
	Response               PasskeyAuthenticatorAssertionResponse `json:"response"`
	ClientExtensionResults map[string]any                        `json:"clientExtensionResults,omitempty"`
}

PasskeyAuthenticationResponse contains the client's authentication response

type PasskeyAuthenticatorAssertionResponse

type PasskeyAuthenticatorAssertionResponse struct {
	ClientDataJSON    []byte `json:"clientDataJSON"`
	AuthenticatorData []byte `json:"authenticatorData"`
	Signature         []byte `json:"signature"`
	UserHandle        []byte `json:"userHandle,omitempty"`
}

PasskeyAuthenticatorAssertionResponse contains assertion data

type PasskeyAuthenticatorAttestationResponse

type PasskeyAuthenticatorAttestationResponse struct {
	ClientDataJSON    []byte   `json:"clientDataJSON"`
	AttestationObject []byte   `json:"attestationObject"`
	Transports        []string `json:"transports,omitempty"`
}

PasskeyAuthenticatorAttestationResponse contains attestation data

type PasskeyAuthenticatorSelection

type PasskeyAuthenticatorSelection struct {
	AuthenticatorAttachment string `json:"authenticatorAttachment,omitempty"` // platform, cross-platform
	RequireResidentKey      bool   `json:"requireResidentKey,omitempty"`
	ResidentKey             string `json:"residentKey,omitempty"`      // discouraged, preferred, required
	UserVerification        string `json:"userVerification,omitempty"` // required, preferred, discouraged
}

PasskeyAuthenticatorSelection specifies authenticator requirements

type PasskeyCredential

type PasskeyCredential struct {
	ID              string    `json:"id"`
	UserID          int       `json:"user_id"`
	CredentialID    []byte    `json:"credential_id"`        // Raw credential ID from authenticator
	PublicKey       []byte    `json:"public_key"`           // COSE public key
	AttestationType string    `json:"attestation_type"`     // none, indirect, direct
	AAGUID          []byte    `json:"aaguid"`               // Authenticator AAGUID
	SignCount       uint32    `json:"sign_count"`           // Signature counter
	CloneWarning    bool      `json:"clone_warning"`        // True if cloning detected
	Transports      []string  `json:"transports,omitempty"` // usb, nfc, ble, internal
	BackupEligible  bool      `json:"backup_eligible"`      // Credential can be backed up
	BackupState     bool      `json:"backup_state"`         // Credential is currently backed up
	Name            string    `json:"name,omitempty"`       // User-friendly name
	CreatedAt       time.Time `json:"created_at"`
	LastUsedAt      time.Time `json:"last_used_at"`
}

PasskeyCredential represents a stored WebAuthn/FIDO2 credential

type PasskeyCredentialDescriptor

type PasskeyCredentialDescriptor struct {
	Type       string   `json:"type"`                 // "public-key"
	ID         []byte   `json:"id"`                   // Credential ID
	Transports []string `json:"transports,omitempty"` // usb, nfc, ble, internal
}

PasskeyCredentialDescriptor describes a credential

type PasskeyCredentialParam

type PasskeyCredentialParam struct {
	Type string `json:"type"` // "public-key"
	Alg  int    `json:"alg"`  // COSE algorithm identifier (e.g., -7 for ES256, -257 for RS256)
}

PasskeyCredentialParam specifies supported public key algorithm

type PasskeyRegistrationOptions

type PasskeyRegistrationOptions struct {
	Challenge              []byte                         `json:"challenge"`
	RelyingParty           PasskeyRelyingParty            `json:"rp"`
	User                   PasskeyUser                    `json:"user"`
	PubKeyCredParams       []PasskeyCredentialParam       `json:"pubKeyCredParams"`
	Timeout                int64                          `json:"timeout,omitempty"` // Milliseconds
	ExcludeCredentials     []PasskeyCredentialDescriptor  `json:"excludeCredentials,omitempty"`
	AuthenticatorSelection *PasskeyAuthenticatorSelection `json:"authenticatorSelection,omitempty"`
	Attestation            string                         `json:"attestation,omitempty"` // none, indirect, direct, enterprise
	Extensions             map[string]any                 `json:"extensions,omitempty"`
}

PasskeyRegistrationOptions contains options for beginning passkey registration

type PasskeyRegistrationResponse

type PasskeyRegistrationResponse struct {
	ID                     string                                  `json:"id"`    // Base64URL encoded credential ID
	RawID                  []byte                                  `json:"rawId"` // Raw credential ID
	Type                   string                                  `json:"type"`  // "public-key"
	Response               PasskeyAuthenticatorAttestationResponse `json:"response"`
	ClientExtensionResults map[string]any                          `json:"clientExtensionResults,omitempty"`
	Transports             []string                                `json:"transports,omitempty"`
}

PasskeyRegistrationResponse contains the client's registration response

type PasskeyRelyingParty

type PasskeyRelyingParty struct {
	ID   string `json:"id"`   // Domain (e.g., "example.com")
	Name string `json:"name"` // Display name
}

PasskeyRelyingParty identifies the relying party

type PasskeyUser

type PasskeyUser struct {
	ID          []byte `json:"id"`          // User handle (unique, persistent)
	Name        string `json:"name"`        // Username
	DisplayName string `json:"displayName"` // Display name
}

PasskeyUser identifies the user

type PasswordResetCompleteRequest

type PasswordResetCompleteRequest struct {
	Token       string `json:"token"`
	NewPassword string `json:"new_password"`
}

PasswordResetCompleteRequest completes a password reset using the token

type PasswordResetRequest

type PasswordResetRequest struct {
	Email    string `json:"email,omitempty"`
	Username string `json:"username,omitempty"`
}

PasswordResetRequest initiates a password reset for a user

type PasswordResetResponse

type PasswordResetResponse struct {
	// Token is the reset token to be delivered out-of-band (e.g. email).
	// The stored procedure may return it for delivery or leave it empty
	// if the delivery is handled entirely in the database.
	Token     string `json:"token"`
	ExpiresIn int64  `json:"expires_in"` // seconds
}

PasswordResetResponse is returned when a reset is initiated

type RegisterRequest

type RegisterRequest struct {
	Username  string         `json:"username"`
	Password  string         `json:"password"`
	Email     string         `json:"email"`
	UserLevel int            `json:"user_level"`
	Roles     []string       `json:"roles"`
	Claims    map[string]any `json:"claims"` // Additional registration data
	Meta      map[string]any `json:"meta"`   // Additional metadata
}

RegisterRequest contains information for new user registration

type RowSecurity

type RowSecurity struct {
	Schema    string `json:"schema"`
	Tablename string `json:"tablename"`
	Template  string `json:"template"`
	HasBlock  bool   `json:"has_block"`
	// UserID is the opaque user reference the security rules were loaded for.
	// It may be an int, a string/UUID, or a *UserContext, depending on what the
	// RowSecurityProvider/SecurityContext.GetUserRef implementation returns.
	UserID any `json:"user_id"`
}

func (*RowSecurity) GetTemplate

func (m *RowSecurity) GetTemplate(pPrimaryKeyName string, pModelType reflect.Type) (clause string, args []any, err error)

GetTemplate expands the row-security template into a WHERE clause and its bind arguments. {PrimaryKeyName}, {TableName} and {SchemaName} are validated identifiers substituted in place; every {UserID} becomes a `?` placeholder with the user reference bound as an argument, so user data never reaches the SQL text.

type TwoFactorSecret

type TwoFactorSecret struct {
	Secret      string   `json:"secret"`       // Base32 encoded secret
	QRCodeURL   string   `json:"qr_code_url"`  // URL for QR code generation
	BackupCodes []string `json:"backup_codes"` // One-time backup codes
	Issuer      string   `json:"issuer"`       // Application name
	AccountName string   `json:"account_name"` // User identifier (email/username)
}

TwoFactorSecret contains 2FA setup information

type UserContext

type UserContext struct {
	UserID           int            `json:"user_id"`
	UserName         string         `json:"user_name"`
	UserLevel        int            `json:"user_level"`
	SessionID        string         `json:"session_id"`
	SessionRID       int64          `json:"session_rid"`
	RemoteID         string         `json:"remote_id"`
	Roles            []string       `json:"roles"`
	Email            string         `json:"email"`
	Claims           map[string]any `json:"claims"`
	Meta             map[string]any `json:"meta"`               // Additional metadata that can hold any JSON-serializable values
	TwoFactorEnabled bool           `json:"two_factor_enabled"` // Indicates if 2FA is enabled for this user
	ProgramUserID    int            `json:"program_user_id"`
	ProgramUserTable string         `json:"program_user_table"`
}

UserContext holds authenticated user information

type UserKey

type UserKey struct {
	ID         int64          `json:"id"`
	UserID     int            `json:"user_id"`
	KeyType    KeyType        `json:"key_type"`
	KeyHash    string         `json:"key_hash"` // SHA-256 hex; never the raw key
	Name       string         `json:"name"`
	Scopes     []string       `json:"scopes,omitempty"`
	Meta       map[string]any `json:"meta,omitempty"`
	ExpiresAt  *time.Time     `json:"expires_at,omitempty"`
	CreatedAt  time.Time      `json:"created_at"`
	LastUsedAt *time.Time     `json:"last_used_at,omitempty"`
	IsActive   bool           `json:"is_active"`
}

UserKey represents a single named auth key belonging to a user. KeyHash stores the SHA-256 hex digest of the raw key; the raw key is never persisted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL