tokens

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tokens contains the models and functions to manage user API tokens.

Index

Constants

View Source
const (
	// TableName is the user table name in database.
	TableName = "token"
)

Variables

View Source
var (
	// Tokens is the token manager.
	Tokens = Manager{}

	// ErrNotFound is returned when a token record was not found.
	ErrNotFound = errors.New("not found")
)

Functions

func GetJwtClaims

func GetJwtClaims(data string) (jwt.StandardClaims, error)

GetJwtClaims checks a raw JWT claims and returns it when it passes the signature validation.

func NewJwtToken

func NewJwtToken(uid string) (*jwt.Token, error)

NewJwtToken returns a new JWT token instance using a given ID and signing with the configuration's JWT secret key.

Types

type Manager

type Manager struct{}

Manager is a query helper for token entries.

func (*Manager) Create

func (m *Manager) Create(token *Token) error

Create insert a new token in the database.

func (*Manager) GetOne

func (m *Manager) GetOne(expressions ...goqu.Expression) (*Token, error)

GetOne executes the a select query and returns the first result or an error when there's no result.

func (*Manager) GetUser

func (m *Manager) GetUser(uid string) (*TokenAndUser, error)

GetUser returns the token and user owning a given token uid.

func (*Manager) Query

func (m *Manager) Query() *goqu.SelectDataset

Query returns a prepared goqu SelectDataset that can be extended later.

type Token

type Token struct {
	ID          int           `db:"id" goqu:"skipinsert,skipupdate"`
	UID         string        `db:"uid"`
	UserID      *int          `db:"user_id"`
	Created     time.Time     `db:"created" goqu:"skipupdate"`
	Expires     *time.Time    `db:"expires"`
	IsEnabled   bool          `db:"is_enabled"`
	Application string        `db:"application"`
	Roles       types.Strings `db:"roles"`
}

Token is a token record in database.

func (*Token) Delete

func (t *Token) Delete() error

Delete removes a token from the database.

func (*Token) IsExpired

func (t *Token) IsExpired() bool

IsExpired returns true if the token has an expiration date and the current time is after the expiration.

func (*Token) Save

func (t *Token) Save() error

Save updates all the token values.

func (*Token) Update

func (t *Token) Update(v interface{}) error

Update updates some bookmark values.

type TokenAndUser

type TokenAndUser struct {
	Token *Token      `db:"t"`
	User  *users.User `db:"u"`
}

TokenAndUser is a result of a joint query on user and token tables.

Jump to

Keyboard shortcuts

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