api

package
v0.0.0-...-b395a04 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type API

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

func New

func New(db *sql.DB, secret string, tokenTTL int) (*API, error)

func (*API) Authenticate

func (a *API) Authenticate(ctx context.Context, id, secret string) (string, *jwt.NumericDate, error)

func (*API) Authorize

func (a *API) Authorize(e Entity, scope []string) bool

func (*API) CreateEntity

func (a *API) CreateEntity(ctx context.Context, secret, note string, scope []string) (string, error)

func (*API) CreateToken

func (a *API) CreateToken(e Entity) *jwt.Token

func (*API) GetEntity

func (a *API) GetEntity(ctx context.Context, id string) (Entity, error)

func (*API) GetEntityByTokenString

func (a *API) GetEntityByTokenString(ctx context.Context, token string) (Entity, error)

func (*API) GetTokenSignedString

func (a *API) GetTokenSignedString(t *jwt.Token) (string, error)

func (*API) UpdateEntity

func (a *API) UpdateEntity(ctx context.Context, id, secret, note string, scope []string) error

type Entity

type Entity struct {
	ID     string
	Secret string
	Scope  []string
	Note   string
}

type ErrInvalidArg

type ErrInvalidArg struct {
	Msg string
}

func (ErrInvalidArg) Error

func (e ErrInvalidArg) Error() string

func (ErrInvalidArg) Is

func (e ErrInvalidArg) Is(err error) bool

type TokenClaims

type TokenClaims struct {
	jwt.RegisteredClaims
}

Jump to

Keyboard shortcuts

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