Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUserNotFound used when we fail to retrieve a user ErrUserNotFound = errors.New("User Not Found") // ErrInvalidCredential used with attempting to compare mismatched // credential types ErrInvalidCredential = errors.New("Invlaid Credential") )
Functions ¶
func GenerateKey ¶
GenerateKey derives an encryption key from a password
Types ¶
type Authenticator ¶
type Authenticator interface {
Authenticate(credential Credential) (bool, error)
}
Authenticator interface used authenticate a request
func NewAuthenticator ¶
func NewAuthenticator(credStore CredStore) Authenticator
NewAuthenticator instantiates a new authenticator
type CredStore ¶
type CredStore interface {
RetrieveCredential(id UserID) (Credential, error)
}
CredStore abstraction for credential lookup
func NewJWTCredStore ¶
func NewJWTCredStore(secret []byte, method jwt.SigningMethod) CredStore
NewJWTCredStore instantiates a cred store for checking jwts
type Credential ¶
type Credential interface { UserID() UserID Check(Credential) (bool, error) }
Credential used for authentication
func NewJWTCredential ¶
func NewJWTCredential(tokenStr string) (Credential, error)
NewJWTCredential creates a new JWTCredential
func NewPlainTextCredential ¶
func NewPlainTextCredential(user string, password string) Credential
NewPlainTextCredential creates a simple credential using a user id and password
type HashedMapStore ¶
type HashedMapStore struct {
// contains filtered or unexported fields
}
HashedMapStore simple in memory credstore
func NewHashedMapStore ¶
func NewHashedMapStore(data map[string]string) (*HashedMapStore, error)
NewHashedMapStore takes a map of user ids as keys and plain text passwords as values, salts and hashes them, and indexes them by user ids and creates a HashedMapStore/CredStore for authentication
func (*HashedMapStore) RetrieveCredential ¶
func (m *HashedMapStore) RetrieveCredential(userID UserID) (Credential, error)
RetrieveCredential looksup a credential by userID
type JWTCredential ¶
type JWTCredential struct {
// contains filtered or unexported fields
}
JWTCredential javascript web token
func (*JWTCredential) Check ¶
func (j *JWTCredential) Check(other Credential) (bool, error)
Check cant really verify against itself, so this is not implemented
type PlainTextCredential ¶
type PlainTextCredential struct {
// contains filtered or unexported fields
}
PlainTextCredential plain text username/password
func (PlainTextCredential) Check ¶
func (b PlainTextCredential) Check(other Credential) (bool, error)
Check checks the plain text credential against another
func (PlainTextCredential) UserID ¶
func (b PlainTextCredential) UserID() UserID
UserID returns the user id