tokenauth

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

tokenauth package implements authentication tokens for HTTP servers

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"
)
View Source
const (
	AdminToken = "admin"
)

Variables

This section is empty.

Functions

func NewWithPlugin

func NewWithPlugin(p Plugin, label string) (*tokenauth, error)

Create a new logger task with provider of other tasks

Types

type EventType

type EventType int
const (
	EventTypeNone EventType = iota
	EventTypeWrite
)

func (EventType) String

func (t EventType) String() string

type Plugin

type Plugin struct {
	task.Plugin
	Path_  string        `json:"path,omitempty"`
	File_  string        `json:"file,omitempty"`
	Delta_ time.Duration `json:"delta,omitempty"`
}

Plugin for tokenauth for storing tokens in a file

func WithLabel

func WithLabel(label string) Plugin

func (Plugin) Delta

func (p Plugin) Delta() time.Duration

func (Plugin) File

func (p Plugin) File() string

func (Plugin) Name

func (p Plugin) Name() string

func (Plugin) New

func (p Plugin) New(parent context.Context, _ iface.Provider) (iface.Task, error)

Create a new logger task with provider of other tasks

func (Plugin) Path

func (p Plugin) Path() (string, error)

func (Plugin) WithPath

func (p Plugin) WithPath(path string) Plugin

type Token

type Token struct {
	Name   string    `json:"name,omitempty"`        // Name of the token
	Value  string    `json:"token,omitempty"`       // Token value
	Expire time.Time `json:"expire_time,omitempty"` // Time of expiration for the token
	Time   time.Time `json:"access_time"`           // Time of last access
	Scope  []string  `json:"scopes,omitempty"`      // Authentication scopes
}

func NewToken

func NewToken(length int, duration time.Duration, scope ...string) *Token

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 TokenCreate

type TokenCreate struct {
	Duration time.Duration `json:"duration,omitempty"` // Duration of the token, or zero for no expiration
	Scope    []string      `json:"scopes,omitempty"`   // Authentication scopes
}

Jump to

Keyboard shortcuts

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