Documentation ¶
Index ¶
- Variables
- func NewToken() (string, error)
- type Tokens
- func (tok *Tokens) Add(ctx context.Context, user string, description string, scopes []string) (*models.Token, error)
- func (tok *Tokens) Check(r *http.Request, scope component.Scope) (bool, error)
- func (tok *Tokens) OnUserDelete(ctx context.Context, user *models.User) error
- func (tok *Tokens) Remove(ctx context.Context, user, id string) error
- func (tok *Tokens) TableInfo() component.TableInfo
- func (tok *Tokens) TokenOf(r *http.Request) (*models.Token, error)
- func (tok *Tokens) Tokens(ctx context.Context, user string) ([]models.Token, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNoToken = errors.New("no token")
Functions ¶
Types ¶
type Tokens ¶
Tokens implements Tokens
func (*Tokens) Add ¶
func (tok *Tokens) Add(ctx context.Context, user string, description string, scopes []string) (*models.Token, error)
Add adds a new token, unless it already exists. The token is granted scopes with .SetScopes(scopes).
func (*Tokens) Check ¶
Check checks if there is a token in the given request and if this request has an appropriate token with the appropriate scope.
If the token is found and has the requested token, returns true, nil. If there is a token found, but the specific scope is not set, returns false, nil. If there is no valid authentication token found, returns false and an error that wraps ErrNoToken. In other cases, other errors may be returned.
Note that the scope may require an parameter to be validated. This validation should take place in the appropriate ScopeProvider; which should recursively invoke this method.