auth

package
v0.0.0-...-ed588b7 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSigningMethod = jwt.SigningMethodHS256
View Source
var ErrInvalidToken = errors.New("invalid token")
View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrUnauthorized = errors.New("unauthorized")

Functions

This section is empty.

Types

type Claims

type Claims struct {
	UserID uuid.UUID `json:"user_id"`
	Type   Type      `json:"type"`

	jwt.StandardClaims
}

type Repo

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

func NewRepository

func NewRepository(db *sqlx.DB) *Repo

func (*Repo) Create

func (r *Repo) Create(token *Token) error

func (*Repo) Get

func (r *Repo) Get(id uuid.UUID) (*Token, error)

type Repository

type Repository interface {
	Create(token *Token) error
	Get(id uuid.UUID) (*Token, error)
}

type Service

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

func NewService

func NewService(method jwt.SigningMethod, secret string, accessTokenTTL time.Duration, repo Repository) *Service

func (*Service) FetchToken

func (s *Service) FetchToken(token string) (*Token, error)

func (*Service) IssueAccessToken

func (s *Service) IssueAccessToken(refreshTokenID uuid.UUID, userID uuid.UUID) (token *Token, signedToken string, err error)

func (*Service) IssueRefreshToken

func (s *Service) IssueRefreshToken(userID uuid.UUID) (token *Token, signedToken string, err error)

type Token

type Token struct {
	ID uuid.UUID `db:"id"`

	Type Type `db:"type"`

	ParentID *uuid.UUID `db:"parent_id"`

	IssuedAt  time.Time  `db:"issued_at"`
	ExpiresAt *time.Time `db:"expires_at"`

	UserID uuid.UUID `db:"user_id"`
}

func (*Token) IsExpired

func (t *Token) IsExpired() bool

type Type

type Type string
const (
	TypeRefreshToken Type = "REFRESH_TOKEN"
	TypeAccessToken  Type = "ACCESS_TOKEN"
)

Jump to

Keyboard shortcuts

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