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 ¶
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 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) }
func NewService ¶
func NewService(r repository.Repository, ltp ListTokenProvider) Service
Click to show internal directories.
Click to hide internal directories.