@infoxchange/make-it-so 2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-3.1 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,6 +9,7 @@ const jwtSecret = "__placeholder-for-jwt-secret__";
|
|
|
9
9
|
const authRoutePrefix = "__placeholder-for-auth-route-prefix__";
|
|
10
10
|
// Set to true to enable console logging
|
|
11
11
|
const loggingEnabled = false;
|
|
12
|
+
// Simple logger that can be enabled/disabled via the loggingEnabled variable.
|
|
12
13
|
const log = function () {
|
|
13
14
|
if (!loggingEnabled)
|
|
14
15
|
return;
|
|
@@ -32,6 +33,7 @@ const redirectResponse = {
|
|
|
32
33
|
location: { value: `${authRoutePrefix}/oidc/authorize` },
|
|
33
34
|
},
|
|
34
35
|
};
|
|
36
|
+
// Takes a JWT token to decode and throws an error if invalid
|
|
35
37
|
function jwtDecode(token, key, noVerify) {
|
|
36
38
|
// check segments
|
|
37
39
|
const segments = token.split(".");
|
|
@@ -75,6 +77,7 @@ function _constantTimeEquals(a, b) {
|
|
|
75
77
|
}
|
|
76
78
|
return 0 === xor;
|
|
77
79
|
}
|
|
80
|
+
// Verifies some input matches an expected signature.
|
|
78
81
|
function _verify(input, key, method, type, signature) {
|
|
79
82
|
if (type === "hmac") {
|
|
80
83
|
return _constantTimeEquals(signature, _sign(input, key, method));
|
|
@@ -83,9 +86,12 @@ function _verify(input, key, method, type, signature) {
|
|
|
83
86
|
throw new Error("Algorithm type not recognized");
|
|
84
87
|
}
|
|
85
88
|
}
|
|
89
|
+
// Signs some input with a key and method.
|
|
86
90
|
function _sign(input, key, method) {
|
|
87
91
|
return crypto.createHmac(method, key).update(input).digest("base64url");
|
|
88
92
|
}
|
|
93
|
+
// Very annoying that we have to implement this ourselves but it seems like the v1 runtime does not have atob/btoa or
|
|
94
|
+
// Buffer available.
|
|
89
95
|
function _base64urlDecode(str) {
|
|
90
96
|
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
91
97
|
while (str.length % 4)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infoxchange/make-it-so",
|
|
3
|
-
"version": "2.11.0
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "Makes deploying services to IX infra easy",
|
|
5
5
|
"repository": "github:infoxchange/make-it-so",
|
|
6
6
|
"type": "module",
|
|
@@ -15,6 +15,7 @@ const authRoutePrefix = "__placeholder-for-auth-route-prefix__";
|
|
|
15
15
|
// Set to true to enable console logging
|
|
16
16
|
const loggingEnabled = false;
|
|
17
17
|
|
|
18
|
+
// Simple logger that can be enabled/disabled via the loggingEnabled variable.
|
|
18
19
|
const log: typeof console.log = function () {
|
|
19
20
|
if (!loggingEnabled) return;
|
|
20
21
|
|
|
@@ -41,6 +42,7 @@ const redirectResponse = {
|
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
|
|
45
|
+
// Takes a JWT token to decode and throws an error if invalid
|
|
44
46
|
function jwtDecode(token: string, key: string, noVerify?: boolean) {
|
|
45
47
|
// check segments
|
|
46
48
|
const segments = token.split(".");
|
|
@@ -97,6 +99,7 @@ function _constantTimeEquals(a: string, b: string) {
|
|
|
97
99
|
return 0 === xor;
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
// Verifies some input matches an expected signature.
|
|
100
103
|
function _verify(
|
|
101
104
|
input: string,
|
|
102
105
|
key: string,
|
|
@@ -111,10 +114,13 @@ function _verify(
|
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
|
|
117
|
+
// Signs some input with a key and method.
|
|
114
118
|
function _sign(input: string, key: string, method: string) {
|
|
115
119
|
return crypto.createHmac(method, key).update(input).digest("base64url");
|
|
116
120
|
}
|
|
117
121
|
|
|
122
|
+
// Very annoying that we have to implement this ourselves but it seems like the v1 runtime does not have atob/btoa or
|
|
123
|
+
// Buffer available.
|
|
118
124
|
function _base64urlDecode(str: string) {
|
|
119
125
|
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
120
126
|
while (str.length % 4) str += "=";
|