@infoxchange/make-it-so 2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-2.7 → 2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-3.1
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.
- package/dist/cdk-constructs/SiteOidcAuth/auth-check-handler-body.js +5 -5
- package/dist/cdk-constructs/SiteOidcAuth/index.d.ts.map +1 -1
- package/dist/cdk-constructs/SiteOidcAuth/index.js +2 -5
- package/package.json +1 -1
- package/src/cdk-constructs/SiteOidcAuth/auth-check-handler-body.ts +17 -13
- package/src/cdk-constructs/SiteOidcAuth/index.ts +16 -17
|
@@ -87,11 +87,11 @@ function _sign(input, key, method) {
|
|
|
87
87
|
return crypto.createHmac(method, key).update(input).digest("base64url");
|
|
88
88
|
}
|
|
89
89
|
function _base64urlDecode(str) {
|
|
90
|
-
str = str.replace(/-/g,
|
|
90
|
+
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
91
91
|
while (str.length % 4)
|
|
92
|
-
str +=
|
|
93
|
-
const chars =
|
|
94
|
-
let output =
|
|
92
|
+
str += "=";
|
|
93
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
94
|
+
let output = "";
|
|
95
95
|
let bc = 0, bs = 0, buffer, i = 0;
|
|
96
96
|
for (; i < str.length; i++) {
|
|
97
97
|
buffer = chars.indexOf(str.charAt(i));
|
|
@@ -101,7 +101,7 @@ function _base64urlDecode(str) {
|
|
|
101
101
|
bc += 6;
|
|
102
102
|
if (bc >= 8) {
|
|
103
103
|
bc -= 8;
|
|
104
|
-
output += String.fromCharCode((bs >> bc) &
|
|
104
|
+
output += String.fromCharCode((bs >> bc) & 0xff);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
return output;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/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oB,CAAC,SAAS,SAAS,uBAAuB,EAC5D,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,SAAS,EACpB,EAAE,MAA+B,EAAE,GAAE,cAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4C1D,iBAAiB,CAAC,SAAS,SAAS,uBAAuB,EACzD,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,SAAS,EACpB,EAAE,MAA+B,EAAE,GAAE,cAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAuC1D,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,sBAAsB;IA8B9B,OAAO,CAAC,2BAA2B;IAsBnC,OAAO,CAAC,yCAAyC;IAgBjD,OAAO,CAAC,sBAAsB;CAkF/B"}
|
|
@@ -94,7 +94,6 @@ export class SiteOidcAuth extends Construct {
|
|
|
94
94
|
// Get the CloudFront Function Association for auth checking
|
|
95
95
|
// Roughly based off https://github.com/sst/v2/blob/4283d706f251724308b397996ff307929bf3a976/packages/sst/src/constructs/SsrSite.ts#L941
|
|
96
96
|
getFunctionAssociation(scope, jwtSecret, authRoutePrefix) {
|
|
97
|
-
console.log("---- 1");
|
|
98
97
|
const authCheckFunction = new CloudFront.Function(scope, `${this.id}AuthCheckFunction`, {
|
|
99
98
|
code: CloudFront.FunctionCode.fromInline(this.convertToCloudFrontFunctionCompatibleCode(`function handler(event) {
|
|
100
99
|
var request = event.request;
|
|
@@ -104,21 +103,20 @@ export class SiteOidcAuth extends Construct {
|
|
|
104
103
|
// We could specify the JS v2.0 runtime here but for SSR sites SST does the function creation and that currently
|
|
105
104
|
// uses JS v1.0 so no point using v2.0 here as the code has to be compatible with v1.0 anyway.
|
|
106
105
|
});
|
|
107
|
-
console.log("---- 2");
|
|
108
106
|
return {
|
|
109
107
|
function: authCheckFunction,
|
|
110
108
|
eventType: CloudFront.FunctionEventType.VIEWER_REQUEST,
|
|
111
109
|
};
|
|
112
110
|
}
|
|
113
111
|
getAuthCheckHandlerBodyCode(jwtSecret, authRoutePrefix) {
|
|
114
|
-
return fs
|
|
112
|
+
return (fs
|
|
115
113
|
.readFileSync(path.join(import.meta.dirname, "auth-check-handler-body.js"), "utf8")
|
|
116
114
|
.replace("__placeholder-for-jwt-secret__", jwtSecret.secretValue.toString())
|
|
117
115
|
.replace("__placeholder-for-auth-route-prefix__", authRoutePrefix)
|
|
118
116
|
// When typescript builds the make-it-so code including "auth-check-handler-body.ts" it will add "export {}" to
|
|
119
117
|
// the end of the file if it's not already a module. This will cause a syntax error in CloudFront Functions so we
|
|
120
118
|
// remove it here.
|
|
121
|
-
.replace(/export {};\s*$/g, "");
|
|
119
|
+
.replace(/export {};\s*$/g, ""));
|
|
122
120
|
}
|
|
123
121
|
convertToCloudFrontFunctionCompatibleCode(sourceCode, esbuildOptions) {
|
|
124
122
|
// ESBuild doesn't currently support transforming const/let to var, which is required for CloudFront Functions
|
|
@@ -126,7 +124,6 @@ export class SiteOidcAuth extends Construct {
|
|
|
126
124
|
sourceCode = sourceCode
|
|
127
125
|
.replaceAll(/const /g, "var ")
|
|
128
126
|
.replaceAll(/let /g, "var ");
|
|
129
|
-
console.log("---- 3", sourceCode);
|
|
130
127
|
return transformSync(sourceCode, {
|
|
131
128
|
target: "es5",
|
|
132
129
|
...esbuildOptions,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infoxchange/make-it-so",
|
|
3
|
-
"version": "2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-
|
|
3
|
+
"version": "2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-3.1",
|
|
4
4
|
"description": "Makes deploying services to IX infra easy",
|
|
5
5
|
"repository": "github:infoxchange/make-it-so",
|
|
6
6
|
"type": "module",
|
|
@@ -116,24 +116,28 @@ function _sign(input: string, key: string, method: string) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
function _base64urlDecode(str: string) {
|
|
119
|
-
str = str.replace(/-/g,
|
|
120
|
-
while (str.length % 4) str +=
|
|
119
|
+
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
120
|
+
while (str.length % 4) str += "=";
|
|
121
121
|
|
|
122
|
-
const chars =
|
|
123
|
-
|
|
122
|
+
const chars =
|
|
123
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
124
|
+
let output = "";
|
|
124
125
|
|
|
125
|
-
let bc = 0,
|
|
126
|
+
let bc = 0,
|
|
127
|
+
bs = 0,
|
|
128
|
+
buffer,
|
|
129
|
+
i = 0;
|
|
126
130
|
for (; i < str.length; i++) {
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
buffer = chars.indexOf(str.charAt(i));
|
|
132
|
+
if (buffer === -1) continue;
|
|
129
133
|
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
bs = (bs << 6) | buffer;
|
|
135
|
+
bc += 6;
|
|
132
136
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
if (bc >= 8) {
|
|
138
|
+
bc -= 8;
|
|
139
|
+
output += String.fromCharCode((bs >> bc) & 0xff);
|
|
140
|
+
}
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
return output;
|
|
@@ -151,7 +151,6 @@ export class SiteOidcAuth extends Construct {
|
|
|
151
151
|
jwtSecret: SecretsManager.Secret,
|
|
152
152
|
authRoutePrefix: string,
|
|
153
153
|
): CloudFront.FunctionAssociation {
|
|
154
|
-
console.log("---- 1")
|
|
155
154
|
const authCheckFunction = new CloudFront.Function(
|
|
156
155
|
scope,
|
|
157
156
|
`${this.id}AuthCheckFunction`,
|
|
@@ -170,7 +169,6 @@ export class SiteOidcAuth extends Construct {
|
|
|
170
169
|
// uses JS v1.0 so no point using v2.0 here as the code has to be compatible with v1.0 anyway.
|
|
171
170
|
},
|
|
172
171
|
);
|
|
173
|
-
console.log("---- 2")
|
|
174
172
|
|
|
175
173
|
return {
|
|
176
174
|
function: authCheckFunction,
|
|
@@ -182,20 +180,22 @@ export class SiteOidcAuth extends Construct {
|
|
|
182
180
|
jwtSecret: SecretsManager.Secret,
|
|
183
181
|
authRoutePrefix: string,
|
|
184
182
|
): string {
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
183
|
+
return (
|
|
184
|
+
fs
|
|
185
|
+
.readFileSync(
|
|
186
|
+
path.join(import.meta.dirname, "auth-check-handler-body.js"),
|
|
187
|
+
"utf8",
|
|
188
|
+
)
|
|
189
|
+
.replace(
|
|
190
|
+
"__placeholder-for-jwt-secret__",
|
|
191
|
+
jwtSecret.secretValue.toString(),
|
|
192
|
+
)
|
|
193
|
+
.replace("__placeholder-for-auth-route-prefix__", authRoutePrefix)
|
|
194
|
+
// When typescript builds the make-it-so code including "auth-check-handler-body.ts" it will add "export {}" to
|
|
195
|
+
// the end of the file if it's not already a module. This will cause a syntax error in CloudFront Functions so we
|
|
196
|
+
// remove it here.
|
|
197
|
+
.replace(/export {};\s*$/g, "")
|
|
198
|
+
);
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
private convertToCloudFrontFunctionCompatibleCode(
|
|
@@ -207,7 +207,6 @@ export class SiteOidcAuth extends Construct {
|
|
|
207
207
|
sourceCode = sourceCode
|
|
208
208
|
.replaceAll(/const /g, "var ")
|
|
209
209
|
.replaceAll(/let /g, "var ");
|
|
210
|
-
console.log("---- 3", sourceCode)
|
|
211
210
|
return transformSync(sourceCode, {
|
|
212
211
|
target: "es5",
|
|
213
212
|
...esbuildOptions,
|