forked from h-arora/aws-cloudfront-cookie-signer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookieSign.js
37 lines (27 loc) · 799 Bytes
/
cookieSign.js
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
let AWS = require('aws-sdk');
let keyPairId = YOUR_KEY_PAIR_ID;
let privateKey = YOUR_PRIVATE_KEY;
let cfUrl = "xyz.cloudfront.net";
let expiry = 1543607263;
let policy = {
'Statement': [{
'Resource': 'http*://' + cfUrl + '/*',
'Condition': {
'DateLessThan': {'AWS:EpochTime': expiry}
}
}]
};
let policyString = JSON.stringify(policy);
let signer = new AWS.CloudFront.Signer(keyPairId, privateKey);
exports.getSignedCookie = function(req, res) {
var options = {url: "http://"+cfUrl, policy: policyString};
signer.getSignedCookie(options, function(err, cookie) {
if (err) {
res.send(err);
} else {
console.log("cookies: ");
console.log(cookie);
res.send(cookie);
}
});
};