auth

package
v0.0.0-...-187a358 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExpiredRefreshToken = errors.New("auth: can not refresh auth token, refresh token is expired")
View Source
var ErrInvalidCredentials = errors.New("auth: can not authenticate, invalid email or password")

Functions

This section is empty.

Types

type AuthenticationToken

type AuthenticationToken struct {
	Token string
	Type  string
}

type Cipher

type Cipher struct {
}

func (Cipher) ComparePasswords

func (c Cipher) ComparePasswords(hashedPwd, plainPwd string) bool

func (Cipher) GenerateHash

func (c Cipher) GenerateHash(pwd string) (string, error)

type Handler

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

func NewHandler

func NewHandler(userRepo user.Repository, cipher Cipher, params Params) *Handler

func (Handler) AdminMiddleware

func (h Handler) AdminMiddleware() gin.HandlerFunc

func (Handler) Authenticate

func (h Handler) Authenticate(email, password string) (AuthenticationToken, error)

func (Handler) GenerateRefreshToken

func (h Handler) GenerateRefreshToken(email string) (RefreshToken, error)

func (Handler) Middleware

func (h Handler) Middleware() gin.HandlerFunc

func (Handler) Refresh

func (h Handler) Refresh(token string) (AuthenticationToken, error)

func (Handler) UserFromContext

func (h Handler) UserFromContext(c *gin.Context) (User, error)

type JWTClaim

type JWTClaim struct {
	Email string `json:"email"`
	jwt.RegisteredClaims
}

type Params

type Params struct {
	AuthTTL    time.Duration
	RefreshTTL time.Duration
	Secret     string
}

type RefreshToken

type RefreshToken struct {
	Token string
}

type User

type User struct {
	ID    string
	Email string
	Role  user.Role
}

func (User) IsAdmin

func (u User) IsAdmin() bool

Jump to

Keyboard shortcuts

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