authorizations

package
v0.0.0-...-9831a62 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken = fmt.Errorf("token is invalid")
	ErrTokenExpired = fmt.Errorf("token is expired")
)

Known errors.

Functions

func NewContext

func NewContext(ctx context.Context, token *Token) context.Context

NewContext creates a new context with the token value.

Types

type Service

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

Service allows to issue and verify jwt tokens.

func NewService

func NewService(db *sql.DB, logger logger) *Service

NewService creates a new jwt service.

func (*Service) Init

func (s *Service) Init(ctx context.Context) error

Init prepares jwt service for work by generating a jwt signer.

func (*Service) NewToken

func (s *Service) NewToken(ctx context.Context, userID string) (*Token, error)

NewToken creates a new signed JWT.

func (*Service) Verify

func (s *Service) Verify(ctx context.Context, token string) (*Token, error)

Verify checks token signature and returns it's meaningful content.

type Token

type Token struct {
	Token     string    `json:"token"`
	UserID    string    `json:"user_id"`
	ExpiresAt time.Time `json:"expires_at"`
}

Token contains information about an authorized user.

func FromContext

func FromContext(ctx context.Context) (*Token, bool)

FromContext returns a token from the given context.

func MustFromContext

func MustFromContext(ctx context.Context) *Token

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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