auth

package
v0.0.0-...-0b48d5a Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const JWTCookieName string = "token"

JWTCookieName name of the cookie JWT token is stored in

Variables

View Source
var (
	// ErrBadCredentials represents an error when validating wrong c.
	ErrBadCredentials = errors.New("bad credentials")
)
View Source
var (
	// ErrUnauthorized unauthorized
	ErrUnauthorized = errors.New("unauthorized")
)

Functions

func TokenFromContext

func TokenFromContext(c *gin.Context) (string, error)

TokenFromContext retrieve token from request Header or Cookie

Types

type Authenticator

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

Authenticator wraps CredentialsManager to provide an easy way of authentication for builtin UI.

func NewAuthenticator

func NewAuthenticator() *Authenticator

NewAuthenticator creates an authenticator.

func (*Authenticator) ChangePassword

func (a *Authenticator) ChangePassword(username, oldPassword, newPassword string) error

ChangePassword changes user password.

func (*Authenticator) CheckCredentials

func (a *Authenticator) CheckCredentials(username, password string) error

CheckCredentials checks if provided username and password combo is valid comparing it to stored credentials.

type CredentialsManager

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

CredentialsManager verifies/sets user credentials for web UI.

func NewCredentialsManager

func NewCredentialsManager(dataDir string) *CredentialsManager

NewCredentialsManager returns given a password file directory returns a new credentials manager, which can be used to validate or alter user credentials.

func (*CredentialsManager) SetPassword

func (c *CredentialsManager) SetPassword(password string) error

SetPassword sets a new password for a user.

func (*CredentialsManager) Validate

func (c *CredentialsManager) Validate(username, password string) error

Validate username and password against stored credentials.

type JWT

type JWT struct {
	Token          string
	ExpirationTime time.Time
}

JWT contains token details

type JWTAuthenticator

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

JWTAuthenticator contains JWT handling methods

func NewJWTAuthenticator

func NewJWTAuthenticator(encryptionKey JWTEncryptionKey) *JWTAuthenticator

NewJWTAuthenticator creates a new JWT authentication instance

func (*JWTAuthenticator) CreateToken

func (jwtAuth *JWTAuthenticator) CreateToken(username string) (JWT, error)

CreateToken creates a new JWT token

func (*JWTAuthenticator) ValidateToken

func (jwtAuth *JWTAuthenticator) ValidateToken(token string) (bool, error)

ValidateToken validates a JWT token

type JWTEncryptionKey

type JWTEncryptionKey []byte

JWTEncryptionKey contains the encryption key for JWT

func NewJWTEncryptionKey

func NewJWTEncryptionKey(storage Storage) (JWTEncryptionKey, error)

NewJWTEncryptionKey creates and stores or re-uses an existing JWT encryption key

type Storage

type Storage interface {
	GetValue(bucket string, key interface{}, to interface{}) error
	SetValue(bucket string, key interface{}, to interface{}) error
}

Storage for Credentials.

Jump to

Keyboard shortcuts

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