@server/next 0.47.0 → 0.47.2

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.
Files changed (3) hide show
  1. package/index.d.ts +2 -2
  2. package/index.js +29 -10
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -212,7 +212,7 @@ type AuthConfig<U = AuthProfile> = {
212
212
  onLogout?: (id: string, ctx: Context) => Awaitable<void>;
213
213
  };
214
214
  type AuthVerify<U = AuthClaims> = {
215
- verify: string;
215
+ issuer: string;
216
216
  audience: string | readonly string[];
217
217
  cookie?: string;
218
218
  audienceClaim?: string | readonly string[];
@@ -228,7 +228,7 @@ type AuthOption = string | AuthFunction | AuthConfig<any> | AuthVerify<any> | Au
228
228
  type UserOf<A> = A extends readonly (infer M)[] ? UserOf<M> : A extends (...args: any[]) => infer R ? NonNullable<Awaited<R>> : A extends {
229
229
  getUser: (...args: any[]) => infer R;
230
230
  } ? NonNullable<Awaited<R>> : A extends {
231
- verify: any;
231
+ issuer: any;
232
232
  } ? AuthClaims : A extends {
233
233
  providers: any;
234
234
  } ? AuthProfile : A extends string ? AuthProfile : never;
package/index.js CHANGED
@@ -1251,12 +1251,12 @@ var CLASSES = {
1251
1251
  yahoo: Yahoo,
1252
1252
  yandex: Yandex,
1253
1253
  zoom: Zoom,
1254
- 42: FortyTwo
1254
+ fortytwo: FortyTwo
1255
1255
  };
1256
1256
  var ALIASES = {
1257
- microsoft: "microsoftentraid",
1258
1257
  cognito: "amazoncognito",
1259
- entra: "microsoftentraid"
1258
+ entra: "microsoftentraid",
1259
+ microsoft: "microsoftentraid"
1260
1260
  };
1261
1261
  var providers = Object.fromEntries(
1262
1262
  Object.entries(CLASSES).map(([name, Client]) => [
@@ -1265,7 +1265,7 @@ var providers = Object.fromEntries(
1265
1265
  ])
1266
1266
  );
1267
1267
  for (const [alias, target2] of Object.entries(ALIASES)) {
1268
- providers[alias] = providers[target2];
1268
+ providers[alias] = antarcticProvider(alias, CLASSES[target2]);
1269
1269
  }
1270
1270
  var ISSUERS = {
1271
1271
  paypal: "https://www.paypal.com"
@@ -1421,6 +1421,12 @@ function entry(config2) {
1421
1421
  );
1422
1422
  }
1423
1423
  }
1424
+ const publicProfile = ({ id, email, name, avatar }) => ({
1425
+ id,
1426
+ email,
1427
+ name,
1428
+ avatar
1429
+ });
1424
1430
  const redirects = typeof config2.redirect === "object" ? config2.redirect : {};
1425
1431
  const loginTo = typeof config2.redirect === "object" ? redirects.login : config2.redirect;
1426
1432
  const finish = async (ctx, profile) => {
@@ -1432,7 +1438,7 @@ function entry(config2) {
1432
1438
  if (!isSigned(strategies[0])) return { sub: String(id) };
1433
1439
  const user2 = await getUser(String(id), ctx);
1434
1440
  return { user: await toPublicUser(user2) };
1435
- })() : { user: profile };
1441
+ })() : { user: publicProfile(profile) };
1436
1442
  const signed = { ...payload, provider: profile.provider };
1437
1443
  const token = await issue(ctx, signed, expires);
1438
1444
  const user = signed.user ?? await getUser(signed.sub, ctx);
@@ -1566,11 +1572,11 @@ var bearer2 = (ctx) => {
1566
1572
  return token;
1567
1573
  };
1568
1574
  function entry2(options) {
1569
- const { verify: issuer, audience } = options;
1575
+ const { issuer, audience } = options;
1570
1576
  const claimNames = options.audienceClaim ? Array.isArray(options.audienceClaim) ? options.audienceClaim : [options.audienceClaim] : ["aud"];
1571
1577
  if (!audience) {
1572
1578
  throw new Error(
1573
- "`verify` needs an `audience`: one issuer serves many applications, and without it a token minted for another one is accepted here."
1579
+ "`issuer` needs an `audience`: one issuer serves many applications, and without it a token minted for another one is accepted here."
1574
1580
  );
1575
1581
  }
1576
1582
  const allowed = Array.isArray(audience) ? audience : [audience];
@@ -1639,6 +1645,19 @@ var VENDORS = {
1639
1645
  claim: "azp",
1640
1646
  docs: "https://clerk.com/docs/backend-requests/resources/session-tokens"
1641
1647
  },
1648
+ firebase: {
1649
+ // The client SDK holds the token and sends it as a header, so no cookie.
1650
+ // Both halves are the project id: the issuer is per-project, and it is
1651
+ // what Firebase puts in `aud`.
1652
+ audience: "your Firebase project id",
1653
+ docs: "https://firebase.google.com/docs/auth/admin/verify-id-tokens"
1654
+ },
1655
+ // Google Cloud Identity Platform is the same service, and the same tokens,
1656
+ // under its enterprise name
1657
+ gcip: {
1658
+ audience: "your Google Cloud project id",
1659
+ docs: "https://cloud.google.com/identity-platform/docs/how-to-verify-tokens"
1660
+ },
1642
1661
  supabase: {
1643
1662
  audience: '"authenticated"',
1644
1663
  docs: "https://supabase.com/docs/guides/auth/jwts"
@@ -1678,7 +1697,7 @@ function vendorEntry(strategy, name) {
1678
1697
  );
1679
1698
  }
1680
1699
  return entry2({
1681
- verify: issuer,
1700
+ issuer,
1682
1701
  audience,
1683
1702
  ...vendor.claim ? { audienceClaim: vendor.claim } : {},
1684
1703
  ...strategy === "cookie" ? { cookie: vendor.cookie } : {}
@@ -1699,7 +1718,7 @@ function toEntry(auth2) {
1699
1718
  return [{ name: "function", user: async (ctx) => auth2(ctx) }];
1700
1719
  }
1701
1720
  if (auth2 && typeof auth2 === "object") {
1702
- if ("verify" in auth2) return [entry2(auth2)];
1721
+ if ("issuer" in auth2) return [entry2(auth2)];
1703
1722
  if ("providers" in auth2) return [entry(auth2)];
1704
1723
  if ("handler" in auth2) {
1705
1724
  const instance = auth2;
@@ -1731,7 +1750,7 @@ function toEntry(auth2) {
1731
1750
  }
1732
1751
  }
1733
1752
  throw new Error(
1734
- "Invalid `auth`: it takes a string, a function, `{ providers }`, `{ verify, audience }`, a library instance, or an array of those."
1753
+ "Invalid `auth`: it takes a string, a function, `{ providers }`, `{ issuer, audience }`, a library instance, or an array of those."
1735
1754
  );
1736
1755
  }
1737
1756
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.47.0",
3
+ "version": "0.47.2",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "github:franciscop/server-next",