Documentation
¶
Index ¶
- func AddUserToContext(ctx context.Context, userID int, isAdmin bool, isAPIClient bool) context.Context
- func GenerateJWT(userID int, isAdmin bool) (string, error)
- func GenerateRefreshToken() (string, error)
- func GenerateToken(userID int, isAdmin bool, expiration time.Duration) (string, error)
- func GetUserID(ctx context.Context) (int, bool)
- func InitAuth(secret []byte, db *db.DB)
- func IsAPIClient(ctx context.Context) bool
- func IsAPIClientKey() contextKey
- func IsAdmin(ctx context.Context) bool
- func IsAdminKey() contextKey
- func IsOriginAllowed(corsType CORSType, origin string) bool
- func RefreshJWT(refreshToken string) (string, int, bool, error)
- func UserIDKey() contextKey
- func WithAuth(authType AuthType, next http.HandlerFunc) http.HandlerFunc
- func WithCORS(next http.HandlerFunc) http.HandlerFunc
- func WithCORSType(corsType CORSType, next http.HandlerFunc) http.HandlerFunc
- func WithLogging(next http.HandlerFunc) http.HandlerFunc
- type AuthType
- type CORSType
- type Claims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddUserToContext ¶
func AddUserToContext(ctx context.Context, userID int, isAdmin bool, isAPIClient bool) context.Context
AddUserToContext adds user information to the request context
func GenerateJWT ¶
GenerateJWT creates a new JWT token for a user with a short expiration time (15 minutes)
func GenerateRefreshToken ¶
GenerateRefreshToken creates a new refresh token for a user
func GenerateToken ¶
GenerateToken generates a JWT token for the given user ID
func IsAPIClient ¶
IsAPIClient checks if the request is from an API client
func IsAPIClientKey ¶
func IsAPIClientKey() contextKey
IsAPIClientKey returns the context key for API client status
func IsOriginAllowed ¶
IsOriginAllowed checks if the given origin is allowed for the specified CORS type
func RefreshJWT ¶
RefreshJWT refreshes a JWT token using a valid refresh token
func WithAuth ¶
func WithAuth(authType AuthType, next http.HandlerFunc) http.HandlerFunc
WithAuth middleware checks for authentication based on the specified type
func WithCORS ¶
func WithCORS(next http.HandlerFunc) http.HandlerFunc
WithCORS adds CORS headers to responses
func WithCORSType ¶
func WithCORSType(corsType CORSType, next http.HandlerFunc) http.HandlerFunc
WithCORSType adds CORS headers to responses with specific CORS configuration
func WithLogging ¶
func WithLogging(next http.HandlerFunc) http.HandlerFunc
WithLogging adds request logging
Types ¶
type AuthType ¶
type AuthType int
AuthType represents the type of authentication
const ( // AuthTypeNone means no authentication required AuthTypeNone AuthType = iota // AuthTypeFrontend means frontend authentication required (JWT) AuthTypeFrontend // AuthTypeAPI means API key authentication required AuthTypeAPI // AuthTypeAny means either frontend or API authentication is acceptable AuthTypeAny )