auth

package
v0.0.0-...-af561f6 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: MIT Imports: 4 Imported by: 0

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.

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

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.

Jump to

Keyboard shortcuts

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