Documentation
¶
Index ¶
- Constants
- func CheckPassword(hash *string, pwd string) bool
- func HashPassword(pwd string) (string, error)
- func NewAuthKey(kind, value string) string
- func NewCtx(ctx context.Context, reqCtx ReqCtx) context.Context
- func SplitAuthKey(key string) (kind, value string)
- func ValidateAuthKey(key string) error
- type App
- type Auth
- type ConfLoader
- type M
- type ReqCtx
- type Session
- type User
- type UserData
- type UserRegistry
Constants ¶
const ( KeyKindID = "id" KeyKindEmail = "email" KeyKindUsername = "username" )
AuthKey kinds.
Variables ¶
This section is empty.
Functions ¶
func CheckPassword ¶
CheckPassword returns true if the given password matches the hashed value of the password in the user object. Returns false if mismatch or no password is set for user.
func HashPassword ¶
HashPassword hashes and returns the PwdHash value.
func NewAuthKey ¶
NewAuthKey returns a new formatted user login-key.
func SplitAuthKey ¶
SplitAuthKey splits the given key-id into its kind and actual value.
func ValidateAuthKey ¶
ValidateAuthKey checks the validity of the login-key.
Types ¶
type App ¶
type App interface {
DB() *pgx.Conn
Auth() Auth
Router() chi.Router
Configs() ConfLoader
UserRegistries() map[string]UserRegistry
}
type Auth ¶
type Auth interface {
CreateSession(ctx context.Context, u User) (*Session, string, error)
RestoreSession(ctx context.Context, token string) (*Session, error)
}
Auth module provides facilities for issuing tokens, verifying tokens, etc.
type ConfLoader ¶
type ConfLoader interface {
Int(key string, defVal int) int
Bool(key string, defVal bool) bool
String(key string, defVal string) string
Strings(key string, defVal []string) []string
Float64(key string, defVal float64) float64
Duration(key string, defVal time.Duration) time.Duration
}
ConfLoader is responsible for loading configurations during initial setup.
type ReqCtx ¶
type ReqCtx struct {
Session *Session
Path string
Method string
RequestID string
RemoteAddr string
}
ReqCtx represents the context for the current request.
func (ReqCtx) Authenticated ¶
Authenticated returns true if rc contains authenticated user.
type Session ¶
type Session struct {
ID string
UserID string
UserKind string
CreatedAt time.Time
ExpiresAt time.Time
}
Session represents a user-session.
type User ¶
type User struct {
ID string `json:"id"`
Kind string `json:"kind"`
Data UserData `json:"data"`
Email string `json:"email"`
PwdHash *string `json:"pwd_hash,omitempty"`
Username string `json:"username"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
VerifiedAt *time.Time `json:"verified_at"`
VerifyToken *string `json:"verify_token,omitempty"`
Attributes map[string]any `json:"-"`
}
User represents a registered user in the system.
type UserData ¶
UserData represents the standard user profile data. Refer https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
type UserRegistry ¶
type UserRegistry interface {
User(ctx context.Context, key string) (*User, error)
Verify(ctx context.Context, uid, token string) (*User, error)
SetPwd(ctx context.Context, uid string, pwd string) error
SetData(ctx context.Context, uid string, data UserData) error
Register(ctx context.Context, u User) (*User, error)
}
UserRegistry provides facilities for managing users.