package
0.0.0-20190806085950-af561f6ff7a1
Repository: https://github.com/kylebanks/go-kit.git
Documentation: pkg.go.dev

# README

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.

# Functions

Authenticate validates an Authenticator based on it's password hash and the plain-text password provided.
GenerateToken returns a new AuthenticationTokenPair.
GetIdentifierForAccessToken returns a user's identifier, as returned by the Authenticator interface, if it exists in the cache.
GetIdentifierForRefreshToken returns a user's identifier, as returned by the Authenticator interface, if it exists in the cahce.
HashPassword returns a hashed version of the plain-text password provided.
Refresh generates a new token pair for a given authenticator.
SetCache sets the Cache to use for authentication tokens.

# Structs

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

# Interfaces

Authenticator defines an interface for an authenticate-able User.