hmacauth

package module
v0.0.0-...-44256df Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2017 License: ISC Imports: 9 Imported by: 62

README

hmacauth HMAC authentication package for Go

Build Status

Coverage Status

Signs and authenticates HTTP requests based on a shared-secret HMAC signature.

Developed in parallel with the following packages for other languages:

Installation

import "github.com/mbland/hmacauth"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CryptoHashToDigestName

func CryptoHashToDigestName(id crypto.Hash) (result string, err error)

CryptoHashToDigestName returns the algorithm name corresponding to the crypto.Hash ID, or an error if the algorithm is not supported.

func DigestNameToCryptoHash

func DigestNameToCryptoHash(name string) (result crypto.Hash, err error)

DigestNameToCryptoHash returns the crypto.Hash value corresponding to the algorithm name, or an error if the algorithm is not supported.

Types

type AuthenticationResult

type AuthenticationResult int

AuthenticationResult is a code used to identify the outcome of HmacAuth.AuthenticateRequest().

const (
	// ResultNoSignature - the incoming result did not have a signature
	// header.
	ResultNoSignature AuthenticationResult = iota

	// ResultInvalidFormat - the signature header was not parseable.
	ResultInvalidFormat

	// ResultUnsupportedAlgorithm - the signature header specified an
	// unsupported algorithm.
	ResultUnsupportedAlgorithm

	// ResultMatch - the signature from the request header matched the
	// locally-computed signature.
	ResultMatch

	// ResultMismatch - the signature from the request header did not match
	// the locally-computed signature.
	ResultMismatch
)

func (AuthenticationResult) String

func (result AuthenticationResult) String() string

type HmacAuth

type HmacAuth interface {
	// Produces the string that will be prefixed to the request body and
	// used to generate the signature.
	StringToSign(req *http.Request) string

	// Adds a signature header to the request.
	SignRequest(req *http.Request)

	// Generates a signature for the request.
	RequestSignature(req *http.Request) string

	// Retrieves the signature included in the request header.
	SignatureFromHeader(req *http.Request) string

	// Authenticates the request, returning the result code, the signature
	// from the header, and the locally-computed signature.
	AuthenticateRequest(request *http.Request) (
		result AuthenticationResult,
		headerSignature, computedSignature string)
}

HmacAuth signs outbound requests and authenticates inbound requests.

func NewHmacAuth

func NewHmacAuth(hash crypto.Hash, key []byte, header string,
	headers []string) HmacAuth

NewHmacAuth returns an HmacAuth object that can be used to sign or authenticate HTTP requests based on the supplied parameters.

Jump to

Keyboard shortcuts

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