auth

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: ISC Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrJWTDecode  = errors.Type("jwt-decode")
	ErrJWTBadAlgo = errors.Type("jwt-bad-algo")
)

Variables

View Source
var SimpleInitErr = errors.New("username and password can't be empty string")

SimpleInitErr is returned when a Simple auth can't be initialized.

Functions

func ReadBytes added in v0.6.0

func ReadBytes(size int) ([]byte, error)

ReadBytes reads size bytes from /dev/urandom.

Types

type Authenticator added in v0.6.0

type Authenticator interface {
	Authenticate(username, password string) (Claims, error)
}

Authenticator is the basic interface used for authenticating a user.

func NewDisabled added in v0.9.0

func NewDisabled() Authenticator

func NewSimple added in v0.7.0

func NewSimple(username, password string) (Authenticator, error)

type BearerToken

type BearerToken string

BearerToken is a base64 encoded string.

func NewBearerToken

func NewBearerToken() (BearerToken, error)

NewBearerToken creates a simple unique base64 encoded bearer token.

type Claims

type Claims struct {
	Username string `json:"uid,omitempty"`
	Admin    bool   `json:"adm,omitempty"`

	// These fields are filled in automatically.
	Expiry    int64 `json:"exp"` // RFC 7519 4.1.4
	NotBefore int64 `json:"nbf"` // RFC 7519 4.1.5
	IssuedAt  int64 `json:"iat"` // RFC 7519 4.1.6
}

Claims contains information an authentication claims to verify.

func (Claims) IsValid added in v0.9.0

func (c Claims) IsValid(now time.Time) bool

IsValid returns true if the claims are valid at the given time.

type JWT

type JWT string

JWT contains signed claim information.

type SymmetricKey

type SymmetricKey [keySize]byte

Symmetrickey contains bytes for encrption or signing operations

func GenerateSymmetricKey

func GenerateSymmetricKey() (SymmetricKey, error)

GenerateSymmetricKey creates a random symmetric key for signing or encrypting claims.

func (SymmetricKey) Sign added in v0.7.0

func (key SymmetricKey) Sign(claims Claims, now time.Time, lifetime time.Duration) (JWT, error)

Sign creates a new JWT from a set of claims with the provided time and duration.

func (SymmetricKey) Verify added in v0.7.0

func (key SymmetricKey) Verify(token JWT) (Claims, error)

Verify checks the signature of the token with the provided key.

Jump to

Keyboard shortcuts

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