Documentation ¶
Index ¶
- Constants
- Variables
- 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 Auth
- type ConfLoader
- type M
- type Middleware
- type ReqCtx
- type Session
- type User
- type UserData
- type UserKey
- type UserRegistry
Constants ¶
const ( KeyKindID = "id" KeyKindEmail = "email" KeyKindUsername = "username" )
AuthKey kinds.
Variables ¶
var ReqCtxKey = "forge:req_ctx"
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 Auth ¶
Auth implementation is responsible for validating access tokens and restoring user-session from it.
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 Middleware ¶ added in v0.2.0
Middleware is convenience type for http middlewares.
type ReqCtx ¶
type ReqCtx struct { Path string Route string Method string Session *Session 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 { User User `json:"user"` Token string `json:"token"` Expiry time.Time `json:"expiry"` }
Session represents a login-session for the contained user.
type User ¶
type User struct { ID string `json:"id"` Data UserData `json:"data"` Email string `json:"email"` PwdHash *string `json:"pwd_hash,omitempty"` Username string `json:"username,omitempty"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` VerifiedAt *time.Time `json:"verified_at,omitempty"` 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