token

package
v0.0.0-...-4db5c07 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package token содержит реализацию генерации и проверки паролей. А также интерфейс для взаимодействия с этим модулем.

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type IMaker

type IMaker interface {
	// Create создаёт токен для переданных id пользователя и продолжительности.
	Create(userID int, duration time.Duration) (string, error)

	// Verify проверяет, является ли токен действительным.
	Verify(in string) (*Payload, error)
}

IMaker абстракция для управления токенами.

func NewPasetoMaker

func NewPasetoMaker(symmetricKey string) (IMaker, error)

NewPasetoMaker возвращает IMaker для взаимодействия.

type PasetoMaker

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

PasetoMaker реализация создателя токенов типа PaseTo.

func (*PasetoMaker) Create

func (m *PasetoMaker) Create(userID int, duration time.Duration) (string, error)

Create создаёт токен для переданных id пользователя и продолжительности.

func (*PasetoMaker) Verify

func (m *PasetoMaker) Verify(in string) (*Payload, error)

Verify проверяет, является ли токен действительным.

type Payload

type Payload struct {
	UserID    int       `json:"user_id"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiredAt time.Time `json:"expired_at"`
}

Payload содержит полезную нагрузку для токена.

func NewPayload

func NewPayload(userID int, duration time.Duration) (*Payload, error)

NewPayload создаёт объект Payload.

func (*Payload) Valid

func (payload *Payload) Valid() error

Valid - проверяет валидность токена.

Jump to

Keyboard shortcuts

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