tokens

package
v0.0.0-...-dae269f Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoToken = errors.New("no token")

Functions

func NewToken

func NewToken() (string, error)

NewToken generates a new token

Types

type Tokens

type Tokens struct {
	component.Base

	Dependencies struct {
		SQL *sql.SQL
	}
}

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

func (tok *Tokens) Check(r *http.Request, scope component.Scope) (bool, error)

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.

func (*Tokens) OnUserDelete

func (tok *Tokens) OnUserDelete(ctx context.Context, user *models.User) error

func (*Tokens) Remove

func (tok *Tokens) Remove(ctx context.Context, user, id string) error

Remove removes a token with the given token from the user

func (*Tokens) TableInfo

func (tok *Tokens) TableInfo() component.TableInfo

func (*Tokens) TokenOf

func (tok *Tokens) TokenOf(r *http.Request) (*models.Token, error)

TokenOf returns the token header found in the given request. If r is nil, or there is no token, returns nil. Error is only set if there is an error accessing the table that stores tokens.

func (*Tokens) Tokens

func (tok *Tokens) Tokens(ctx context.Context, user string) ([]models.Token, error)

Tokens returns a list of tokens for the given user

Jump to

Keyboard shortcuts

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