auth

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package auth provides user authentication and login services and APIs. It supplies the "jellyauth" component.

To use the jellyauth component, simply add a "jellyauth" section to your config and call jelly.Use(auth.Component) before loading config. This config section overrides the typical API defaults and will create a fully functional system simply by being enabled, albeit with an unpersisted, in-memory database.

TODO: carry over config instructions from the example.

Index

Constants

View Source
const (
	ConfigKeySecret      = "secret"
	ConfigKeySetAdmin    = "set_admin"
	ConfigKeyUnauthDelay = "unauth_delay"
)
View Source
const (
	MaxSecretSize = 64
	MinSecretSize = 32
)
View Source
const (
	Version = "0.0.1"
)

Variables

View Source
var (
	// Component holds the component information for jellyauth. This is passed
	// to jelly.Use to enable the use of jellyauth in a server.
	Component jelly.Component = ComponentInfo{}
)
View Source
var (
	Issuer = "jelly"
)

Functions

This section is empty.

Types

type ComponentInfo

type ComponentInfo struct{}

func (ComponentInfo) API

func (ci ComponentInfo) API() jelly.API

func (ComponentInfo) Config

func (ci ComponentInfo) Config() jelly.APIConfig

func (ComponentInfo) Name

func (ci ComponentInfo) Name() string

type Config

type Config struct {
	CommonConf jelly.CommonConfig

	// Secret is the secret used for signing tokens. If not provided, a default
	// key is used.
	Secret []byte

	// SetAdmin sets the initial admin user in the DB. If it doesn't exist,
	// it's created on initialization. Format must be USERNAME:PASSWORD. This
	// will not default; if none is provided, no user is created. If the user
	// already exists, it will have its password set to the given one.
	SetAdmin string

	// UnauthDelayMillis is the amount of additional time to wait
	// (in milliseconds) before sending a response that indicates either that
	// the client was unauthorized or the client was unauthenticated. This is
	// something of an "anti-flood" measure for naive clients attempting
	// non-parallel connections. If not set it will default to 1 second
	// (1000ms). Set this to any negative number to disable the delay.
	UnauthDelayMillis int
}

func (*Config) Common

func (cfg *Config) Common() jelly.CommonConfig

func (*Config) FillDefaults

func (cfg *Config) FillDefaults() jelly.APIConfig

FillDefaults returns a new *Config identical to cfg but with unset values set to their defaults and values normalized.

func (*Config) Get

func (cfg *Config) Get(key string) interface{}

func (*Config) Keys

func (cfg *Config) Keys() []string

func (*Config) Set

func (cfg *Config) Set(key string, value interface{}) error

func (*Config) SetFromString

func (cfg *Config) SetFromString(key string, value string) error

func (*Config) Validate

func (cfg *Config) Validate() error

Validate returns an error if the Config has invalid field values set. Empty and unset values are considered invalid; if defaults are intended to be used, call Validate on the return value of FillDefaults.

Jump to

Keyboard shortcuts

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