tokens

package
v0.0.0-...-e934472 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccessBlocked = errors.New("access_blocked")
)
View Source
var (
	ErrRefreshTokenExpired = errors.New("refresh_expired")
)

Functions

func UUID

func UUID() string

Types

type BlockedUpdater

type BlockedUpdater struct {
	Blocked bool `db:"blocked"`
}

func (BlockedUpdater) Build

func (b BlockedUpdater) Build(ctx context.Context, qb goqu.DialectWrapper, args ...interface{}) (string, []interface{}, error)

type BuildOpts

type BuildOpts func(t Token) Token

func AddAccessExpiry

func AddAccessExpiry(conf ExpiryConfig) BuildOpts

func AddRefreshExpiry

func AddRefreshExpiry(conf ExpiryConfig) BuildOpts

func WithBlocked

func WithBlocked(blocked bool) BuildOpts

func WithCreatedAt

func WithCreatedAt(createdAt time.Time) BuildOpts

func WithRefreshExpiry

func WithRefreshExpiry(refreshExpiresAt time.Time) BuildOpts

func WithRefreshToken

func WithRefreshToken(refreshToken string) BuildOpts

type ExpireUpdate

type ExpireUpdate struct {
	ExpiresAt time.Time `db:"expires_at"`
}

func (ExpireUpdate) Build

func (e ExpireUpdate) Build(ctx context.Context, qb goqu.DialectWrapper, args ...interface{}) (sql string, dargs []interface{}, err error)

type ExpiryConfig

type ExpiryConfig struct {
	AccessExpiresIn  time.Duration
	RefreshExpiresIn time.Duration
}

type FindBy

type FindBy map[string]interface{}

type Repository

type Repository interface{}

type Service

type Service interface {
	Create(ctx context.Context, clientID string) (Token, error)
	Revoke(ctx context.Context, accessToken string) (bool, error)
	Authenticate(ctx context.Context, accessToken string) (bool, error)
	ReAuthenticate(ctx context.Context, accessToken, refreshToken string) (Token, error)
	Expire(ctx context.Context, accessToken string) error
}

type Token

type Token struct {
	ClientID         string          `db:"client_id" validate:"required"`
	AccessToken      string          `db:"access_token" validate:"required"`
	RefreshToken     string          `db:"refresh_token" validate:"required"`
	Scopes           bob.StringArray `db:"scopes"`
	Blocked          bool            `db:"blocked"`
	ExpiresAt        time.Time       `db:"expires_at" validate:"required"`
	RefreshExpiresAt time.Time       `db:"refresh_expires_at" validate:"required"`

	CreatedAt time.Time `db:"created_at" validate:"required"`
	UpdatedAt time.Time `db:"updated_at" validate:"required"`
}

func BuildToken

func BuildToken(clientID string, opts ...BuildOpts) Token

func (Token) HasExpired

func (t Token) HasExpired() bool

func (Token) HasRefreshExpired

func (t Token) HasRefreshExpired() bool

func (Token) TableName

func (Token) TableName() string

type TokenService

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

func NewTokenService

func NewTokenService(repo TokensRepository, econf ExpiryConfig) TokenService

func (TokenService) Authenticate

func (s TokenService) Authenticate(ctx context.Context, accessToken string) (bool, error)

func (TokenService) Create

func (s TokenService) Create(ctx context.Context, clientID string) (Token, error)

func (TokenService) Expire

func (s TokenService) Expire(ctx context.Context, accessToken string) error

func (TokenService) ReAuthenticate

func (s TokenService) ReAuthenticate(ctx context.Context, accessToken, refreshToken string) (Token, error)

func (TokenService) Revoke

func (s TokenService) Revoke(ctx context.Context, accessToken string) (bool, error)

type TokensRepository

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

func NewRepository

func NewRepository(db *sqlx.DB, qb goqu.DialectWrapper) TokensRepository

func (TokensRepository) Create

func (t TokensRepository) Create(ctx context.Context, token Token) (Token, error)

func (TokensRepository) Find

func (t TokensRepository) Find(ctx context.Context, clauses FindBy, checkExpiry bool) (Token, error)

func (TokensRepository) Update

func (t TokensRepository) Update(ctx context.Context, builder UpdateQueryBuilder, bargs ...interface{}) error

type UpdateQueryBuilder

type UpdateQueryBuilder interface {
	Build(context.Context, goqu.DialectWrapper, ...interface{}) (string, []interface{}, error)
}

Jump to

Keyboard shortcuts

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