Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface {
// Router returns the underlying fiber app.
Router() *fiber.App
// StartSession starts a new session for a user. It returns the session ID.
StartSession(ctx *fasthttp.RequestCtx, values ...SessionValue) (string, error)
// EndSession ends the specified session. It returns an error if the session does not exist.
EndSession(ctx *fasthttp.RequestCtx, sessionID string) error
// IsValidSessionID checks if the specified session ID is valid (i.e., it corresponds to an active session).
IsValidSessionID(ctx *fasthttp.RequestCtx, sessionID string) bool
// GetSession retrieves the session information for a session ID. It returns an error if the session does not exist.
GetSession(ctx *fasthttp.RequestCtx, sessionID string) (*Session, error)
// Serve serves the fiber app.
Serve()
}
Authenticator represents the interface for session-based authentication.
func NewAuthenticator ¶
func NewAuthenticator() Authenticator
NewAuthenticator returns a new Authenticator instance. It also initializes the underlying fiber app. this is used to have authenticated routes.
type Session ¶
type Session struct {
UserAlias string
Credential string
Address string
IsMobile bool
Did string
Name string
Days string
Secret string
}
Session represents an authenticated session. In a real application, this might include additional fields such as the user ID, the session expiry time, etc.
func LoadSession ¶
LoadSession gets all the session values and verifies their types.
type SessionValue ¶
type SessionValue func(s *Session)
func WithAddress ¶
func WithAddress(address string) SessionValue
func WithCredential ¶
func WithCredential(credential []byte) SessionValue
func WithDid ¶
func WithDid(did string) SessionValue
func WithIsMobile ¶
func WithIsMobile(isMobile bool) SessionValue
func WithUserAlias ¶
func WithUserAlias(alias string) SessionValue
Click to show internal directories.
Click to hide internal directories.