forked from firstdata/marketplace-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
43 lines (34 loc) · 1.28 KB
/
auth.js
File metadata and controls
43 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var request = require('request');
var crypto = require('crypto');
var http = require("https");
var username = 'xxxx-xxxx-xxx-xxx-xxxx'; // replace with userna,e from email
var secret = 'xxx-xxx-xxx-xxx-xxxxxxxx'; // replace with secret from your email
var url = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // replace with url from your email
var getAuthenticationHeaders = function () {
var date = new Date().toUTCString();
var stringToSign = 'date: ' + date.trim();
var encodedSignature = crypto.createHmac("sha1", secret).update(stringToSign).digest("base64");
var hmacAuth = 'hmac username="' + username + '",algorithm="hmac-sha1",headers="date",signature="' + encodedSignature + '"';
return {
'date': date,
'Authorization': hmacAuth
}
}
// Sample GET
var options = { method: 'GET',
url: url + 'marketplace/v1/contracts/31/agreement/',
headers: getAuthenticationHeaders() };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
// Sample POST
var options2 = { method: 'POST',
url: url + 'marketplace/v1/identity/questions',
headers: getAuthenticationHeaders(),
body: { orderId: 242 },
json: true };
request(options2, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});