auth

package
v0.0.0-...-b2c82e1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JWTAuthMiddleware

func JWTAuthMiddleware(verificationKey string) echo.MiddlewareFunc

JWTAuthMiddleware returns a JWT-based authentication middleware.

func RegisterHandlers

func RegisterHandlers(rg *echo.Group, service Service, logger log.Logger)

RegisterHandlers registers handlers for different HTTP requests.

func WithUser

func WithUser(ctx echo.Context, token *jwt.Token)

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

Types

type AccountGetter

type AccountGetter interface {
	Get(ctx context.Context, username, password string) (entity.Account, error)
	GetByUsername(ctx context.Context, username string) (entity.Account, error)
}

type LoginRequest

type LoginRequest struct {
	// Username the username to authenticate with. Length has to be between 5 and
	// 128 characters.
	Username string `json:"username"`
	// Password password to authenticate with. Length has to be between 5 and
	// 128 characters.
	Password string `json:"password"`
}

LoginRequest authentication login input request.

func (*LoginRequest) Validate

func (r *LoginRequest) Validate() *response.Error

Validate validates the LoginRequest struct.

type LoginResponse

type LoginResponse struct {
	// AccessToken the token to be used on authenticated requests.
	AccessToken string `json:"token"`
	// RefreshToken the token to be used to refresh the access token.
	RefreshToken string `json:"refresh_token,omitempty"`
}

LoginResponse authentication login output response.

type RefreshRequest

type RefreshRequest struct {
	// RefreshToken the token to be used to refresh the access token.
	RefreshToken string `json:"refresh_token"`
}

RefreshRequest refresh your JWT token.

func (*RefreshRequest) Validate

func (r *RefreshRequest) Validate() *response.Error

Validate validates the LoginRequest struct

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) (LoginResponse, error)

	Refresh(c context.Context, token string) (LoginResponse, error)
}

Service encapsulates the authentication logic.

func NewService

func NewService(cfg *config.Config, ar AccountGetter, appRepo app.Repository, logger log.Logger) 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