Documentation
¶
Index ¶
- Variables
- func ContextWithLoginfy(ctx context.Context, loginfyCtx *Context) context.Context
- type Context
- type Hooks
- type Loginfy
- func (l *Loginfy) Authenticate(strategyName string, ctx *Context) (*User, error)
- func (l *Loginfy) GetSessionManager() SessionManager
- func (l *Loginfy) GetStorage() Storage
- func (l *Loginfy) GetStrategy(name string) (Strategy, bool)
- func (l *Loginfy) Login(user *User) (string, error)
- func (l *Loginfy) Logout(ctx *Context, token string) error
- func (l *Loginfy) Mount() func(http.Handler) http.Handler
- func (l *Loginfy) SetHooks(hooks Hooks)
- func (l *Loginfy) SetSessionManager(session SessionManager)
- func (l *Loginfy) SetStorage(storage Storage)
- func (l *Loginfy) Use(strategy Strategy)
- type OAuthConfig
- type OAuthProvider
- type SessionManager
- type Storage
- type Strategy
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrStrategyNotFound = errors.New("authentication strategy not found") ErrSessionManagerNotSet = errors.New("session manager not configured") ErrStorageNotSet = errors.New("storage not configured") ErrInsufficientRole = errors.New("insufficient role permissions") ErrInsufficientPermission = errors.New("insufficient permissions") )
Common errors
Functions ¶
Types ¶
type Context ¶
type Context struct {
Request *http.Request
Response http.ResponseWriter
Loginfy *Loginfy
RequestID string // unique identifier for this request
// contains filtered or unexported fields
}
Context holds the request context for authentication operations
func LoginfyFromContext ¶
LoginfyFromContext retrieves the Loginfy context from the request context
type Loginfy ¶
type Loginfy struct {
// contains filtered or unexported fields
}
Loginfy is the main authentication framework instance
func (*Loginfy) Authenticate ¶
Authenticate performs authentication using the specified strategy
func (*Loginfy) GetSessionManager ¶
func (l *Loginfy) GetSessionManager() SessionManager
GetSessionManager returns the session manager
func (*Loginfy) GetStorage ¶
GetStorage returns the storage adapter
func (*Loginfy) GetStrategy ¶
GetStrategy retrieves a registered strategy by name
func (*Loginfy) Mount ¶
Mount returns an HTTP middleware that integrates Loginfy with your HTTP framework This middleware creates a Loginfy context for each request
func (*Loginfy) SetSessionManager ¶
func (l *Loginfy) SetSessionManager(session SessionManager)
SetSessionManager sets the session manager
func (*Loginfy) SetStorage ¶
SetStorage sets the storage adapter
type OAuthConfig ¶
OAuthConfig holds common OAuth configuration
type OAuthProvider ¶
type OAuthProvider interface {
Strategy
// AuthURL returns the URL to redirect the user to for authentication
AuthURL(state string) string
// HandleCallback processes the OAuth callback and returns the authenticated user
HandleCallback(ctx *Context) (*User, error)
// ProviderName returns the OAuth provider name (e.g., "google", "github")
ProviderName() string
}
OAuthProvider extends Strategy with OAuth-specific methods
type SessionManager ¶
type User ¶
type User struct {
ID string `json:"id" bson:"_id,omitempty"`
Email string `json:"email" bson:"email"`
Password string `json:"-" bson:"password"` // Never serialize password in JSON
Roles []string `json:"roles" bson:"roles"`
Metadata map[string]interface{} `json:"metadata,omitempty" bson:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}
User represents an authenticated user in the system
func (*User) HasAnyRole ¶
HasAnyRole checks if the user has any of the specified roles