authy

package
v0.0.0-...-b8bc1d6 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// NonceHeader should always be used to add or check the nonce in a request
	// instead of X-Authentication-Nonce, to ensure consistency.
	NonceHeader = "X-Authentication-Nonce"
	// TokenHeader should likewise always be used in place of
	// X-Authentication-Token to ensure consistency
	TokenHeader = "X-Authentication-Token"
)

Variables

This section is empty.

Functions

func AuthenticateRequest

func AuthenticateRequest(pubKey, privKey string, requestTime time.Time, duration time.Duration, r *http.Request)

AuthenticateRequest creates a nonce and a token from the input keys, time, and duration, and then adds the corresponding headers to an http request

func NewHandler

func NewHandler(next http.Handler, keys map[string]string) http.Handler

NewHandler constructs a new AuthHandler object with a given next handler and keys map

Types

type AuthHandler

type AuthHandler struct {
	NextHandler http.Handler
	Keys        map[string]string
}

AuthHandler ensures that HTTP requests contain a valid nonce and token using the correct format for nonces and tokens and a map of public to private keys

func (*AuthHandler) ServeHTTP

func (middleware *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP confirms that an HTTP request contains a valid nonce and token

type Nonce

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

Nonce is the non-hashed value passed in an authenticated request, and contains information to determine if the request is expired or not. The Nonce value expires to deter copycat attacks.

func MakeNonce

func MakeNonce(requestTime time.Time, duration time.Duration, pubKey string) *Nonce

MakeNonce constructs a new Nonce using a given request time, duration, and public key. The duration is added to the request time to get the expiration time.

func MakeNonceWithUnixTime

func MakeNonceWithUnixTime(requestUnixTime int64, durationUnix int64, pubKey string) *Nonce

MakeNonceWithUnixTime creates a new Nonce, but accepts times given in Unix Epoch format.

func (*Nonce) Encode

func (nonce *Nonce) Encode() string

Encode returns a base64 encoded string of a Nonce's three values

type Token

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

Token is the hashed value in an authenticated request, and contains a nonce and a private key. Token needs a nonce so that the server can validate not just that the private key is valid, but also that the hashed value is from a non-expired request.

func MakeToken

func MakeToken(encodedNonce, privKey string) *Token

MakeToken accepts the base64 encoded value of a Nonce and a private key and creates a new Token object.

func (*Token) Encode

func (token *Token) Encode() string

Encode returns a sha256 hashed string of a Token's values

Jump to

Keyboard shortcuts

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