Skip to content

Latest commit

 

History

History
89 lines (64 loc) · 2.24 KB

File metadata and controls

89 lines (64 loc) · 2.24 KB

auth

-- import "github.com/KyleBanks/go-kit/auth/"

Package auth provides generic authentication functionality.

Note this is not 100% secure and should only be used for prototyping, not for production systems or systems that are accessed by real users.

Usage

func GetIdentifierForAccessToken

func GetIdentifierForAccessToken(a string) (string, error)

GetIdentifierForAccessToken returns a user's identifier, as returned by the Authenticator interface, if it exists in the cache.

If the identifier does not exist, and empty string and error will be returned.

func GetIdentifierForRefreshToken

func GetIdentifierForRefreshToken(r string) (string, error)

GetIdentifierForRefreshToken returns a user's identifier, as returned by the Authenticator interface, if it exists in the cahce.

If the identifier does not exist, an empty string and error will be returned.

func HashPassword

func HashPassword(plainText string) (string, error)

HashPassword returns a hashed version of the plain-text password provided.

func SetCache

func SetCache(c cache.Cacher)

SetCache sets the Cache to use for authentication tokens.

type AuthenticationTokenPair

type AuthenticationTokenPair struct {
	AccessToken  string `json:"accessToken"`
	RefreshToken string `json:"refreshToken"`
}

AuthenticationTokenPair represents a pair of authentication tokens (Access and Refresh).

func Authenticate

func Authenticate(a Authenticator, plainTextPassword string) (AuthenticationTokenPair, error)

Authenticate validates an Authenticator based on it's password hash and the plain-text password provided.

func GenerateToken

func GenerateToken() AuthenticationTokenPair

GenerateToken returns a new AuthenticationTokenPair

func Refresh

func Refresh(a Authenticator, refreshToken string) (AuthenticationTokenPair, error)

Refresh generates a new token pair for a given authenticator.

type Authenticator

type Authenticator interface {
	Identifier() string     // Identifier returns a unique reference to this user.
	HashedPassword() string // HashedPassword returns the user's password hash.
}

Authenticator defines an interface for an authenticate-able User.