http-signature-helpers
Helpers for the HTTP Signature spec.
Install
yarn add http-signature-helpers# or npm install http-signature-helpers
;# orconst getSignatureString createSignatureHeader parseSignatureHeader = ;
Usage
getSignatureString(options)
Get the signature string (this is the content to create the signature from).
Options (object):
body
: (string) Body contentheaders
: (object) Key-value of HTTP headers to be used withsignatureHeaders
signatureHeaders
(array) Which headers to include in signature stringtarget
: (object) Values to use with(request-target)
signatureHeader
(optional)method
: (string) HTTP method (GET
,POST
, etc)path
: (string) Request path (/
, etc)
nonce
: (object) Used for signature nonce spec (optional)clientId
: (string/number)nonce
: (string/number)
Example:
;
(request-target): get /foo
host: example.org
date: Tue, 07 Jun 2014 20:51:35 GMT
cache-control: max-age=60, must-revalidate
x-example: Example header with some whitespace.
body
createSignatureHeader(options)
Get the signature header to set to Authorization
.
Options (object):
keyId
: (string) Key identifieralgorithm
: (string) Algorithm (known/recommended values:rsa-sha256
,hmac-sha256
. The algorithm link on the draft spec is dead)signature
: (string) Signature generated fromgetSignatureString
signatureHeaders
: (array) Headers to be included inheader
param. Matching fromgetSignatureString
nonce
: (object) Used for signature nonce spec (optional). Matching fromgetSignatureString
clientId
: (string/number)nonce
: (string/number)
prefix
(booleam, default:true
) If it should prefix withSignature
.
Example:
;
Signature keyId="rsa-key-1",algorithm="rsa-sha256",headers="(request-target) host date digest content-length",signature="rsa-signature-1"
parseSignatureHeader(value, prefix = true)
Parse the value from createSignatureHeader
. If prefix
is true, it will remove the Signature
prefix.
Example:
;
keyId: "rsa-key-1" algorithm: "rsa-sha256" signatureHeaders: "(request-target)" "host" "date" "digest" "content-length" signature: "rsa-signature-1"