/
HawkDynamicValue.js
53 lines (43 loc) · 1.28 KB
/
HawkDynamicValue.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var Hawk = require('hawk.js');
var HawkDynamicValue = function() {
this.evaluate = function(context) {
if(['sha1', 'sha256'].indexOf(this.algorithm) < 0) {
throw new Error('The algorithm must be either `sha1` or `sha256`');
}
// Client credentials
var credentials = {
id: this.id || "",
key: this.key,
algorithm: this.algorithm
}
var currentRequest = context.getCurrentRequest();
var header = Hawk.client.header(currentRequest.url, currentRequest.method, { credentials: credentials, ext: this.ext });
// Send authenticated request
return header.field;
};
this.title = function() {
return "Hawk Token";
};
return this;
};
HawkDynamicValue.identifier = 'uk.co.jalada.PawExtensions.HawkDynamicValue';
HawkDynamicValue.title = 'Hawk Authentication';
HawkDynamicValue.inputs = [
DynamicValueInput("id", "ID", "String", {
placeholder: "Hawk key identifier"
}),
DynamicValueInput("key", "Key", "String", {
placeholder: "Hawk key"
}),
DynamicValueInput("algorithm", "Algorithm", "Select", {
choices: {
"sha1": "SHA-1",
"sha256": "SHA-256"
},
defaultValue: "sha1"
}),
DynamicValueInput("ext", "Ext", "String", {
placeholder: ""
}),
];
registerDynamicValueClass(HawkDynamicValue);