sst 3.0.7 → 3.0.9

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.
@@ -7,12 +7,12 @@ export interface AdapterOptions<Properties> {
7
7
  name: string;
8
8
  algorithm: string;
9
9
  encryption: {
10
- publicKey: Promise<KeyLike>;
11
- privateKey: Promise<KeyLike>;
10
+ publicKey: () => Promise<KeyLike>;
11
+ privateKey: () => Promise<KeyLike>;
12
12
  };
13
13
  signing: {
14
- publicKey: Promise<KeyLike>;
15
- privateKey: Promise<KeyLike>;
14
+ publicKey: () => Promise<KeyLike>;
15
+ privateKey: () => Promise<KeyLike>;
16
16
  };
17
17
  success: (ctx: Context, properties: Properties) => Promise<Response>;
18
18
  forward: (ctx: Context, response: Response) => Response;
@@ -23,7 +23,7 @@ export function CodeAdapter(config) {
23
23
  code,
24
24
  })))
25
25
  .setProtectedHeader({ alg: "RSA-OAEP-512", enc: "A256GCM" })
26
- .encrypt(await ctx.encryption.publicKey);
26
+ .encrypt(await ctx.encryption.publicKey());
27
27
  ctx.cookie(c, "authorization", authorization, 60 * 10);
28
28
  return ctx.forward(c, await config.onCodeRequest(code, claims, c.req.raw));
29
29
  });
@@ -31,7 +31,7 @@ export function CodeAdapter(config) {
31
31
  const authorization = getCookie(c, "authorization");
32
32
  if (!authorization)
33
33
  throw new UnknownStateError();
34
- const { code, claims } = JSON.parse(new TextDecoder().decode(await compactDecrypt(authorization, await ctx.encryption.privateKey).then((value) => value.plaintext)));
34
+ const { code, claims } = JSON.parse(new TextDecoder().decode(await compactDecrypt(authorization, await ctx.encryption.privateKey()).then((value) => value.plaintext)));
35
35
  if (!code || !claims) {
36
36
  return ctx.forward(c, await config.onCodeInvalid(code, claims, c.req.raw));
37
37
  }
@@ -5,7 +5,7 @@ export function LinkAdapter(config) {
5
5
  const token = await new SignJWT(c.req.query())
6
6
  .setProtectedHeader({ alg: ctx.algorithm })
7
7
  .setExpirationTime("10m")
8
- .sign(await ctx.signing.privateKey);
8
+ .sign(await ctx.signing.privateKey());
9
9
  const url = new URL(new URL(c.req.url).origin);
10
10
  url.pathname = `/${ctx.name}/callback`;
11
11
  for (const key of url.searchParams.keys()) {
@@ -19,7 +19,7 @@ export function LinkAdapter(config) {
19
19
  const token = c.req.query("token");
20
20
  if (!token)
21
21
  throw new Error("Missing token parameter");
22
- const verified = await jwtVerify(token, await ctx.signing.publicKey);
22
+ const verified = await jwtVerify(token, await ctx.signing.publicKey());
23
23
  const resp = await ctx.success(c, { claims: verified.payload });
24
24
  return resp;
25
25
  });
@@ -34,6 +34,8 @@ export class InvalidSessionError extends Error {
34
34
  super("Invalid session");
35
35
  }
36
36
  }
37
+ import process from "node:process";
38
+ import { Resource } from "../resource.js";
37
39
  export function AuthHandler(input) {
38
40
  const app = new Hono();
39
41
  if (!input.callbacks.auth.error) {
@@ -48,12 +50,12 @@ export function AuthHandler(input) {
48
50
  }
49
51
  const options = {
50
52
  signing: {
51
- privateKey: importPKCS8(process.env.AUTH_PRIVATE_KEY, "RS512"),
52
- publicKey: importSPKI(process.env.AUTH_PUBLIC_KEY, "RS512"),
53
+ privateKey: () => importPKCS8(process.env.AUTH_PRIVATE_KEY || Resource.AUTH_PRIVATE_KEY, "RS512"),
54
+ publicKey: () => importSPKI(process.env.AUTH_PUBLIC_KEY || Resource.AUTH_PUBLIC_KEY, "RS512"),
53
55
  },
54
56
  encryption: {
55
- privateKey: importPKCS8(process.env.AUTH_PRIVATE_KEY, "RSA-OAEP-512"),
56
- publicKey: importSPKI(process.env.AUTH_PUBLIC_KEY, "RSA-OAEP-512"),
57
+ privateKey: () => importPKCS8(process.env.AUTH_PRIVATE_KEY || Resource.AUTH_PRIVATE_KEY, "RSA-OAEP-512"),
58
+ publicKey: () => importSPKI(process.env.AUTH_PUBLIC_KEY || Resource.AUTH_PUBLIC_KEY, "RSA-OAEP-512"),
57
59
  },
58
60
  algorithm: "RS512",
59
61
  async success(ctx, properties) {
@@ -67,7 +69,7 @@ export function AuthHandler(input) {
67
69
  const token = await new SignJWT(session)
68
70
  .setProtectedHeader({ alg: "RS512" })
69
71
  .setExpirationTime("1yr")
70
- .sign(await options.signing.privateKey);
72
+ .sign(await options.signing.privateKey());
71
73
  deleteCookie(ctx, "provider");
72
74
  deleteCookie(ctx, "response_type");
73
75
  deleteCookie(ctx, "redirect_uri");
@@ -90,7 +92,7 @@ export function AuthHandler(input) {
90
92
  })
91
93
  .setProtectedHeader({ alg: "RS512" })
92
94
  .setExpirationTime("30s")
93
- .sign(await options.signing.privateKey);
95
+ .sign(await options.signing.privateKey());
94
96
  const location = new URL(redirect_uri);
95
97
  location.searchParams.set("code", code);
96
98
  location.searchParams.set("state", state || "");
@@ -129,7 +131,7 @@ export function AuthHandler(input) {
129
131
  c.status(400);
130
132
  return c.text("Missing code");
131
133
  }
132
- const { payload } = await jwtVerify(code, await options.signing.publicKey);
134
+ const { payload } = await jwtVerify(code, await options.signing.publicKey());
133
135
  if (payload.redirect_uri !== form.get("redirect_uri")) {
134
136
  c.status(400);
135
137
  return c.text("redirect_uri mismatch");
@@ -12,7 +12,7 @@ export function createSessionBuilder() {
12
12
  return result.payload;
13
13
  },
14
14
  async create(session) {
15
- const privateKey = await importPKCS8(process.env.AUTH_PRIVATE_KEY, "RS512");
15
+ const privateKey = await importPKCS8(process.env.AUTH_PRIVATE_KEY || Resource.AUTH_PRIVATE_KEY, "RS512");
16
16
  const token = await new SignJWT(session)
17
17
  .setProtectedHeader({ alg: "RS512" })
18
18
  .setExpirationTime("1yr")
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "sst",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
- "version": "3.0.7",
6
+ "version": "3.0.9",
7
7
  "main": "./dist/index.js",
8
8
  "exports": {
9
9
  ".": "./dist/index.js",