Documentation
¶
Index ¶
- func Handler(verificationKey string) echo.MiddlewareFunc
- func IsAuthenticated(authHandler echo.MiddlewareFunc) echo.MiddlewareFunc
- func RegisterHandlers(g *echo.Group, service Service, logger log.Logger)
- func WithUser(ctx context.Context, id string, isAdmin bool) context.Context
- type Identity
- type Securer
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(verificationKey string) echo.MiddlewareFunc
Handler returns a JWT-based authentication middleware.
func IsAuthenticated ¶
func IsAuthenticated(authHandler echo.MiddlewareFunc) echo.MiddlewareFunc
IsAuthenticated middleware checks if a user is authenticated. If not, it calls the next handler HTTP. If yes, it validates the JWT token and returns an error if token is invalid.
func RegisterHandlers ¶
RegisterHandlers registers handlers for different HTTP requests.
Types ¶
type Identity ¶
type Identity interface {
// ID returns the user ID.
ID() string
// IsAdmin return true if the user have admin priviliges.
IsAdmin() bool
}
Identity represents an authenticated user identity.
func CurrentUser ¶
CurrentUser returns the user identity from the given context. Nil is returned if no user identity is found in the context.
type Service ¶
type Service interface {
// authenticate authenticates a user using username and password.
// It returns a JWT token if authentication succeeds. Otherwise, an error is returned.
Login(ctx context.Context, username, password string) (string, error)
}
Service encapsulates the authentication logic.
Click to show internal directories.
Click to hide internal directories.