auth

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthKey added in v1.0.8

type AuthKey struct {
	// contains filtered or unexported fields
}

AuthKey structure for authentication and credential management for authorized user acces to restricted content.

The package supports path base (eg. /api/{apikey}/action) requests, however the admin management routes require a header token:{apikey} value be set to access the user management routes.

func NewAuthKey added in v1.0.8

func NewAuthKey(path *string, r *chi.Mux) *AuthKey

NewAuthKey configurator will initialize an *auth.Auth and populate the uMap from the disk when path is provided or will use a memory uMap when nil is passed for path; configues the admin routes on a chi.Router

func (*AuthKey) AddHandler added in v1.0.8

func (a *AuthKey) AddHandler() http.HandlerFunc

AddHandler will add a new user to the ApiKey.uMap authority

.../add/{user}

func (*AuthKey) Admin added in v1.0.8

func (a *AuthKey) Admin(name string) *AuthKey

Admin sets the admin name; {default:admin}

func (*AuthKey) Configure added in v1.0.8

func (a *AuthKey) Configure(path *string) *AuthKey

Configure will populate uMap from disk and create a default admin user when no current file exists (or path is file)

func (*AuthKey) DeleteHandler added in v1.0.8

func (a *AuthKey) DeleteHandler() http.HandlerFunc

DeleteHandler removes a user from the ApiKey.uMap authority

.../remove/{user}

func (*AuthKey) GetUser added in v1.0.8

func (a *AuthKey) GetUser(r *http.Request) string

GetUser retreives the user from the r.Context middleware transport chain using the specific mwUser key type

func (*AuthKey) HKey added in v1.0.8

func (a *AuthKey) HKey(key string) *AuthKey

HKey sets the header key name; {default:token}

func (*AuthKey) IsAdmin added in v1.0.8

func (a *AuthKey) IsAdmin(next http.Handler) http.Handler

IsAdmin middleware is restricted to admin and requries that {a.hKey}:{apikey} be set in the request header for access

eg. r.Header [a.hKey:{apikey}]

func (*AuthKey) IsValid added in v1.0.8

func (a *AuthKey) IsValid(next http.Handler) http.Handler

IsValid middleware is restriced to valid users and requires the http header have [a.hKey:{apikey}] set in the header however it will failover and support /api/{key}/action formatting within the url string in r.URL.Path

func (*AuthKey) RefreshHandler added in v1.0.8

func (a *AuthKey) RefreshHandler() http.HandlerFunc

RefreshHandler reloads the ApiKey.uMap from disk

.../refresh

func (*AuthKey) Silent added in v1.0.8

func (a *AuthKey) Silent() *AuthKey

Silent toggle; {default:on}

func (*AuthKey) Start added in v1.0.8

func (a *AuthKey) Start(ctx context.Context, refresh *time.Duration)

Start automated authorization refreshing; useful on clusters which share a common file or sync'd file system

func (*AuthKey) UpdateHandler added in v1.0.8

func (a *AuthKey) UpdateHandler() http.HandlerFunc

UpdateHandler reloads the ApiKey.uMap from disk

.../update/{user}

func (*AuthKey) User added in v1.0.8

func (a *AuthKey) User(user, key string) *AuthKey

User will set a manual user,key combination; key must 6 or more characters

func (*AuthKey) UserHandler added in v1.0.8

func (a *AuthKey) UserHandler() http.HandlerFunc

UserHandler provides the current ApiKey.uMap

.../users

type Authentication added in v1.0.8

type Authentication interface {
	IsValid(http.Handler) http.Handler
}

Authentication interface for middleware using authKey and passKey protected endpoint routes

type Client

type Client interface {
	Configure(interface{}) *PassKey
	Interval(interface{}) *PassKey
	Start(context.Context)
	Current() uint32
}

Client interface that exposes the minimal PassKey methods that a client needs to access for authentication

func NewClient

func NewClient(secret interface{}) Client

NewClient configures a PassKey with the provided secret to allow authentical with a PassKey enabled server

var pkc = passkey.NewClient(secret)
pkc.Start(ctx)
for {
 req.Header.Set("token",pkc.Current())
}

type PassKey

type PassKey struct {
	// contains filtered or unexported fields
}

PassKey structure to generate a time based token set based on a shared secret for system-to-system machine communication with rolling authentication

func NewPassKey

func NewPassKey(secret interface{}) *PassKey

NewPassKey configurator used the provided secret or generates a secret on initilization that can be exported and then shared

default: generate new secret with default one-minute interval
accepts: nil, [20]byte slice, or a base32(A..Z,2...7) 32-character string
eg. AW6TJVTYMAYJXLWFW2WWJ6D3Q5B2AY25

func (*PassKey) Configure

func (pk *PassKey) Configure(secret interface{}) *PassKey

User will Configure applies the provided secret or generates a new one and generates a new token set based off the current pk.interval

default: generate new
accepts: nil, [20]byte slice, or a base32(A..Z,2...7) 32-character string
eg. AW6TJVTYMAYJXLWFW2WWJ6D3Q5B2AY25

func (*PassKey) Current

func (pk *PassKey) Current() uint32

Current token

func (*PassKey) HKey added in v1.0.8

func (pk *PassKey) HKey(key string) *PassKey

HKey sets the header key name; {default:token}

func (*PassKey) Interval

func (pk *PassKey) Interval(interval interface{}) *PassKey

Interval sets the time duration and generates a token set

default: one-minute
accepts: nil, time.Duration, or int value of seconds

func (*PassKey) IsValid

func (pk *PassKey) IsValid(next http.Handler) http.Handler

IsValid middleware is restructed to valid tokens set as token:{passkey} in the http header

func (*PassKey) Secret

func (pk *PassKey) Secret() string

Secret provides the current shared secret as a base32 encoded string

func (*PassKey) Start

func (pk *PassKey) Start(ctx context.Context)

Start interval token PassKey

func (*PassKey) Tokens

func (pk *PassKey) Tokens() []uint32

Tokens return the current token set

func (*PassKey) Validate

func (pk *PassKey) Validate(token uint32) bool

Validate the current token

Jump to

Keyboard shortcuts

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