@infoxchange/make-it-so 2.10.0-internal-testing-vdt-199-add-oidc-auth.4 → 2.10.0-internal-testing-vdt-199-add-oidc-auth.5
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/CloudWatchOidcAuth/auth-check.d.ts +9 -1
- package/dist/cdk-constructs/CloudWatchOidcAuth/auth-check.d.ts.map +1 -1
- package/dist/cdk-constructs/CloudWatchOidcAuth/auth-check.js +5 -5
- package/dist/cdk-constructs/CloudWatchOidcAuth/auth-route.d.ts.map +1 -1
- package/dist/cdk-constructs/CloudWatchOidcAuth/auth-route.js +9 -29
- package/package.json +1 -1
- package/src/cdk-constructs/CloudWatchOidcAuth/auth-check.ts +5 -5
- package/src/cdk-constructs/CloudWatchOidcAuth/auth-route.ts +9 -27
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
export declare const handler: (event: AWSCloudFrontFunction.Event, context: AWSCloudFrontFunction.Context) => Promise<{
|
|
3
|
+
statusCode: number;
|
|
4
|
+
headers: {
|
|
5
|
+
location: {
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
} | AWSCloudFrontFunction.Request>;
|
|
2
10
|
//# sourceMappingURL=auth-check.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-check.d.ts","sourceRoot":"","sources":["../../../src/cdk-constructs/CloudWatchOidcAuth/auth-check.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth-check.d.ts","sourceRoot":"","sources":["../../../src/cdk-constructs/CloudWatchOidcAuth/auth-check.ts"],"names":[],"mappings":";AA8FA,eAAO,MAAM,OAAO,UAAiB,2BAA2B,WAAW,sBAAsB,OAAO;;;;;;;kCAkCvG,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Based off: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/example_cloudfront_functions_kvs_jwt_verify_section.html
|
|
2
2
|
import crypto from "crypto";
|
|
3
3
|
import cf from "cloudfront";
|
|
4
|
-
import { ApiHandler, useCookie } from "sst/node/api";
|
|
5
4
|
//Response when JWT is not valid.
|
|
6
5
|
const redirectResponse = {
|
|
7
6
|
statusCode: 302,
|
|
@@ -74,8 +73,9 @@ function _sign(input, key, method) {
|
|
|
74
73
|
function _base64urlDecode(str) {
|
|
75
74
|
return Buffer.from(str, "base64url").toString();
|
|
76
75
|
}
|
|
77
|
-
export const handler =
|
|
78
|
-
console.log("Auth check event:", event);
|
|
76
|
+
export const handler = async (event, context) => {
|
|
77
|
+
console.log("🟢 Auth check event:", event);
|
|
78
|
+
console.log("🔵 Auth check context:", context);
|
|
79
79
|
const request = event.request;
|
|
80
80
|
const secret_key = await getSecret();
|
|
81
81
|
if (!secret_key) {
|
|
@@ -85,7 +85,7 @@ export const handler = ApiHandler(async (event) => {
|
|
|
85
85
|
// console.log(request.cookies);
|
|
86
86
|
// console.log(request.cookies["auth-token"]);
|
|
87
87
|
// console.log(Object.keys(request.cookies));
|
|
88
|
-
const jwtToken =
|
|
88
|
+
const jwtToken = request.cookies["auth-token"]?.value;
|
|
89
89
|
console.log("jwtToken:", jwtToken);
|
|
90
90
|
// console.log(Object.keys(request.cookies));
|
|
91
91
|
// If no JWT token, then generate HTTP redirect 401 response.
|
|
@@ -104,7 +104,7 @@ export const handler = ApiHandler(async (event) => {
|
|
|
104
104
|
// delete request.querystring.jwt;
|
|
105
105
|
log("Valid JWT token");
|
|
106
106
|
return request;
|
|
107
|
-
}
|
|
107
|
+
};
|
|
108
108
|
// Get secret from key value store
|
|
109
109
|
async function getSecret() {
|
|
110
110
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-route.d.ts","sourceRoot":"","sources":["../../../src/cdk-constructs/CloudWatchOidcAuth/auth-route.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"auth-route.d.ts","sourceRoot":"","sources":["../../../src/cdk-constructs/CloudWatchOidcAuth/auth-route.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,OAAO,4CAyCnB,CAAC"}
|
|
@@ -18,7 +18,7 @@ if (!jwtSecret) {
|
|
|
18
18
|
throw new Error("JWT_SECRET not set");
|
|
19
19
|
}
|
|
20
20
|
const oidcIssuerConfigUrl = new URL(`${process.env.OIDC_ISSUER_URL?.replace(/\/$/, "")}/.well-known/openid-configuration`);
|
|
21
|
-
export const handler =
|
|
21
|
+
export const handler = addRequiredContext(AuthHandler({
|
|
22
22
|
providers: {
|
|
23
23
|
oidc: OidcAdapter({
|
|
24
24
|
issuer: await Issuer.discover(oidcIssuerConfigUrl.href),
|
|
@@ -26,7 +26,7 @@ export const handler = convertApiGatewayHandlerToCloudFrontHandler(AuthHandler({
|
|
|
26
26
|
scope: oidcScope,
|
|
27
27
|
onSuccess: async (tokenset) => {
|
|
28
28
|
console.log("tokenset", tokenset, tokenset.claims());
|
|
29
|
-
console.log("Config.jwtSecret:", jwtSecret);
|
|
29
|
+
// console.log("Config.jwtSecret:", jwtSecret);
|
|
30
30
|
// Payload to include in the token
|
|
31
31
|
const payload = {
|
|
32
32
|
userID: tokenset.claims().sub,
|
|
@@ -38,9 +38,7 @@ export const handler = convertApiGatewayHandlerToCloudFrontHandler(AuthHandler({
|
|
|
38
38
|
};
|
|
39
39
|
// Create the token
|
|
40
40
|
const token = jwt.sign(payload, jwtSecret, options);
|
|
41
|
-
const expires = new Date(
|
|
42
|
-
// @ ts-ignore error in GH action
|
|
43
|
-
Date.now() + 1000 * 60 * 60 * 24 * 7);
|
|
41
|
+
const expires = new Date(Date.now() + 1000 * 60 * 60 * 24 * 7);
|
|
44
42
|
return {
|
|
45
43
|
statusCode: 302,
|
|
46
44
|
headers: {
|
|
@@ -50,35 +48,17 @@ export const handler = convertApiGatewayHandlerToCloudFrontHandler(AuthHandler({
|
|
|
50
48
|
`auth-token=${token}; HttpOnly; SameSite=None; Secure; Path=/; Expires=${expires}`,
|
|
51
49
|
],
|
|
52
50
|
};
|
|
53
|
-
// return Session.cookie({
|
|
54
|
-
// redirect: "https://openidconnect.net/callback",
|
|
55
|
-
// type: "public",
|
|
56
|
-
// properties: {
|
|
57
|
-
// userID: tokenset.claims().sub,
|
|
58
|
-
// },
|
|
59
|
-
// });
|
|
60
51
|
},
|
|
61
52
|
}),
|
|
62
53
|
},
|
|
63
54
|
}));
|
|
64
|
-
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
return async function (event, context) {
|
|
55
|
+
function addRequiredContext(handler) {
|
|
56
|
+
return async function (...args) {
|
|
57
|
+
const [event, context] = args;
|
|
68
58
|
// Used by AuthHandler to create callback url sent to oidc server
|
|
69
59
|
event.requestContext.domainName = event.headers["x-forwarded-host"];
|
|
70
|
-
console.log("
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const response = await callback(event, context);
|
|
74
|
-
// if (response.cookies) {
|
|
75
|
-
// if (!response.headers) {
|
|
76
|
-
// response.headers = {}
|
|
77
|
-
// }
|
|
78
|
-
// response.headers["set-cookie"] = response.cookies
|
|
79
|
-
// }
|
|
80
|
-
// response.headers.location += "&cake=blar"
|
|
81
|
-
// response.headers.foo = "bar"
|
|
82
|
-
return response;
|
|
60
|
+
console.log("🟢 event", event);
|
|
61
|
+
console.log("🔵 context", context);
|
|
62
|
+
return await handler(...args);
|
|
83
63
|
};
|
|
84
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infoxchange/make-it-so",
|
|
3
|
-
"version": "2.10.0-internal-testing-vdt-199-add-oidc-auth.
|
|
3
|
+
"version": "2.10.0-internal-testing-vdt-199-add-oidc-auth.5",
|
|
4
4
|
"description": "Makes deploying services to IX infra easy",
|
|
5
5
|
"repository": "github:infoxchange/make-it-so",
|
|
6
6
|
"type": "module",
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import crypto from "crypto";
|
|
4
4
|
import cf from "cloudfront";
|
|
5
|
-
import { ApiHandler, useCookie } from "sst/node/api";
|
|
6
5
|
|
|
7
6
|
//Response when JWT is not valid.
|
|
8
7
|
const redirectResponse = {
|
|
@@ -93,8 +92,9 @@ function _base64urlDecode(str: string) {
|
|
|
93
92
|
return Buffer.from(str, "base64url").toString();
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
export const handler =
|
|
97
|
-
console.log("Auth check event:", event);
|
|
95
|
+
export const handler = async (event: AWSCloudFrontFunction.Event, context: AWSCloudFrontFunction.Context) => {
|
|
96
|
+
console.log("🟢 Auth check event:", event);
|
|
97
|
+
console.log("🔵 Auth check context:", context);
|
|
98
98
|
const request = event.request;
|
|
99
99
|
const secret_key = await getSecret();
|
|
100
100
|
|
|
@@ -106,7 +106,7 @@ export const handler = ApiHandler(async (event) => {
|
|
|
106
106
|
// console.log(request.cookies);
|
|
107
107
|
// console.log(request.cookies["auth-token"]);
|
|
108
108
|
// console.log(Object.keys(request.cookies));
|
|
109
|
-
const jwtToken =
|
|
109
|
+
const jwtToken = request.cookies["auth-token"]?.value;
|
|
110
110
|
console.log("jwtToken:", jwtToken);
|
|
111
111
|
// console.log(Object.keys(request.cookies));
|
|
112
112
|
|
|
@@ -126,7 +126,7 @@ export const handler = ApiHandler(async (event) => {
|
|
|
126
126
|
// delete request.querystring.jwt;
|
|
127
127
|
log("Valid JWT token");
|
|
128
128
|
return request;
|
|
129
|
-
}
|
|
129
|
+
}
|
|
130
130
|
|
|
131
131
|
// Get secret from key value store
|
|
132
132
|
async function getSecret() {
|
|
@@ -23,7 +23,7 @@ const oidcIssuerConfigUrl = new URL(
|
|
|
23
23
|
`${process.env.OIDC_ISSUER_URL?.replace(/\/$/, "")}/.well-known/openid-configuration`,
|
|
24
24
|
);
|
|
25
25
|
|
|
26
|
-
export const handler =
|
|
26
|
+
export const handler = addRequiredContext(
|
|
27
27
|
AuthHandler({
|
|
28
28
|
providers: {
|
|
29
29
|
oidc: OidcAdapter({
|
|
@@ -33,7 +33,7 @@ export const handler = convertApiGatewayHandlerToCloudFrontHandler(
|
|
|
33
33
|
onSuccess: async (tokenset) => {
|
|
34
34
|
console.log("tokenset", tokenset, tokenset.claims());
|
|
35
35
|
|
|
36
|
-
console.log("Config.jwtSecret:", jwtSecret);
|
|
36
|
+
// console.log("Config.jwtSecret:", jwtSecret);
|
|
37
37
|
|
|
38
38
|
// Payload to include in the token
|
|
39
39
|
const payload = {
|
|
@@ -49,7 +49,6 @@ export const handler = convertApiGatewayHandlerToCloudFrontHandler(
|
|
|
49
49
|
// Create the token
|
|
50
50
|
const token = jwt.sign(payload, jwtSecret, options);
|
|
51
51
|
const expires = new Date(
|
|
52
|
-
// @ ts-ignore error in GH action
|
|
53
52
|
Date.now() + 1000 * 60 * 60 * 24 * 7,
|
|
54
53
|
);
|
|
55
54
|
return {
|
|
@@ -61,37 +60,20 @@ export const handler = convertApiGatewayHandlerToCloudFrontHandler(
|
|
|
61
60
|
`auth-token=${token}; HttpOnly; SameSite=None; Secure; Path=/; Expires=${expires}`,
|
|
62
61
|
],
|
|
63
62
|
};
|
|
64
|
-
// return Session.cookie({
|
|
65
|
-
// redirect: "https://openidconnect.net/callback",
|
|
66
|
-
// type: "public",
|
|
67
|
-
// properties: {
|
|
68
|
-
// userID: tokenset.claims().sub,
|
|
69
|
-
// },
|
|
70
|
-
// });
|
|
71
63
|
},
|
|
72
64
|
}),
|
|
73
65
|
},
|
|
74
66
|
}),
|
|
75
67
|
);
|
|
76
68
|
|
|
77
|
-
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
return async function (event, context) {
|
|
69
|
+
function addRequiredContext(handler: ReturnType<typeof AuthHandler>): ReturnType<typeof AuthHandler> {
|
|
70
|
+
return async function (...args) {
|
|
71
|
+
const [event, context] = args;
|
|
81
72
|
// Used by AuthHandler to create callback url sent to oidc server
|
|
82
73
|
event.requestContext.domainName = event.headers["x-forwarded-host"];
|
|
83
|
-
console.log("
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// if (response.cookies) {
|
|
88
|
-
// if (!response.headers) {
|
|
89
|
-
// response.headers = {}
|
|
90
|
-
// }
|
|
91
|
-
// response.headers["set-cookie"] = response.cookies
|
|
92
|
-
// }
|
|
93
|
-
// response.headers.location += "&cake=blar"
|
|
94
|
-
// response.headers.foo = "bar"
|
|
95
|
-
return response;
|
|
74
|
+
console.log("🟢 event", event)
|
|
75
|
+
console.log("🔵 context", context)
|
|
76
|
+
|
|
77
|
+
return await handler(...args);
|
|
96
78
|
};
|
|
97
79
|
}
|