Last active
August 4, 2018 03:56
-
-
Save grosscorporation/424236be927aaa7554b3e2eac06da746 to your computer and use it in GitHub Desktop.
HMAC-SHA256 signature crypto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let now = new Date (); | |
let ISODate = new Date ( now.toISOString () ); | |
let TimeStamp = ISODate.getTime (); | |
let api_access_key = "key1"; | |
let api_secret_key = "key2"; | |
let url = "https://test-emoney-services.w-ha.com/api/"; | |
let body = { | |
"subscriber" : { | |
"lastname" : "Martin", | |
"firstname" : "Philippe", | |
"birthdate" : "1986-03-01", | |
"nationality" : "FRA" | |
}, | |
"address" : { | |
"label1" : "12 rue de Stalingrad", | |
"zip_code" : "92800", | |
"city" : "Puteaux", | |
"country" : "FRA" | |
}, | |
"email" : "[email protected]", | |
"tag" : "account_type1" | |
}; | |
let hmac = crypto.createHmac ( 'sha256', api_secret_key ); | |
hmac.update ( api_access_key + ':' + TimeStamp + ':1:' + JSON.stringify ( body ) ); | |
let signature = hmac.digest ( 'hex' ); | |
let options = { | |
method : 'post', | |
url : url + 'accounts/standard', | |
json : true, | |
headers : { | |
'Authorization' : 'AUTH ' + api_access_key + ':' + TimeStamp + ':1:' + signature, | |
'Content-Type' : 'application/json' | |
}, | |
body : body | |
}; | |
request ( options, function callback ( error, response, body ) { | |
if ( error ) { | |
res.send ( error ) | |
} else { | |
res.send ( body ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment