auth

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// Scope for reading tokens
	ScopeRead = "github.com/mutablelogic/go-server/tokenauth:read"

	// Scope for updating, deleting and creating tokens
	ScopeWrite = "github.com/mutablelogic/go-server/tokenauth:write"
)

Variables

This section is empty.

Functions

func New

func New(pool Pool, opts ...Option) Auth

Create a new authorization service with the given pool

func NewAuthToken added in v0.0.3

func NewAuthToken(t *Token) *authtoken

Types

type Option

type Option func(*auth) error

type Token

type Token struct {
	Key    string    `json:"key,omitempty" bson:"_id,omitempty"`               // Key
	Name   string    `json:"name" bson:"name"`                                 // Name of token
	Type   TokenType `json:"type" bson:"type"`                                 // Type of token
	Value  string    `json:"-" bson:"value"`                                   // Token value
	Expire time.Time `json:"expires_at,omitempty" bson:"expires_at,omitempty"` // Time of expiration for the token
	Time   time.Time `json:"access_at" bson:"access_at"`                       // Time of last access
	Scope  []string  `json:"scope,omitempty" bson:"scope,omitempty"`           // Authorization scopes
}

func NewByte16

func NewByte16(duration time.Duration, scope ...string) *Token

NewByte16 creates a new 16-byte token without a name

func (*Token) IsScope

func (t *Token) IsScope(scopes ...string) bool

Return true if the token has the specified scope, and is valid

func (*Token) IsValid

func (t *Token) IsValid() bool

Return true if the token is valid (not expired)

func (*Token) MarshalJSON

func (t *Token) MarshalJSON() ([]byte, error)

func (*Token) String

func (t *Token) String() string

type TokenType

type TokenType string
const (
	TokenByte16 TokenType = "byte16" // 16 byte value
)

type TokenUpdateExpiry

type TokenUpdateExpiry struct {
	Time   time.Time `bson:"access_at"`            // Time of last access
	Expire time.Time `bson:"expires_at,omitempty"` // Time of expiration for the token
}

type TokenUpdateScope

type TokenUpdateScope struct {
	Time  time.Time `bson:"access_at"`       // Time of last access
	Scope []string  `bson:"scope,omitempty"` // Authentication scopes
}

type TokenUpdateTime

type TokenUpdateTime struct {
	Time time.Time `bson:"access_at"` // Time of last access
}

Jump to

Keyboard shortcuts

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