@seamless-auth/express 0.0.2-beta.13 → 0.0.2-beta.14

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/index.d.ts CHANGED
@@ -4,6 +4,7 @@ type SeamlessAuthServerOptions = {
4
4
  authServerUrl: string;
5
5
  cookieSecret: string;
6
6
  serviceSecret: string;
7
+ issuer: string;
7
8
  jwksKid?: string;
8
9
  cookieDomain?: string;
9
10
  accessCookieName?: string;
@@ -181,10 +182,6 @@ interface EnsureCookiesMiddlewareOptions {
181
182
  }
182
183
  declare function createEnsureCookiesMiddleware(opts: EnsureCookiesMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
183
184
 
184
- declare function getSeamlessUser(req: Request, opts: {
185
- authServerUrl: string;
186
- cookieSecret: string;
187
- cookieName?: string;
188
- }): Promise<any>;
185
+ declare function getSeamlessUser(req: Request, opts: SeamlessAuthServerOptions): Promise<any>;
189
186
 
190
187
  export { type SeamlessAuthServerOptions, createEnsureCookiesMiddleware, createSeamlessAuthServer as default, getSeamlessUser, requireAuth, requireRole };
package/dist/index.js CHANGED
@@ -138,16 +138,16 @@ import { finishLoginHandler } from "@seamless-auth/core/handlers/finishLogin";
138
138
 
139
139
  // src/internal/buildAuthorization.ts
140
140
  import { createServiceToken } from "@seamless-auth/core";
141
- function buildServiceAuthorization(req) {
141
+ function buildServiceAuthorization(req, opts) {
142
142
  if (!req.cookiePayload?.sub && !req.user.sub) {
143
143
  return void 0;
144
144
  }
145
145
  const token = createServiceToken({
146
146
  subject: req.cookiePayload?.sub || req.user.sub,
147
- issuer: process.env.APP_ORIGIN,
148
- audience: process.env.AUTH_SERVER_URL,
149
- serviceSecret: process.env.API_SERVICE_TOKEN,
150
- keyId: "dev-main"
147
+ issuer: opts.issuer,
148
+ audience: opts.authServerUrl,
149
+ serviceSecret: opts.serviceSecret,
150
+ keyId: opts.jwksKid
151
151
  });
152
152
  return `Bearer ${token}`;
153
153
  }
@@ -159,7 +159,7 @@ async function finishLogin(req, res, opts) {
159
159
  secure: process.env.NODE_ENV === "production",
160
160
  sameSite: process.env.NODE_ENV === "production" ? "none" : "lax"
161
161
  };
162
- const authorization = buildServiceAuthorization(req);
162
+ const authorization = buildServiceAuthorization(req, opts);
163
163
  const result = await finishLoginHandler(
164
164
  { body: req.body, authorization },
165
165
  {
@@ -239,7 +239,7 @@ async function finishRegister(req, res, opts) {
239
239
  secure: process.env.NODE_ENV === "production",
240
240
  sameSite: process.env.NODE_ENV === "production" ? "none" : "lax"
241
241
  };
242
- const authorization = buildServiceAuthorization(req);
242
+ const authorization = buildServiceAuthorization(req, opts);
243
243
  const result = await finishRegisterHandler(
244
244
  { body: req.body, authorization },
245
245
  {
@@ -275,7 +275,7 @@ async function finishRegister(req, res, opts) {
275
275
  // src/handlers/me.ts
276
276
  import { meHandler } from "@seamless-auth/core/handlers/me";
277
277
  async function me(req, res, opts) {
278
- const authorization = buildServiceAuthorization(req);
278
+ const authorization = buildServiceAuthorization(req, opts);
279
279
  const result = await meHandler({
280
280
  authServerUrl: opts.authServerUrl,
281
281
  preAuthCookieName: opts.preAuthCookieName,
@@ -315,6 +315,7 @@ function createSeamlessAuthServer(opts) {
315
315
  r.use(cookieParser());
316
316
  const resolvedOpts = {
317
317
  authServerUrl: opts.authServerUrl,
318
+ issuer: opts.issuer,
318
319
  cookieSecret: opts.cookieSecret,
319
320
  serviceSecret: opts.serviceSecret,
320
321
  jwksKid: opts.jwksKid ?? "dev-main",
@@ -341,7 +342,7 @@ function createSeamlessAuthServer(opts) {
341
342
  res.status(401).json({ error: "registeration session required" });
342
343
  return;
343
344
  }
344
- const authorization = buildServiceAuthorization(req);
345
+ const authorization = buildServiceAuthorization(req, resolvedOpts);
345
346
  const options = method == "GET" ? { method, authorization } : { method, authorization, body: req.body };
346
347
  const upstream = await authFetch(
347
348
  `${resolvedOpts.authServerUrl}/${path}`,
@@ -360,7 +361,7 @@ function createSeamlessAuthServer(opts) {
360
361
  preAuthCookieName: resolvedOpts.preAuthCookieName,
361
362
  cookieSecret: resolvedOpts.cookieSecret,
362
363
  serviceSecret: resolvedOpts.serviceSecret,
363
- issuer: process.env.APP_ORIGIN,
364
+ issuer: resolvedOpts.issuer,
364
365
  audience: resolvedOpts.authServerUrl,
365
366
  keyId: resolvedOpts.jwksKid
366
367
  })
@@ -478,11 +479,11 @@ import {
478
479
  getSeamlessUser as getSeamlessUserCore
479
480
  } from "@seamless-auth/core";
480
481
  async function getSeamlessUser(req, opts) {
481
- const authorization = buildServiceAuthorization(req);
482
+ const authorization = buildServiceAuthorization(req, opts);
482
483
  return getSeamlessUserCore(req.cookies ?? {}, {
483
484
  authServerUrl: opts.authServerUrl,
484
485
  cookieSecret: opts.cookieSecret,
485
- cookieName: opts.cookieName ?? "seamless-access",
486
+ cookieName: opts.accessCookieName ?? "seamless-access",
486
487
  authorization
487
488
  });
488
489
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamless-auth/express",
3
- "version": "0.0.2-beta.13",
3
+ "version": "0.0.2-beta.14",
4
4
  "description": "Express adapter for Seamless Auth passwordless authentication",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",