auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: Apache-2.0 Imports: 13 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)

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 Securer

type Securer interface {
	HashMatchesPassword(string, string) bool
}

Securer represents security interface.

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.

func NewService

func NewService(signingKey string, tokenExpiration int,
	logger log.Logger, sec Securer, userSvc user.Service) 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