auth

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const UserSessionName = "user_session"

UserSessionName is the shared session cookie name used by all auth providers

Variables

This section is empty.

Functions

func GetUserIdFromSession

func GetUserIdFromSession(session *sessions.Session) (string, bool)

GetUserIdFromSession extracts the unified userId from session

func IsAuthenticated

func IsAuthenticated(session *sessions.Session) bool

IsAuthenticated checks if the session has valid authentication

Types

type AuthProvider

type AuthProvider interface {
	// GetName returns the authentication mode name (e.g., "email", "token")
	GetName() string

	// RegisterRoutes registers authentication-related routes
	RegisterRoutes(router *gin.RouterGroup)
}

AuthProvider defines the interface for authentication providers

type AuthProviderBase

type AuthProviderBase struct {
	// contains filtered or unexported fields
}

AuthProviderBase provides common functionality for auth providers

type EmailAuthProvider

type EmailAuthProvider struct {
	AuthProviderBase
	// contains filtered or unexported fields
}

EmailAuthProvider implements email-based authentication

func NewEmailAuthProvider

func NewEmailAuthProvider(cfg *config.Config, store sessions.Store) *EmailAuthProvider

NewEmailAuthProvider creates a new email authentication provider

func (*EmailAuthProvider) GetName

func (p *EmailAuthProvider) GetName() string

GetName returns "email"

func (*EmailAuthProvider) RegisterRoutes

func (p *EmailAuthProvider) RegisterRoutes(router *gin.RouterGroup)

RegisterRoutes registers email authentication routes

type Login

type Login struct {
	Email string `form:"email" json:"email" xml:"email" binding:"required,email"`
	Code  string `form:"code" json:"code" xml:"password" binding:"omitempty,numeric,len=6"`
}

Login represents the request body for email login

type TokenAuthProvider

type TokenAuthProvider struct {
	AuthProviderBase
	// contains filtered or unexported fields
}

TokenAuthProvider implements token-based authentication

func NewTokenAuthProvider

func NewTokenAuthProvider(cfg *config.Config, store sessions.Store) *TokenAuthProvider

NewTokenAuthProvider creates a new token authentication provider

func (*TokenAuthProvider) GetName

func (p *TokenAuthProvider) GetName() string

GetName returns "token"

func (*TokenAuthProvider) RegisterRoutes

func (p *TokenAuthProvider) RegisterRoutes(router *gin.RouterGroup)

RegisterRoutes registers token authentication routes

type TokenRequest

type TokenRequest struct {
	Token string `form:"token" json:"token" binding:"required,len=6"`
}

TokenRequest represents the request body for token operations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL