sst 3.0.8 → 3.0.10

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
  });
@@ -50,12 +50,12 @@ export function AuthHandler(input) {
50
50
  }
51
51
  const options = {
52
52
  signing: {
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
+ 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"),
55
55
  },
56
56
  encryption: {
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
+ 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"),
59
59
  },
60
60
  algorithm: "RS512",
61
61
  async success(ctx, properties) {
@@ -69,7 +69,7 @@ export function AuthHandler(input) {
69
69
  const token = await new SignJWT(session)
70
70
  .setProtectedHeader({ alg: "RS512" })
71
71
  .setExpirationTime("1yr")
72
- .sign(await options.signing.privateKey);
72
+ .sign(await options.signing.privateKey());
73
73
  deleteCookie(ctx, "provider");
74
74
  deleteCookie(ctx, "response_type");
75
75
  deleteCookie(ctx, "redirect_uri");
@@ -92,7 +92,7 @@ export function AuthHandler(input) {
92
92
  })
93
93
  .setProtectedHeader({ alg: "RS512" })
94
94
  .setExpirationTime("30s")
95
- .sign(await options.signing.privateKey);
95
+ .sign(await options.signing.privateKey());
96
96
  const location = new URL(redirect_uri);
97
97
  location.searchParams.set("code", code);
98
98
  location.searchParams.set("state", state || "");
@@ -131,7 +131,7 @@ export function AuthHandler(input) {
131
131
  c.status(400);
132
132
  return c.text("Missing code");
133
133
  }
134
- const { payload } = await jwtVerify(code, await options.signing.publicKey);
134
+ const { payload } = await jwtVerify(code, await options.signing.publicKey());
135
135
  if (payload.redirect_uri !== form.get("redirect_uri")) {
136
136
  c.status(400);
137
137
  return c.text("redirect_uri mismatch");
@@ -1,5 +1,6 @@
1
1
  import { SignJWT, importPKCS8, importSPKI, jwtVerify } from "jose";
2
2
  import { Resource } from "../resource.js";
3
+ import process from "node:process";
3
4
  export function createSessionBuilder() {
4
5
  return {
5
6
  async verify(token) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "sst",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
- "version": "3.0.8",
6
+ "version": "3.0.10",
7
7
  "main": "./dist/index.js",
8
8
  "exports": {
9
9
  ".": "./dist/index.js",