-
Notifications
You must be signed in to change notification settings - Fork 2
/
Auth0Token.js
53 lines (45 loc) · 1.62 KB
/
Auth0Token.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 jsrassign = require("./jsrassign");
// Extensions are implemented as JavaScript classes
var Auth0Token = function() {
// implement the evaluate() method to generate the dynamic value
this.evaluate = function() {
var now = Math.floor(new Date().getTime() / 1000),
headerInput = {
typ: "JWT",
alg: "HS256"
},
bodyInput = {
email: this.email,
iss: this.issuer,
sub: this.userId,
aud: this.clientId,
exp: now + 60 * 60 * 24 * 7,
iat: now
};
secret = this.base64encoded
? { b64: jsrassign.b64utob64(this.clientSecret) }
: this.clientSecret;
// provider should be included in userId, but assume auth0 if not
if (bodyInput.sub.split("|").length === 1) {
bodyInput.sub = "auth0|" + bodyInput.sub;
}
return (
"Bearer " + jsrassign.jws.JWS.sign(null, headerInput, bodyInput, secret)
);
};
};
// set the Extension Identifier (must be same as the directory name)
Auth0Token.identifier = "io.blackcode.Auth0Token";
// give a display name to your Dynamic Value
Auth0Token.title = "Auth0 Authorization Token";
// link to the Dynamic Value documentation
Auth0Token.help = "https://github.com/LordZardeck/PAW-Auth0TokenDynamicValue";
Auth0Token.inputs = [
InputField("issuer", "Issuer", "String"),
InputField("userId", "User Id", "String"),
InputField("email", "User Email", "String"),
InputField("clientId", "Client ID", "String"),
InputField("clientSecret", "Client Secret", "SecureValue"),
InputField("base64encoded", "Secret Base64 Encoded?", "Checkbox")
];
registerDynamicValueClass(Auth0Token);