auth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Number of bits of the hash used for anti-bruteforce ratelimit
	LOGIN_HASH_BITS = 12
)
View Source
const MAX_TOKEN_SIZE = 65536

MAX_TOKEN_SIZE is the maximum token size returned by auth

Variables

View Source
var ErrorAuthCancelled = errors.New("AuthManager is being cancelled")
View Source
var ErrorEmptyAuthResponse = errors.New("Empty body in auth response")

ErrorEmptyAuthResponse returned when response to auth request is empty

View Source
var ErrorInvalidWebToken = errors.New("Web Token is not valid, check your clock")
View Source
var ErrorTooManyAttempts = errors.New("Too many concurrent auth attempts")

Functions

This section is empty.

Types

type Credentials

type Credentials struct {
	Service  string
	Username string
}

Credentials for authentication

func (Credentials) Hash

func (cred Credentials) Hash(password string) uint32

Hash credentials for rate-limiting

type ErrorUnauthorized

type ErrorUnauthorized string

ErrorUnauthorized encapsulates the error returned by Keystone

func (ErrorUnauthorized) Error

func (err ErrorUnauthorized) Error() string

type Keystone

type Keystone struct {
	URL    string
	Client *http.Client
}

type Manager

type Manager struct {
	// Keeper must be at the top of the struct
	clock.Keeper
	Logger   *log.Logger
	Lifetime time.Duration
	Keystone Keystone
	// For token signing
	SigningMethod jwt.SigningMethod
	KeyFunc       jwt.Keyfunc
	// contains filtered or unexported fields
}

Manager handles credential resolution, ratelimit and cache

func New

func New(logger *log.Logger, client *http.Client, lifetime time.Duration, keystoneURL string, signingMethod jwt.SigningMethod, keyFunc jwt.Keyfunc) *Manager

New creates new Auth Manager

func (*Manager) Check

func (m *Manager) Check(webToken string) (Credentials, *Session, error)

Check the credential cache for a match that has not expired yet.

func (*Manager) Login

func (m *Manager) Login(cred Credentials, password string) (*Session, error)

Login with credentials and password.

func (*Manager) Logout

func (m *Manager) Logout(session *Session)

Logout session

func (*Manager) Watch

func (m *Manager) Watch(ctx context.Context, cred Credentials, session *Session)

Watch a session, expire it when the user leaves

type Session

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

Session keeps authentication session status

func (*Session) JWT

func (s *Session) JWT() (string, time.Time, error)

JWT returns the signedJWT along with an expiration time for cookies

Jump to

Keyboard shortcuts

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