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, mailer Mailer, ...)
- func WithSource(ctx context.Context, src string) context.Context
- func WithUser(ctx context.Context, id string, isAdmin bool) context.Context
- type Identity
- type LoginResponse
- type Mailer
- type ResendConfirmationResponse
- type ResetPasswordResponse
- 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 ¶
func RegisterHandlers(g *echo.Group, service Service, logger log.Logger, mailer Mailer, templater tpl.Service, UIAddress string)
RegisterHandlers registers handlers for different HTTP requests.
func WithSource ¶ added in v0.4.0
WithSource returns a context that contains the source of the HTTP request.
Types ¶
type Identity ¶
type Identity interface { // ID returns the user ID. ID() string // IsAdmin return true if the user have admin privileges. 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 LoginResponse ¶ added in v0.5.0
type LoginResponse struct {
// contains filtered or unexported fields
}
type ResendConfirmationResponse ¶ added in v0.4.0
type ResendConfirmationResponse struct {
// contains filtered or unexported fields
}
type ResetPasswordResponse ¶ added in v0.3.0
type ResetPasswordResponse struct {
// contains filtered or unexported fields
}
type Service ¶
type Service interface { // Login authenticates a user using username or email and a password. // It returns a JWT token if authentication succeeds. Otherwise, an error is returned. Login(ctx context.Context, usernameOrEmail, password string) (LoginResponse, error) // reset password generates a password reset token. The hash of the token // is stored in the database, a GUID is also generated to retrieve the // document when the user send the new password from the html form. ResetPassword(ctx context.Context, email string) (ResetPasswordResponse, error) // VerifyAccount confirms the user account by verifying the token. VerifyAccount(ctx context.Context, id, token string) error // create a new password if the user has already a reset password token. CreateNewPassword(ctx context.Context, id, token, password string) error // resend a new confirmation email for the user's account. ResendConfirmation(ctx context.Context, email string) (ResendConfirmationResponse, error) }
Service encapsulates the authentication logic.
Click to show internal directories.
Click to hide internal directories.