contract

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExp define error for expiration date
	ErrExp = errors.New("Token expired")

	// ErrNbf define error for not before date
	ErrNbf = errors.New("Token cant be use right now")

	// ErrIat define error for Issued at date
	ErrIat = errors.New("Token create from future")

	// ErrIss define error for mismatch issuer
	ErrIss = errors.New("Issuer not match")

	// ErrEmptyIss define error for empty issuer
	ErrEmptyIss = errors.New("Issuer empty")
)

Functions

This section is empty.

Types

type IToken

type IToken interface {
	Sign(ctx context.Context, payload *Payload) (string, error)
	Verify(ctx context.Context, token string) (*Payload, error)
}

IToken define interface

type Mock

type Mock struct {
	mock.Mock
}

Mock define testify/mock

func (*Mock) Sign

func (m *Mock) Sign(ctx context.Context, payload *Payload) (string, error)

Sign Mocks

func (*Mock) Verify

func (m *Mock) Verify(ctx context.Context, token string) (*Payload, error)

Verify Mocks

type Payload

type Payload struct {
	Issuer         string   `json:"iss,omitempty"`
	Subject        string   `json:"sub,omitempty"`
	Audience       []string `json:"aud,omitempty"`
	ExpirationTime *Time    `json:"exp,omitempty"`
	NotBefore      *Time    `json:"nbf,omitempty"`
	IssuedAt       *Time    `json:"iat,omitempty"`
	JWTID          string   `json:"jti,omitempty"`
}

Payload define basic JWT field

type SignAlgorithm

type SignAlgorithm string

SignAlgorithm types

const HS256 SignAlgorithm = "HS365"

HS256 const

const HS512 SignAlgorithm = "HS512"

HS512 const

type Time

type Time struct {
	time.Time
}

Time define costume time type

func TimeNow

func TimeNow() *Time

TimeNow is a function to return current time

func (*Time) AddDates

func (t *Time) AddDates(year, month, day int) *Time

AddDates is a function to return current time plus dates

func (*Time) MarshalJSON

func (t *Time) MarshalJSON() ([]byte, error)

MarshalJSON is a function to marshaling field time

func (*Time) UnixTime

func (t *Time) UnixTime() int64

UnixTime is a function to convert timestamp to unix format

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

UnmarshalJSON is a function to unmarshaling function for time-related claims.

type Token

type Token struct {
	Issuer  string
	SignKey string
	SignAlg SignAlgorithm
	PrivKey interface{}
	PublKey interface{}
}

Token define jwt

Jump to

Keyboard shortcuts

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