auth

package
v0.0.0-...-1c68573 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JWTClaimUsername = "username"

JWTClaimUsername is claims key which holds user's username.

View Source
var JWTSigningMethod = jwt.SigningMethodHS256

JWTSigningMethod is a signing method used to sign JWT claims.

Functions

This section is empty.

Types

type DefaultJWTAuthenticator

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

DefaultJWTAuthenticator is the default JWT authenticator.

func NewJWTAuthenticator

func NewJWTAuthenticator(secretKey string, tokenTTL time.Duration) *DefaultJWTAuthenticator

NewJWTAuthenticator creates a new instance of DefaultJWTAuthenticator and returns pointer to it.

func (*DefaultJWTAuthenticator) CreateToken

func (a *DefaultJWTAuthenticator) CreateToken(username string) (string, time.Time, error)

CreateToken generates a new JWT and returns its string representation and expiration timestamp.

func (*DefaultJWTAuthenticator) VerifyToken

func (a *DefaultJWTAuthenticator) VerifyToken(tokenString string) (jwt.MapClaims, error)

VerifyToken verifies that JWT token is valid and not expired, returns claims it contains.

type DefaultPasswordAuthenticator

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

DefaultPasswordAuthenticator represents password hashing and validation authority.

func NewPasswordAuthenticator

func NewPasswordAuthenticator(bcryptCost int) *DefaultPasswordAuthenticator

NewPasswordAuthenticator creates a new instance of DefaultPasswordAuthenticator and returns pointer to it.

func (*DefaultPasswordAuthenticator) HashPassword

func (d *DefaultPasswordAuthenticator) HashPassword(password string) (string, error)

HashPassword returns hash of a given password.

func (*DefaultPasswordAuthenticator) VerifyPassword

func (d *DefaultPasswordAuthenticator) VerifyPassword(password string, hash string) (bool, error)

VerifyPassword returns true if a given password matches with a given hash.

type JWTAuthenticator

type JWTAuthenticator interface {
	// CreateToken generates a new JWT and returns its string representation and expiration timestamp.
	// todo: should `expires` be returned and is it necessary for a user?
	CreateToken(username string) (token string, expires time.Time, err error)

	// VerifyToken verifies that JWT token is valid and not expired, returns claims it contains.
	VerifyToken(token string) (jwt.MapClaims, error)
}

JWTAuthenticator is an interface for a JWT authenticator: it can create and verify tokens.

type PasswordAuthenticator

type PasswordAuthenticator interface {
	// HashPassword returns hash of a given password.
	HashPassword(password string) (string, error)

	// VerifyPassword returns true if a given password matches with a given hash.
	VerifyPassword(password string, hash string) (bool, error)
}

Jump to

Keyboard shortcuts

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