auth

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Root scope allows ANY operation
	ScopeRoot = version.GitSource + "/scope/root"
)

Functions

func New

func New(c Config) (*auth, error)

Create a new auth task from the configuration

Types

type Config

type Config struct {
	TokenJar   TokenJar `hcl:"token_jar" description:"Persistent storage for tokens"`
	TokenBytes int      `hcl:"token_bytes" description:"Number of bytes in a token"`
}

func (Config) Description

func (Config) Description() string

Description returns the description of the service

func (Config) Name

func (Config) Name() string

Name returns the name of the service

func (Config) New

func (c Config) New() (server.Task, error)

Create a new task from the configuration

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(name string, length int, duration time.Duration, scope ...string) Token

Create a token of the specified number of bytes, with the specified duration and scope. If the duration is zero, the token will not expire.

func (Token) Equals

func (t Token) Equals(other Token) bool

Compares token name, value, expiry and scopes

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) IsZero

func (t Token) IsZero() bool

Return true if the token is a zero token

func (Token) MarshalJSON

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

func (Token) String

func (t Token) String() string

type TokenCreate

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

type TokenJar

type TokenJar interface {
	// Run the token jar until cancelled
	Run(context.Context) error

	// Return all tokens
	Tokens() []Token

	// Return a token from the jar by value, or an invalid token
	// if the token is not found. The method should update the access
	// time of the token.
	GetWithValue(string) Token

	// Return a token from the jar by name, or nil if the token
	// is not found. The method should not update the access time
	// of the token.
	GetWithName(string) Token

	// Put a token into the jar, assuming it does not yet exist.
	Create(Token) error

	// Update an existing token in the jar, assuming it already exists.
	Update(Token) error

	// Remove a token from the jar, based on key.
	Delete(string) error
}

Jump to

Keyboard shortcuts

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