Documentation
¶
Index ¶
- Variables
- func GenerateJWT(secret []byte, userID string, ttl int) (string, error)
- func UIModules() []any
- func ValidateJWT(secret []byte, token string) (string, error)
- type AuthMode
- type Config
- type Executor
- type GoogleProvider
- type Identity
- type IdentityList
- func (s *IdentityList) Append() fmt.Fielder
- func (s *IdentityList) At(i int) fmt.Fielder
- func (s *IdentityList) DecodeFields(_ fmt.FieldReader)
- func (s *IdentityList) EncodeFields(_ fmt.FieldWriter)
- func (s *IdentityList) IsNil() bool
- func (s *IdentityList) Len() int
- func (s *IdentityList) Pointers() []any
- func (s *IdentityList) Schema() []fmt.Field
- type LANIP
- type LANIPList
- func (s *LANIPList) Append() fmt.Fielder
- func (s *LANIPList) At(i int) fmt.Fielder
- func (s *LANIPList) DecodeFields(_ fmt.FieldReader)
- func (s *LANIPList) EncodeFields(_ fmt.FieldWriter)
- func (s *LANIPList) IsNil() bool
- func (s *LANIPList) Len() int
- func (s *LANIPList) Pointers() []any
- func (s *LANIPList) Schema() []fmt.Field
- type LoginData
- type LoginDataList
- func (s *LoginDataList) Append() fmt.Fielder
- func (s *LoginDataList) At(i int) fmt.Fielder
- func (s *LoginDataList) DecodeFields(_ fmt.FieldReader)
- func (s *LoginDataList) EncodeFields(_ fmt.FieldWriter)
- func (s *LoginDataList) IsNil() bool
- func (s *LoginDataList) Len() int
- func (s *LoginDataList) Pointers() []any
- func (s *LoginDataList) Schema() []fmt.Field
- type MicrosoftProvider
- func (p *MicrosoftProvider) AuthCodeURL(state string) string
- func (p *MicrosoftProvider) ExchangeCode(ctx context.Context, code string) (*oauth2.Token, error)
- func (p *MicrosoftProvider) GetUserInfo(ctx context.Context, token *oauth2.Token) (OAuthUserInfo, error)
- func (p *MicrosoftProvider) Name() string
- type Module
- func (m *Module) AccessCheck(resource string, action byte, data ...any) bool
- func (m *Module) Add() []any
- func (m *Module) AssignLANIP(userID, ip, label string) error
- func (m *Module) AssignPermission(roleID, permissionID string) error
- func (m *Module) AssignRole(userID, roleID string) error
- func (m *Module) BeginOAuth(providerName string) (string, error)
- func (m *Module) CanExecute(ctx context.Context, resource string, action byte) bool
- func (m *Module) CompleteOAuth(providerName string, r *http.Request, ip, ua string) (User, bool, error)
- func (m *Module) CreatePermission(id, name, resource string, action string) error
- func (m *Module) CreateRole(id string, code string, name, description string) error
- func (m *Module) CreateSession(userID, ip, userAgent string) (Session, error)
- func (m *Module) DeletePermission(id string) error
- func (m *Module) DeleteRole(id string) error
- func (m *Module) DeleteSession(id string) error
- func (m *Module) FromContext(ctx context.Context) (*User, bool)
- func (m *Module) GenerateAPIToken(userID string, ttl int) (string, error)
- func (m *Module) GetLANIPs(userID string) ([]LANIP, error)
- func (m *Module) GetPermission(id string) (*Permission, error)
- func (m *Module) GetRole(id string) (*Role, error)
- func (m *Module) GetRoleByCode(code string) (*Role, error)
- func (m *Module) GetSession(id string) (Session, error)
- func (m *Module) GetUser(id string) (User, error)
- func (m *Module) GetUserIdentities(userID string) ([]Identity, error)
- func (m *Module) GetUserRoles(userID string) ([]Role, error)
- func (m *Module) HasPermission(userID, resource string, action byte) (bool, error)
- func (m *Module) InjectIdentity(ctx context.Context, r *http.Request) context.Context
- func (m *Module) Login(email, password string) (User, error)
- func (m *Module) LoginLAN(rut string, r *http.Request) (User, error)
- func (m *Module) Middleware(next http.Handler) http.Handler
- func (m *Module) PurgeExpiredOAuthStates() error
- func (m *Module) PurgeExpiredSessions() error
- func (m *Module) PurgeSessionsByUser(userID string) error
- func (m *Module) ReactivateUser(id string) error
- func (m *Module) Register(handlers ...RBACObject) error
- func (m *Module) RegisterLAN(userID, rut string) error
- func (m *Module) RegisterMCP(next http.Handler) http.Handler
- func (m *Module) RevokeLANIP(userID, ip string) error
- func (m *Module) RevokeRole(userID, roleID string) error
- func (m *Module) RotateSession(oldID, ip, userAgent string) (Session, error)
- func (m *Module) SetLog(fn func(...any))
- func (m *Module) SetPassword(userID, password string) error
- func (m *Module) SuspendUser(id string) error
- func (m *Module) UIModules() []any
- func (m *Module) UnlinkIdentity(userID, provider string) error
- func (m *Module) UnregisterLAN(userID string) error
- func (m *Module) VerifyPassword(userID, password string) error
- type OAuthProvider
- type OAuthState
- type OAuthStateList
- func (s *OAuthStateList) Append() fmt.Fielder
- func (s *OAuthStateList) At(i int) fmt.Fielder
- func (s *OAuthStateList) DecodeFields(_ fmt.FieldReader)
- func (s *OAuthStateList) EncodeFields(_ fmt.FieldWriter)
- func (s *OAuthStateList) IsNil() bool
- func (s *OAuthStateList) Len() int
- func (s *OAuthStateList) Pointers() []any
- func (s *OAuthStateList) Schema() []fmt.Field
- type OAuthUserInfo
- type PasswordData
- type PasswordDataList
- func (s *PasswordDataList) Append() fmt.Fielder
- func (s *PasswordDataList) At(i int) fmt.Fielder
- func (s *PasswordDataList) DecodeFields(_ fmt.FieldReader)
- func (s *PasswordDataList) EncodeFields(_ fmt.FieldWriter)
- func (s *PasswordDataList) IsNil() bool
- func (s *PasswordDataList) Len() int
- func (s *PasswordDataList) Pointers() []any
- func (s *PasswordDataList) Schema() []fmt.Field
- type Permission
- type PermissionList
- func (s *PermissionList) Append() fmt.Fielder
- func (s *PermissionList) At(i int) fmt.Fielder
- func (s *PermissionList) DecodeFields(_ fmt.FieldReader)
- func (s *PermissionList) EncodeFields(_ fmt.FieldWriter)
- func (s *PermissionList) IsNil() bool
- func (s *PermissionList) Len() int
- func (s *PermissionList) Pointers() []any
- func (s *PermissionList) Schema() []fmt.Field
- type ProfileData
- type ProfileDataList
- func (s *ProfileDataList) Append() fmt.Fielder
- func (s *ProfileDataList) At(i int) fmt.Fielder
- func (s *ProfileDataList) DecodeFields(_ fmt.FieldReader)
- func (s *ProfileDataList) EncodeFields(_ fmt.FieldWriter)
- func (s *ProfileDataList) IsNil() bool
- func (s *ProfileDataList) Len() int
- func (s *ProfileDataList) Pointers() []any
- func (s *ProfileDataList) Schema() []fmt.Field
- type RBACObject
- type RegisterData
- type RegisterDataList
- func (s *RegisterDataList) Append() fmt.Fielder
- func (s *RegisterDataList) At(i int) fmt.Fielder
- func (s *RegisterDataList) DecodeFields(_ fmt.FieldReader)
- func (s *RegisterDataList) EncodeFields(_ fmt.FieldWriter)
- func (s *RegisterDataList) IsNil() bool
- func (s *RegisterDataList) Len() int
- func (s *RegisterDataList) Pointers() []any
- func (s *RegisterDataList) Schema() []fmt.Field
- type Role
- type RoleList
- func (s *RoleList) Append() fmt.Fielder
- func (s *RoleList) At(i int) fmt.Fielder
- func (s *RoleList) DecodeFields(_ fmt.FieldReader)
- func (s *RoleList) EncodeFields(_ fmt.FieldWriter)
- func (s *RoleList) IsNil() bool
- func (s *RoleList) Len() int
- func (s *RoleList) Pointers() []any
- func (s *RoleList) Schema() []fmt.Field
- type RolePermission
- type RolePermissionList
- func (s *RolePermissionList) Append() fmt.Fielder
- func (s *RolePermissionList) At(i int) fmt.Fielder
- func (s *RolePermissionList) DecodeFields(_ fmt.FieldReader)
- func (s *RolePermissionList) EncodeFields(_ fmt.FieldWriter)
- func (s *RolePermissionList) IsNil() bool
- func (s *RolePermissionList) Len() int
- func (s *RolePermissionList) Pointers() []any
- func (s *RolePermissionList) Schema() []fmt.Field
- type Rows
- type Scanner
- type SecurityEvent
- type SecurityEventType
- type Session
- type SessionList
- func (s *SessionList) Append() fmt.Fielder
- func (s *SessionList) At(i int) fmt.Fielder
- func (s *SessionList) DecodeFields(_ fmt.FieldReader)
- func (s *SessionList) EncodeFields(_ fmt.FieldWriter)
- func (s *SessionList) IsNil() bool
- func (s *SessionList) Len() int
- func (s *SessionList) Pointers() []any
- func (s *SessionList) Schema() []fmt.Field
- type User
- type UserList
- func (s *UserList) Append() fmt.Fielder
- func (s *UserList) At(i int) fmt.Fielder
- func (s *UserList) DecodeFields(_ fmt.FieldReader)
- func (s *UserList) EncodeFields(_ fmt.FieldWriter)
- func (s *UserList) IsNil() bool
- func (s *UserList) Len() int
- func (s *UserList) Pointers() []any
- func (s *UserList) Schema() []fmt.Field
- type UserRole
- type UserRoleList
- func (s *UserRoleList) Append() fmt.Fielder
- func (s *UserRoleList) At(i int) fmt.Fielder
- func (s *UserRoleList) DecodeFields(_ fmt.FieldReader)
- func (s *UserRoleList) EncodeFields(_ fmt.FieldWriter)
- func (s *UserRoleList) IsNil() bool
- func (s *UserRoleList) Len() int
- func (s *UserRoleList) Pointers() []any
- func (s *UserRoleList) Schema() []fmt.Field
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCredentials = fmt.Err("access", "denied") // EN: Access Denied / ES: Acceso Denegado ErrSuspended = fmt.Err("user", "suspended") // EN: User Suspended / ES: Usuario Suspendido ErrEmailTaken = fmt.Err("email", "registered") // EN: Email Registered / ES: Correo electrónico Registrado ErrWeakPassword = fmt.Err("password", "weak") // EN: Password Weak / ES: Contraseña Débil ErrSessionExpired = fmt.Err("token", "expired") // EN: Token Expired / ES: Token Expirado ErrNotFound = fmt.Err("user", "not", "found") // EN: User Not Found / ES: Usuario No Encontrado ErrProviderNotFound = fmt.Err("provider", "not", "found") // EN: Provider Not Found / ES: Proveedor No Encontrado ErrInvalidOAuthState = fmt.Err("state", "invalid") // EN: State Invalid / ES: Estado Inválido ErrCannotUnlink = fmt.Err("identity", "cannot", "unlink") // EN: Identity Cannot Unlink / ES: Identidad No puede Desvincular ErrInvalidRUT = fmt.Err("rut", "invalid") // EN: Rut Invalid / ES: Rut Inválido ErrRUTTaken = fmt.Err("rut", "registered") // EN: Rut Registered / ES: Rut Registrado ErrIPTaken = fmt.Err("ip", "registered") // EN: Ip Registered / ES: Ip Registrado )
var ErrInvalidToken = fmt.Err("token", "invalid")
var Identity_ = struct { ID string UserID string Provider string ProviderID string Email string CreatedAt string }{ ID: "id", UserID: "user_id", Provider: "provider", ProviderID: "provider_id", Email: "email", CreatedAt: "created_at", }
var LANIP_ = struct { ID string UserID string IP string Label string CreatedAt string }{ ID: "id", UserID: "user_id", IP: "ip", Label: "label", CreatedAt: "created_at", }
var OAuthState_ = struct { State string Provider string ExpiresAt string CreatedAt string }{ State: "state", Provider: "provider", ExpiresAt: "expires_at", CreatedAt: "created_at", }
var PasswordHashCost = bcrypt.DefaultCost
var Permission_ = struct { ID string Name string Resource string Action string }{ ID: "id", Name: "name", Resource: "resource", Action: "action", }
var RolePermission_ = struct { RoleID string PermissionID string }{ RoleID: "role_id", PermissionID: "permission_id", }
var Role_ = struct { ID string Code string Name string Description string }{ ID: "id", Code: "code", Name: "name", Description: "description", }
var Session_ = struct { ID string UserID string ExpiresAt string IP string UserAgent string CreatedAt string }{ ID: "id", UserID: "user_id", ExpiresAt: "expires_at", IP: "ip", UserAgent: "user_agent", CreatedAt: "created_at", }
var UserRole_ = struct { UserID string RoleID string }{ UserID: "user_id", RoleID: "role_id", }
Functions ¶
func GenerateJWT ¶ added in v0.0.17
Types ¶
type AuthMode ¶ added in v0.0.17
type AuthMode uint8
AuthMode selects the session strategy.
const ( // AuthModeCookie stores a session ID in an HttpOnly cookie. // Stateful: requires user_sessions table. Supports immediate revocation. AuthModeCookie AuthMode = iota // default // AuthModeJWT stores a signed JWT in an HttpOnly cookie. // Stateless: no DB lookup per request. No immediate revocation. // Ideal for SPA/PWA and multi-server deployments. AuthModeJWT // AuthModeBearer reads a signed JWT from the "Authorization: Bearer <token>" header. // Stateless: for API clients (MCP servers, IDEs, LLMs) that cannot use cookies. // Structurally implements mcp.Authorizer via InjectIdentity + CanExecute methods. // Requires JWTSecret. AuthModeBearer )
type Config ¶ added in v0.0.2
type Config struct {
AuthMode AuthMode // default: AuthModeCookie
// Shared by all modes
CookieName string // default: "session"
TokenTTL int // default: 86400 (seconds). Session TTL in cookie mode, JWT expiry in JWT mode.
// Required when AuthMode == AuthModeJWT or AuthMode == AuthModeBearer.
// Also required to call GenerateAPIToken regardless of AuthMode.
JWTSecret []byte
TrustProxy bool
OAuthProviders []OAuthProvider
// Optional hook for receiving security events (e.g. tampering, brute force)
OnSecurityEvent func(SecurityEvent)
// OnPasswordValidate is called by SetPassword before hashing.
// Return a non-nil error to reject the password.
// If nil, only the built-in len >= 8 check applies.
OnPasswordValidate func(password string) error
}
type Executor ¶ added in v0.0.2
type Executor interface {
Exec(query string, args ...any) error
Query(query string, args ...any) (Rows, error)
QueryRow(query string, args ...any) Scanner
Prepare(query string) (*sql.Stmt, error)
Begin() (*sql.Tx, error)
}
Executor interface abstracts database operations.
type GoogleProvider ¶ added in v0.0.2
type GoogleProvider struct {
ClientID string
ClientSecret string
RedirectURL string
// contains filtered or unexported fields
}
func (*GoogleProvider) AuthCodeURL ¶ added in v0.0.2
func (p *GoogleProvider) AuthCodeURL(state string) string
func (*GoogleProvider) ExchangeCode ¶ added in v0.0.2
func (*GoogleProvider) GetUserInfo ¶ added in v0.0.2
func (p *GoogleProvider) GetUserInfo(ctx context.Context, token *oauth2.Token) (OAuthUserInfo, error)
func (*GoogleProvider) Name ¶ added in v0.0.2
func (p *GoogleProvider) Name() string
type Identity ¶ added in v0.0.2
type Identity struct {
ID string `db:"pk"`
UserID string `db:"ref=users"`
Provider string
ProviderID string
Email string
CreatedAt int64
}
orm:typed_fields
func ReadOneIdentity ¶ added in v0.0.6
func (*Identity) DecodeFields ¶ added in v0.0.29
func (m *Identity) DecodeFields(r fmt.FieldReader)
func (*Identity) EncodeFields ¶ added in v0.0.29
func (m *Identity) EncodeFields(w fmt.FieldWriter)
type IdentityList ¶ added in v0.0.29
type IdentityList []*Identity
func ReadAllIdentity ¶ added in v0.0.6
func ReadAllIdentity(qb *orm.QB) (IdentityList, error)
func (*IdentityList) Append ¶ added in v0.0.29
func (s *IdentityList) Append() fmt.Fielder
func (*IdentityList) DecodeFields ¶ added in v0.0.29
func (s *IdentityList) DecodeFields(_ fmt.FieldReader)
func (*IdentityList) EncodeFields ¶ added in v0.0.29
func (s *IdentityList) EncodeFields(_ fmt.FieldWriter)
func (*IdentityList) IsNil ¶ added in v0.0.29
func (s *IdentityList) IsNil() bool
func (*IdentityList) Len ¶ added in v0.0.29
func (s *IdentityList) Len() int
func (*IdentityList) Pointers ¶ added in v0.0.29
func (s *IdentityList) Pointers() []any
func (*IdentityList) Schema ¶ added in v0.0.29
func (s *IdentityList) Schema() []fmt.Field
type LANIP ¶ added in v0.0.2
type LANIP struct {
ID string `db:"pk"`
UserID string `db:"ref=users"`
IP string
Label string
CreatedAt int64
}
orm:typed_fields
func (*LANIP) DecodeFields ¶ added in v0.0.29
func (m *LANIP) DecodeFields(r fmt.FieldReader)
func (*LANIP) EncodeFields ¶ added in v0.0.29
func (m *LANIP) EncodeFields(w fmt.FieldWriter)
type LANIPList ¶ added in v0.0.29
type LANIPList []*LANIP
func (*LANIPList) DecodeFields ¶ added in v0.0.29
func (s *LANIPList) DecodeFields(_ fmt.FieldReader)
func (*LANIPList) EncodeFields ¶ added in v0.0.29
func (s *LANIPList) EncodeFields(_ fmt.FieldWriter)
type LoginData ¶ added in v0.0.2
LoginData is validated by LoginModule on both frontend and backend.
func (*LoginData) DecodeFields ¶ added in v0.0.29
func (m *LoginData) DecodeFields(r fmt.FieldReader)
func (*LoginData) EncodeFields ¶ added in v0.0.29
func (m *LoginData) EncodeFields(w fmt.FieldWriter)
type LoginDataList ¶ added in v0.0.29
type LoginDataList []*LoginData
func (*LoginDataList) Append ¶ added in v0.0.29
func (s *LoginDataList) Append() fmt.Fielder
func (*LoginDataList) DecodeFields ¶ added in v0.0.29
func (s *LoginDataList) DecodeFields(_ fmt.FieldReader)
func (*LoginDataList) EncodeFields ¶ added in v0.0.29
func (s *LoginDataList) EncodeFields(_ fmt.FieldWriter)
func (*LoginDataList) IsNil ¶ added in v0.0.29
func (s *LoginDataList) IsNil() bool
func (*LoginDataList) Len ¶ added in v0.0.29
func (s *LoginDataList) Len() int
func (*LoginDataList) Pointers ¶ added in v0.0.29
func (s *LoginDataList) Pointers() []any
func (*LoginDataList) Schema ¶ added in v0.0.29
func (s *LoginDataList) Schema() []fmt.Field
type MicrosoftProvider ¶ added in v0.0.2
type MicrosoftProvider struct {
ClientID string
ClientSecret string
RedirectURL string
// contains filtered or unexported fields
}
func (*MicrosoftProvider) AuthCodeURL ¶ added in v0.0.2
func (p *MicrosoftProvider) AuthCodeURL(state string) string
func (*MicrosoftProvider) ExchangeCode ¶ added in v0.0.2
func (*MicrosoftProvider) GetUserInfo ¶ added in v0.0.2
func (p *MicrosoftProvider) GetUserInfo(ctx context.Context, token *oauth2.Token) (OAuthUserInfo, error)
func (*MicrosoftProvider) Name ¶ added in v0.0.2
func (p *MicrosoftProvider) Name() string
type Module ¶ added in v0.0.15
type Module struct {
// contains filtered or unexported fields
}
Module is the user/auth/rbac handle. All backend operations are methods on this type. Created exclusively via New().
func New ¶
New initializes the user/rbac schema, warms the cache, and returns a Module handle. This is the ONLY entry point for this package on the backend.
func (*Module) AccessCheck ¶ added in v0.0.15
AccessCheck is the bridge function for tinywasm/crudp and tinywasm/site. Reads the *http.Request from data, validates the session, and checks RBAC permissions. Satisfies the site.SetAccessCheck(fn) signature directly.
Usage: site.SetAccessCheck(m.AccessCheck)
func (*Module) Add ¶ added in v0.0.15
Add returns all admin-managed CRUDP handlers for registration. The concrete types are private — pass directly to crudp.RegisterHandlers.
Usage: cp.RegisterHandlers(m.Add()...)
func (*Module) AssignLANIP ¶ added in v0.0.15
func (*Module) AssignPermission ¶ added in v0.0.15
func (*Module) AssignRole ¶ added in v0.0.15
func (*Module) BeginOAuth ¶ added in v0.0.15
func (*Module) CanExecute ¶ added in v0.0.24
CanExecute implements mcp.Authorizer. Reads identity injected by InjectIdentity and checks RBAC.
func (*Module) CompleteOAuth ¶ added in v0.0.15
func (*Module) CreatePermission ¶ added in v0.0.15
func (*Module) CreateRole ¶ added in v0.0.15
func (*Module) CreateSession ¶ added in v0.0.15
func (*Module) DeletePermission ¶ added in v0.0.15
func (*Module) DeleteRole ¶ added in v0.0.15
func (*Module) DeleteSession ¶ added in v0.0.15
func (*Module) FromContext ¶ added in v0.0.15
FromContext extracts the authenticated *User injected by Middleware or RegisterMCP. Returns (nil, false) if the context carries no authenticated user.
func (*Module) GenerateAPIToken ¶ added in v0.0.24
GenerateAPIToken creates a signed JWT for API access (MCP clients, IDEs, LLMs). Requires Config.JWTSecret — independent of the configured AuthMode. ttl=0 → 100 years (effectively no expiry). The returned token is used as a Bearer token in Authorization headers.
func (*Module) GetPermission ¶ added in v0.0.15
func (m *Module) GetPermission(id string) (*Permission, error)
func (*Module) GetRoleByCode ¶ added in v0.0.15
func (*Module) GetSession ¶ added in v0.0.15
func (*Module) GetUserIdentities ¶ added in v0.0.15
func (*Module) GetUserRoles ¶ added in v0.0.15
func (*Module) HasPermission ¶ added in v0.0.15
func (*Module) InjectIdentity ¶ added in v0.0.24
InjectIdentity implements mcp.Authorizer. Delegates to validateSession (respects configured AuthMode). On failure: returns ctx unchanged — CanExecute will deny.
func (*Module) Middleware ¶ added in v0.0.15
Middleware protects HTTP routes. Validates the session cookie and injects the authenticated *User into the request context. Returns HTTP 401 if the session is missing or expired.
Example:
mux.Handle("/admin", m.Middleware(adminHandler))
func (*Module) PurgeExpiredOAuthStates ¶ added in v0.0.15
func (*Module) PurgeExpiredSessions ¶ added in v0.0.15
func (*Module) PurgeSessionsByUser ¶ added in v0.0.22
PurgeSessionsByUser deletes all sessions belonging to userID from cache and DB.
func (*Module) ReactivateUser ¶ added in v0.0.22
ReactivateUser sets Status = "active". Evicts user from cache.
func (*Module) Register ¶ added in v0.0.15
func (m *Module) Register(handlers ...RBACObject) error
func (*Module) RegisterLAN ¶ added in v0.0.15
func (*Module) RegisterMCP ¶ added in v0.0.15
RegisterMCP envuelve el handler MCP con middleware de sesión. Alternativa limpia a registrar hooks en el MCPServer (que no existe en tinywasm/mcp).
Ejemplo:
mcpHandler := mcp.NewStreamableHTTPServer(srv)
mux.Handle("/mcp", m.RegisterMCP(mcpHandler))
func (*Module) RevokeLANIP ¶ added in v0.0.15
func (*Module) RevokeRole ¶ added in v0.0.15
func (*Module) RotateSession ¶ added in v0.0.22
RotateSession atomically deletes the old session and creates a new one with the same userID, updated IP/UserAgent, and a fresh TTL. Prevents session fixation attacks when called post-login.
func (*Module) SetLog ¶ added in v0.0.15
SetLog configures optional logging. Call immediately after New(). Default: no-op. Follows the tinywasm ecosystem SetLog convention (same as rbac).
Example:
m.SetLog(func(msg ...any) { log.Println(msg...) })
func (*Module) SetPassword ¶ added in v0.0.15
func (*Module) SuspendUser ¶ added in v0.0.22
SuspendUser sets Status = "suspended". Evicts user from cache.
func (*Module) UIModules ¶ added in v0.0.15
UIModules returns all standard authentication UI flow handlers bound to this module. Isomorphic: The signature exists in both WASM and backend. On the backend, it links to the DB.
func (*Module) UnlinkIdentity ¶ added in v0.0.15
func (*Module) UnregisterLAN ¶ added in v0.0.15
func (*Module) VerifyPassword ¶ added in v0.0.15
type OAuthProvider ¶ added in v0.0.2
type OAuthState ¶ added in v0.0.6
orm:typed_fields
func ReadOneOAuthState ¶ added in v0.0.6
func ReadOneOAuthState(qb *orm.QB, model *OAuthState) (*OAuthState, error)
func (*OAuthState) DecodeFields ¶ added in v0.0.29
func (m *OAuthState) DecodeFields(r fmt.FieldReader)
func (*OAuthState) EncodeFields ¶ added in v0.0.29
func (m *OAuthState) EncodeFields(w fmt.FieldWriter)
func (*OAuthState) IsNil ¶ added in v0.0.29
func (m *OAuthState) IsNil() bool
func (*OAuthState) ModelName ¶ added in v0.0.29
func (m *OAuthState) ModelName() string
func (*OAuthState) Pointers ¶ added in v0.0.6
func (m *OAuthState) Pointers() []any
func (*OAuthState) Schema ¶ added in v0.0.6
func (m *OAuthState) Schema() []fmt.Field
type OAuthStateList ¶ added in v0.0.29
type OAuthStateList []*OAuthState
func ReadAllOAuthState ¶ added in v0.0.6
func ReadAllOAuthState(qb *orm.QB) (OAuthStateList, error)
func (*OAuthStateList) Append ¶ added in v0.0.29
func (s *OAuthStateList) Append() fmt.Fielder
func (*OAuthStateList) DecodeFields ¶ added in v0.0.29
func (s *OAuthStateList) DecodeFields(_ fmt.FieldReader)
func (*OAuthStateList) EncodeFields ¶ added in v0.0.29
func (s *OAuthStateList) EncodeFields(_ fmt.FieldWriter)
func (*OAuthStateList) IsNil ¶ added in v0.0.29
func (s *OAuthStateList) IsNil() bool
func (*OAuthStateList) Len ¶ added in v0.0.29
func (s *OAuthStateList) Len() int
func (*OAuthStateList) Pointers ¶ added in v0.0.29
func (s *OAuthStateList) Pointers() []any
func (*OAuthStateList) Schema ¶ added in v0.0.29
func (s *OAuthStateList) Schema() []fmt.Field
type OAuthUserInfo ¶ added in v0.0.2
type PasswordData ¶ added in v0.0.2
PasswordData is validated by ProfileModule (password change sub-form).
func (*PasswordData) DecodeFields ¶ added in v0.0.29
func (m *PasswordData) DecodeFields(r fmt.FieldReader)
func (*PasswordData) EncodeFields ¶ added in v0.0.29
func (m *PasswordData) EncodeFields(w fmt.FieldWriter)
func (*PasswordData) IsNil ¶ added in v0.0.29
func (m *PasswordData) IsNil() bool
func (*PasswordData) ModelName ¶ added in v0.0.29
func (m *PasswordData) ModelName() string
func (*PasswordData) Pointers ¶ added in v0.0.28
func (m *PasswordData) Pointers() []any
func (*PasswordData) Schema ¶ added in v0.0.28
func (m *PasswordData) Schema() []fmt.Field
type PasswordDataList ¶ added in v0.0.29
type PasswordDataList []*PasswordData
func (*PasswordDataList) Append ¶ added in v0.0.29
func (s *PasswordDataList) Append() fmt.Fielder
func (*PasswordDataList) DecodeFields ¶ added in v0.0.29
func (s *PasswordDataList) DecodeFields(_ fmt.FieldReader)
func (*PasswordDataList) EncodeFields ¶ added in v0.0.29
func (s *PasswordDataList) EncodeFields(_ fmt.FieldWriter)
func (*PasswordDataList) IsNil ¶ added in v0.0.29
func (s *PasswordDataList) IsNil() bool
func (*PasswordDataList) Len ¶ added in v0.0.29
func (s *PasswordDataList) Len() int
func (*PasswordDataList) Pointers ¶ added in v0.0.29
func (s *PasswordDataList) Pointers() []any
func (*PasswordDataList) Schema ¶ added in v0.0.29
func (s *PasswordDataList) Schema() []fmt.Field
type Permission ¶ added in v0.0.6
orm:typed_fields
func ReadOnePermission ¶ added in v0.0.6
func ReadOnePermission(qb *orm.QB, model *Permission) (*Permission, error)
func (*Permission) DecodeFields ¶ added in v0.0.29
func (m *Permission) DecodeFields(r fmt.FieldReader)
func (*Permission) EncodeFields ¶ added in v0.0.29
func (m *Permission) EncodeFields(w fmt.FieldWriter)
func (*Permission) IsNil ¶ added in v0.0.29
func (m *Permission) IsNil() bool
func (*Permission) ModelName ¶ added in v0.0.29
func (m *Permission) ModelName() string
func (*Permission) Pointers ¶ added in v0.0.6
func (m *Permission) Pointers() []any
func (*Permission) Schema ¶ added in v0.0.6
func (m *Permission) Schema() []fmt.Field
type PermissionList ¶ added in v0.0.29
type PermissionList []*Permission
func ReadAllPermission ¶ added in v0.0.6
func ReadAllPermission(qb *orm.QB) (PermissionList, error)
func (*PermissionList) Append ¶ added in v0.0.29
func (s *PermissionList) Append() fmt.Fielder
func (*PermissionList) DecodeFields ¶ added in v0.0.29
func (s *PermissionList) DecodeFields(_ fmt.FieldReader)
func (*PermissionList) EncodeFields ¶ added in v0.0.29
func (s *PermissionList) EncodeFields(_ fmt.FieldWriter)
func (*PermissionList) IsNil ¶ added in v0.0.29
func (s *PermissionList) IsNil() bool
func (*PermissionList) Len ¶ added in v0.0.29
func (s *PermissionList) Len() int
func (*PermissionList) Pointers ¶ added in v0.0.29
func (s *PermissionList) Pointers() []any
func (*PermissionList) Schema ¶ added in v0.0.29
func (s *PermissionList) Schema() []fmt.Field
type ProfileData ¶ added in v0.0.2
ProfileData is validated by ProfileModule (name/phone update).
func (*ProfileData) DecodeFields ¶ added in v0.0.29
func (m *ProfileData) DecodeFields(r fmt.FieldReader)
func (*ProfileData) EncodeFields ¶ added in v0.0.29
func (m *ProfileData) EncodeFields(w fmt.FieldWriter)
func (*ProfileData) IsNil ¶ added in v0.0.29
func (m *ProfileData) IsNil() bool
func (*ProfileData) ModelName ¶ added in v0.0.29
func (m *ProfileData) ModelName() string
func (*ProfileData) Pointers ¶ added in v0.0.28
func (m *ProfileData) Pointers() []any
func (*ProfileData) Schema ¶ added in v0.0.28
func (m *ProfileData) Schema() []fmt.Field
type ProfileDataList ¶ added in v0.0.29
type ProfileDataList []*ProfileData
func (*ProfileDataList) Append ¶ added in v0.0.29
func (s *ProfileDataList) Append() fmt.Fielder
func (*ProfileDataList) DecodeFields ¶ added in v0.0.29
func (s *ProfileDataList) DecodeFields(_ fmt.FieldReader)
func (*ProfileDataList) EncodeFields ¶ added in v0.0.29
func (s *ProfileDataList) EncodeFields(_ fmt.FieldWriter)
func (*ProfileDataList) IsNil ¶ added in v0.0.29
func (s *ProfileDataList) IsNil() bool
func (*ProfileDataList) Len ¶ added in v0.0.29
func (s *ProfileDataList) Len() int
func (*ProfileDataList) Pointers ¶ added in v0.0.29
func (s *ProfileDataList) Pointers() []any
func (*ProfileDataList) Schema ¶ added in v0.0.29
func (s *ProfileDataList) Schema() []fmt.Field
type RBACObject ¶ added in v0.0.6
type RegisterData ¶ added in v0.0.2
RegisterData is validated by RegisterModule.
func (*RegisterData) DecodeFields ¶ added in v0.0.29
func (m *RegisterData) DecodeFields(r fmt.FieldReader)
func (*RegisterData) EncodeFields ¶ added in v0.0.29
func (m *RegisterData) EncodeFields(w fmt.FieldWriter)
func (*RegisterData) IsNil ¶ added in v0.0.29
func (m *RegisterData) IsNil() bool
func (*RegisterData) ModelName ¶ added in v0.0.29
func (m *RegisterData) ModelName() string
func (*RegisterData) Pointers ¶ added in v0.0.28
func (m *RegisterData) Pointers() []any
func (*RegisterData) Schema ¶ added in v0.0.28
func (m *RegisterData) Schema() []fmt.Field
type RegisterDataList ¶ added in v0.0.29
type RegisterDataList []*RegisterData
func (*RegisterDataList) Append ¶ added in v0.0.29
func (s *RegisterDataList) Append() fmt.Fielder
func (*RegisterDataList) DecodeFields ¶ added in v0.0.29
func (s *RegisterDataList) DecodeFields(_ fmt.FieldReader)
func (*RegisterDataList) EncodeFields ¶ added in v0.0.29
func (s *RegisterDataList) EncodeFields(_ fmt.FieldWriter)
func (*RegisterDataList) IsNil ¶ added in v0.0.29
func (s *RegisterDataList) IsNil() bool
func (*RegisterDataList) Len ¶ added in v0.0.29
func (s *RegisterDataList) Len() int
func (*RegisterDataList) Pointers ¶ added in v0.0.29
func (s *RegisterDataList) Pointers() []any
func (*RegisterDataList) Schema ¶ added in v0.0.29
func (s *RegisterDataList) Schema() []fmt.Field
type Role ¶ added in v0.0.6
orm:typed_fields
func (*Role) DecodeFields ¶ added in v0.0.29
func (m *Role) DecodeFields(r fmt.FieldReader)
func (*Role) EncodeFields ¶ added in v0.0.29
func (m *Role) EncodeFields(w fmt.FieldWriter)
type RoleList ¶ added in v0.0.29
type RoleList []*Role
func (*RoleList) DecodeFields ¶ added in v0.0.29
func (s *RoleList) DecodeFields(_ fmt.FieldReader)
func (*RoleList) EncodeFields ¶ added in v0.0.29
func (s *RoleList) EncodeFields(_ fmt.FieldWriter)
type RolePermission ¶ added in v0.0.6
type RolePermission struct {
RoleID string `db:"pk,ref=roles"`
PermissionID string `db:"pk,ref=permissions"`
}
orm:typed_fields
func ReadOneRolePermission ¶ added in v0.0.6
func ReadOneRolePermission(qb *orm.QB, model *RolePermission) (*RolePermission, error)
func (*RolePermission) DecodeFields ¶ added in v0.0.29
func (m *RolePermission) DecodeFields(r fmt.FieldReader)
func (*RolePermission) EncodeFields ¶ added in v0.0.29
func (m *RolePermission) EncodeFields(w fmt.FieldWriter)
func (*RolePermission) IsNil ¶ added in v0.0.29
func (m *RolePermission) IsNil() bool
func (*RolePermission) ModelName ¶ added in v0.0.29
func (m *RolePermission) ModelName() string
func (*RolePermission) Pointers ¶ added in v0.0.6
func (m *RolePermission) Pointers() []any
func (*RolePermission) Schema ¶ added in v0.0.6
func (m *RolePermission) Schema() []fmt.Field
type RolePermissionList ¶ added in v0.0.29
type RolePermissionList []*RolePermission
func ReadAllRolePermission ¶ added in v0.0.6
func ReadAllRolePermission(qb *orm.QB) (RolePermissionList, error)
func (*RolePermissionList) Append ¶ added in v0.0.29
func (s *RolePermissionList) Append() fmt.Fielder
func (*RolePermissionList) DecodeFields ¶ added in v0.0.29
func (s *RolePermissionList) DecodeFields(_ fmt.FieldReader)
func (*RolePermissionList) EncodeFields ¶ added in v0.0.29
func (s *RolePermissionList) EncodeFields(_ fmt.FieldWriter)
func (*RolePermissionList) IsNil ¶ added in v0.0.29
func (s *RolePermissionList) IsNil() bool
func (*RolePermissionList) Len ¶ added in v0.0.29
func (s *RolePermissionList) Len() int
func (*RolePermissionList) Pointers ¶ added in v0.0.29
func (s *RolePermissionList) Pointers() []any
func (*RolePermissionList) Schema ¶ added in v0.0.29
func (s *RolePermissionList) Schema() []fmt.Field
type SecurityEvent ¶ added in v0.0.22
type SecurityEventType ¶ added in v0.0.22
type SecurityEventType uint8
const ( EventJWTTampered SecurityEventType = iota // ValidateJWT: HMAC mismatch EventOAuthReplay // consumeState: state already consumed (2nd use) EventOAuthExpiredState // consumeState: state found but past ExpiresAt EventOAuthCrossProvider // consumeState: provider mismatch (state preserved) EventIPMismatch // LoginLAN: IP not registered EventNonActiveAccess // Login/LoginLAN: status != "active" EventAccessDenied // AccessCheck: RBAC denied with valid session )
type Session ¶ added in v0.0.2
type Session struct {
ID string `db:"pk"`
UserID string `db:"ref=users"`
ExpiresAt int64
IP string
UserAgent string
CreatedAt int64
}
orm:typed_fields
func ReadOneSession ¶ added in v0.0.6
func (*Session) DecodeFields ¶ added in v0.0.29
func (m *Session) DecodeFields(r fmt.FieldReader)
func (*Session) EncodeFields ¶ added in v0.0.29
func (m *Session) EncodeFields(w fmt.FieldWriter)
type SessionList ¶ added in v0.0.29
type SessionList []*Session
func ReadAllSession ¶ added in v0.0.6
func ReadAllSession(qb *orm.QB) (SessionList, error)
func (*SessionList) Append ¶ added in v0.0.29
func (s *SessionList) Append() fmt.Fielder
func (*SessionList) DecodeFields ¶ added in v0.0.29
func (s *SessionList) DecodeFields(_ fmt.FieldReader)
func (*SessionList) EncodeFields ¶ added in v0.0.29
func (s *SessionList) EncodeFields(_ fmt.FieldWriter)
func (*SessionList) IsNil ¶ added in v0.0.29
func (s *SessionList) IsNil() bool
func (*SessionList) Len ¶ added in v0.0.29
func (s *SessionList) Len() int
func (*SessionList) Pointers ¶ added in v0.0.29
func (s *SessionList) Pointers() []any
func (*SessionList) Schema ¶ added in v0.0.29
func (s *SessionList) Schema() []fmt.Field
type User ¶
type User struct {
ID string `db:"pk"`
Email string `db:"unique"`
Name string
Phone string
Status string // "active", "suspended"
CreatedAt int64
Roles []Role `db:"-"`
Permissions []Permission `db:"-"`
}
orm:typed_fields
func (*User) DecodeFields ¶ added in v0.0.29
func (m *User) DecodeFields(r fmt.FieldReader)
func (*User) EncodeFields ¶ added in v0.0.29
func (m *User) EncodeFields(w fmt.FieldWriter)
type UserList ¶ added in v0.0.29
type UserList []*User
func (*UserList) DecodeFields ¶ added in v0.0.29
func (s *UserList) DecodeFields(_ fmt.FieldReader)
func (*UserList) EncodeFields ¶ added in v0.0.29
func (s *UserList) EncodeFields(_ fmt.FieldWriter)
type UserRole ¶ added in v0.0.6
orm:typed_fields
func ReadOneUserRole ¶ added in v0.0.6
func (*UserRole) DecodeFields ¶ added in v0.0.29
func (m *UserRole) DecodeFields(r fmt.FieldReader)
func (*UserRole) EncodeFields ¶ added in v0.0.29
func (m *UserRole) EncodeFields(w fmt.FieldWriter)
type UserRoleList ¶ added in v0.0.29
type UserRoleList []*UserRole
func ReadAllUserRole ¶ added in v0.0.6
func ReadAllUserRole(qb *orm.QB) (UserRoleList, error)
func (*UserRoleList) Append ¶ added in v0.0.29
func (s *UserRoleList) Append() fmt.Fielder
func (*UserRoleList) DecodeFields ¶ added in v0.0.29
func (s *UserRoleList) DecodeFields(_ fmt.FieldReader)
func (*UserRoleList) EncodeFields ¶ added in v0.0.29
func (s *UserRoleList) EncodeFields(_ fmt.FieldWriter)
func (*UserRoleList) IsNil ¶ added in v0.0.29
func (s *UserRoleList) IsNil() bool
func (*UserRoleList) Len ¶ added in v0.0.29
func (s *UserRoleList) Len() int
func (*UserRoleList) Pointers ¶ added in v0.0.29
func (s *UserRoleList) Pointers() []any
func (*UserRoleList) Schema ¶ added in v0.0.29
func (s *UserRoleList) Schema() []fmt.Field
Source Files
¶
- api_token_back.go
- auth.go
- cache.go
- cache_users.go
- crud.go
- generate.go
- google.go
- identities.go
- jwt_back.go
- lan.go
- lan_ips.go
- microsoft.go
- middleware_back.go
- migrate.go
- models.go
- models_crud_back.go
- models_orm.go
- module_lan.go
- module_lan_back.go
- module_login.go
- module_login_back.go
- module_oauth.go
- module_oauth_back.go
- module_profile.go
- module_profile_back.go
- module_register.go
- module_register_back.go
- modules.go
- oauth.go
- sessions.go
- sql.go
- user.go
- user_back.go
- user_rbac_mutations.go