api

package
v0.0.0-...-90949e5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: MIT Imports: 12 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 interface {
	SecretKey() string
	CheckSecret(hashed, secret string) (bool, error)

	CreateEntity(ctx context.Context, id string, secret []byte, scope Scope, attrs Attrs) error
	UpdateEntity(ctx context.Context, id string, secret []byte, scope Scope, attrs Attrs) error
	GetEntity(ctx context.Context, id string) (Entity, error)
	CheckScope(target Scope, required Scope) bool

	CreateToken(subject string, scope []string, ttl time.Duration) Token
	ParseToken(token string) (TokenClaims, error)
}

type APIMock

type APIMock struct {
	mock.Mock
}

func (*APIMock) CheckScope

func (m *APIMock) CheckScope(target Scope, required Scope) bool

func (*APIMock) CheckSecret

func (m *APIMock) CheckSecret(hashed, secret string) (bool, error)

func (*APIMock) CreateEntity

func (m *APIMock) CreateEntity(ctx context.Context, id string, secret []byte, scope Scope, attrs Attrs) error

func (*APIMock) CreateToken

func (m *APIMock) CreateToken(subject string, scope []string, ttl time.Duration) Token

func (*APIMock) GetEntity

func (m *APIMock) GetEntity(ctx context.Context, id string) (Entity, error)

func (*APIMock) ParseToken

func (m *APIMock) ParseToken(t string) (TokenClaims, error)

func (*APIMock) SecretKey

func (m *APIMock) SecretKey() string

func (*APIMock) UpdateEntity

func (m *APIMock) UpdateEntity(ctx context.Context, id string, secret []byte, scope Scope, attrs Attrs) error

type Attrs

type Attrs map[string]string

type Claims

type Claims interface {
	GetExpirationTime() (*jwt.NumericDate, error)
}

type ClaimsMock

type ClaimsMock struct {
	mock.Mock
}

func (*ClaimsMock) GetExpirationTime

func (m *ClaimsMock) GetExpirationTime() (*jwt.NumericDate, error)

type DefaultAPI

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

func NewDefault

func NewDefault(db sqldb.DB, secretKey string, now func() time.Time) *DefaultAPI

func (*DefaultAPI) CheckScope

func (a *DefaultAPI) CheckScope(target Scope, required Scope) bool

CheckScope checks whether target scope has all required scopes

func (*DefaultAPI) CheckSecret

func (a *DefaultAPI) CheckSecret(hashed, secret string) (bool, error)

func (*DefaultAPI) CreateEntity

func (a *DefaultAPI) CreateEntity(ctx context.Context, id string, secret []byte, scope Scope, attrs Attrs) error

CreateEntity creates a new entity. The secret should contain a hashed string, not clear text.

func (*DefaultAPI) CreateToken

func (a *DefaultAPI) CreateToken(subject string, scope []string, ttl time.Duration) Token

func (*DefaultAPI) GetEntity

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

func (*DefaultAPI) ParseToken

func (a *DefaultAPI) ParseToken(token string) (TokenClaims, error)

func (*DefaultAPI) SecretKey

func (a *DefaultAPI) SecretKey() string

func (*DefaultAPI) UpdateEntity

func (a *DefaultAPI) UpdateEntity(ctx context.Context, id string, secret []byte, scope Scope, attrs Attrs) error

UpdateEntity updates an existing entity. The secret should contain a hashed string, not clear text. Empty secret tells this method that it should not be updated.

type DefaultToken

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

func (*DefaultToken) Claims

func (t *DefaultToken) Claims() Claims

func (*DefaultToken) SignedString

func (t *DefaultToken) SignedString(key interface{}) (string, error)

type Entity

type Entity struct {
	ID     string
	Secret string
	Scope  Scope
	Attrs  Attrs
}

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 Scope

type Scope []string

type Token

type Token interface {
	Claims() Claims
	SignedString(key interface{}) (string, error)
}

type TokenClaims

type TokenClaims struct {
	jwt.RegisteredClaims
	Scope []string `json:"scope,omitempty"`
}

type TokenMock

type TokenMock struct {
	mock.Mock
}

func (*TokenMock) Claims

func (m *TokenMock) Claims() Claims

func (*TokenMock) SignedString

func (m *TokenMock) SignedString(key interface{}) (string, error)

Jump to

Keyboard shortcuts

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