auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

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 WithUser

func WithUser(ctx context.Context, id string, isAdmin bool) context.Context

WithUser returns a context that contains the user identity from the given JWT.

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

func CurrentUser(ctx context.Context) Identity

CurrentUser returns the user identity from the given context. Nil is returned if no user identity is found in the context.

type Mailer added in v0.3.0

type Mailer interface {
	Send(body, subject, from, to string) error
}

Mailer represents the mailer interface/

type ResetPasswordResponse added in v0.3.0

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

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)
	// 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, password, token string) error
}

Service encapsulates the authentication logic.

func NewService

func NewService(signingKey string, tokenExpiration int,
	logger log.Logger, sec secure.Password, userSvc user.Service,
	tokenGen secure.TokenGenerator) Service

NewService creates a new authentication service.

Jump to

Keyboard shortcuts

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