auth

package
v1.4.15 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 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 = scopePrefix + "root"
)

Functions

func New

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

Create a new auth task from the configuration

func TokenName added in v1.4.7

func TokenName(ctx context.Context) string

TokenName returns the token name from the context

func TokenScope added in v1.4.7

func TokenScope(ctx context.Context) []string

TokenScope returns the token scope from the context, or nil

func WithToken added in v1.4.7

func WithToken(ctx context.Context, token Token) context.Context

WithToken returns a context with the given auth token

func WithTokenName added in v1.4.7

func WithTokenName(ctx context.Context, token Token) context.Context

WithTokenName returns a context with the given auth token name

func WithTokenScope added in v1.4.7

func WithTokenScope(ctx context.Context, token Token) context.Context

WithTokenScope returns a context with the given auth token scope

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"`
	Bearer     bool     `hcl:"bearer" description:"Use bearer token for authorization"`
}

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"  writer:",width:29"` // Time of expiration for the token
	Time   time.Time `json:"access_time,omitempty" writer:",width:29"`  // Time of last access
	Scope  []string  `json:"scopes,omitempty" writer:",wrap"`           // Authentication scopes
	// contains filtered or unexported fields
}

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) SetWrite added in v1.4.10

func (t *Token) SetWrite()

Flag that the token is to be written to persistent storage and should not include the 'valid' field

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
}

func NewCreateToken added in v1.4.7

func NewCreateToken(name string, expires_in time.Duration, scope ...string) TokenCreate

Create a new create token request

type TokenJar

type TokenJar interface {
	server.Task

	// 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
}

Directories

Path Synopsis
Implements an API client for the Token auth API (https://github.com/mutablelogic/go-server/pkg/handler/auth)
Implements an API client for the Token auth API (https://github.com/mutablelogic/go-server/pkg/handler/auth)

Jump to

Keyboard shortcuts

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