auth

package
v0.0.0-...-10b8bc0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const SessionTokenAgeInMinutes = 60
View Source
const TokenAgeInMinutes = 5

Variables

View Source
var (
	ErrInvalidToken = errors.New("token is invalid")
	ErrExpiredToken = errors.New("token is expired")
)

Functions

func CreateSession

func CreateSession(email string, userAgent string, clientIP string) (*models.Session, error)

func GetCurrentUser

func GetCurrentUser() string

func Login

func Login(ctx *gin.Context)

func RefreshSession

func RefreshSession(ctx *gin.Context)

func SetCurrentUser

func SetCurrentUser(username string)

func SignUp

func SignUp(ctx *gin.Context)

Types

type JWTMaker

type JWTMaker struct {
	SecretKey string
}

func (*JWTMaker) CreateToken

func (jwtMaker *JWTMaker) CreateToken(username string, duration time.Duration) (string, error)

func (*JWTMaker) VerifyToken

func (jwtMaker *JWTMaker) VerifyToken(token string) (*Payload, error)

type PasetoMaker

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

func (*PasetoMaker) CreateToken

func (pasetoMaker *PasetoMaker) CreateToken(username string, duration time.Duration) (string, error)

func (*PasetoMaker) VerifyToken

func (pasetoMaker *PasetoMaker) VerifyToken(token string) (*Payload, error)

type Payload

type Payload struct {
	Id        uuid.UUID `json:"id"`
	Username  string    `json:"username"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

func NewPayload

func NewPayload(username string, duration time.Duration) *Payload

func (*Payload) Valid

func (payload *Payload) Valid() error

type TokenMaker

type TokenMaker interface {
	CreateToken(username string, duration time.Duration) (string, error)
	VerifyToken(token string) (*Payload, error)
}

func NewJWTMaker

func NewJWTMaker(secretKey string) (TokenMaker, error)

func NewPasetoMaker

func NewPasetoMaker() (TokenMaker, error)

Jump to

Keyboard shortcuts

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