service

package
v0.0.0-...-0d2eb9b Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const TokenSecretVariableName = "WISHES_JWT_SECRET"

Variables

View Source
var (
	ErrAccessDenied = errors.New("access denied")

	ErrNotFound = repository.ErrNotFound
	ErrConflict = repository.ErrConflict
	ErrOutdated = fmt.Errorf("%w: outdated revision", ErrConflict)

	ErrOAuth      = errors.New("invalid oauth credentials")
	ErrNoProvider = fmt.Errorf("%w: unknown provider", ErrOAuth)
)
View Source
var ErrTokenExpired = errors.New("token expired")

Functions

func NewJwtClaims

func NewJwtClaims(base jwt.RegisteredClaims, userId int64) jwt.Claims

Types

type ErrAlreadyTaken

type ErrAlreadyTaken struct {
	TakenBy int64
}

func (ErrAlreadyTaken) Error

func (err ErrAlreadyTaken) Error() string

func (ErrAlreadyTaken) Unwrap

func (err ErrAlreadyTaken) Unwrap() error

type ListClaims

type ListClaims struct {
	ListID   int64 `json:"lid"`
	ReadOnly bool  `json:"ro"`
}

func (*ListClaims) Valid

func (*ListClaims) Valid() error

type ListTokenProvider

type ListTokenProvider interface {
	GenerateToken(claims ListClaims) (string, error)
	ValidateToken(token string) (ListClaims, error)
}

func NewListTokenProvider

func NewListTokenProvider(secret []byte) ListTokenProvider

type OAuthProvider

type OAuthProvider interface {
	Validate(ctx context.Context, token string) (extId string, err error)
}

type Service

type Service interface {
	Auth(ctx context.Context, token string) (*models.User, error)

	// Login returns ErrAccessDenied on any problem with login credentials (i.e. it
	// does not distinguish between bad username or bad password). Other errors indicate
	// internal server-side error.
	Login(ctx context.Context, username, password string) (token string, err error)

	Register(ctx context.Context, username, password string) (int64, error)

	GetUser(ctx context.Context, id int64, client *models.User) (*models.User, error)

	EditUser(ctx context.Context, user, client *models.User) error

	GetUserLists(ctx context.Context, id int64, client *models.User) ([]int64, error)

	GetList(ctx context.Context, id int64, client *models.User, token *string) (*models.List, error)

	GetListItems(ctx context.Context, list *models.List, client *models.User, token *string) (*models.List, error)

	EditList(ctx context.Context, list *models.List, client *models.User) (*models.List, error)

	AddList(ctx context.Context, list *models.List, client *models.User) (*models.List, error)

	AddListItems(ctx context.Context, list *models.List, items []models.ListItem, client *models.User) (*models.List, error)

	GetListToken(ctx context.Context, id int64, client *models.User) (string, error)

	DeleteList(ctx context.Context, list *models.List, client *models.User) error

	DeleteListItems(ctx context.Context, list *models.List, ids []int64, client *models.User) (*models.List, error)

	TakeItem(ctx context.Context, list *models.List, itemId int64, client *models.User, token *string) error

	UntakeItem(ctx context.Context, list *models.List, itemId int64, client *models.User, token *string) error

	// AddOAuthProvider registers new provider. It is not safe for concurrent use with other methods
	// and should be called only during configuration.
	AddOAuthProvider(providerId string, op OAuthProvider)

	OAuthRegister(ctx context.Context, username, provider, oauthToken string) (int64, error)

	OAuthLogin(ctx context.Context, provider, oauthToken string) (token string, err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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