@seamless-auth/express 0.0.3-beta.2 → 0.1.0
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.js +59 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -305,6 +305,47 @@ async function logout(req, res, opts) {
|
|
|
305
305
|
res.status(result.status).end();
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
// src/handlers/pollMagicLinkConfirmation.ts
|
|
309
|
+
import { pollMagicLinkConfirmationHandler } from "@seamless-auth/core/handlers/pollMagicLinkConfirmationHandler";
|
|
310
|
+
async function pollMagicLinkConfirmation(req, res, opts) {
|
|
311
|
+
const cookieSigner = {
|
|
312
|
+
secret: opts.cookieSecret,
|
|
313
|
+
secure: process.env.NODE_ENV === "production",
|
|
314
|
+
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax"
|
|
315
|
+
};
|
|
316
|
+
const authorization = buildServiceAuthorization(req, opts);
|
|
317
|
+
const result = await pollMagicLinkConfirmationHandler(
|
|
318
|
+
{ authorization },
|
|
319
|
+
{
|
|
320
|
+
authServerUrl: opts.authServerUrl,
|
|
321
|
+
cookieDomain: opts.cookieDomain,
|
|
322
|
+
accessCookieName: opts.accessCookieName,
|
|
323
|
+
refreshCookieName: opts.refreshCookieName
|
|
324
|
+
}
|
|
325
|
+
);
|
|
326
|
+
if (!cookieSigner.secret) {
|
|
327
|
+
throw new Error("Missing COOKIE_SIGNING_KEY");
|
|
328
|
+
}
|
|
329
|
+
if (result.setCookies) {
|
|
330
|
+
for (const c of result.setCookies) {
|
|
331
|
+
setSessionCookie(
|
|
332
|
+
res,
|
|
333
|
+
{
|
|
334
|
+
name: c.name,
|
|
335
|
+
payload: c.value,
|
|
336
|
+
domain: c.domain,
|
|
337
|
+
ttlSeconds: c.ttl
|
|
338
|
+
},
|
|
339
|
+
cookieSigner
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (result.error) {
|
|
344
|
+
return res.status(result.status).json(result.error);
|
|
345
|
+
}
|
|
346
|
+
res.status(result.status).json(result.body).end();
|
|
347
|
+
}
|
|
348
|
+
|
|
308
349
|
// src/createServer.ts
|
|
309
350
|
import {
|
|
310
351
|
authFetch
|
|
@@ -407,6 +448,19 @@ function createSeamlessAuthServer(opts) {
|
|
|
407
448
|
"/users/credentials",
|
|
408
449
|
proxyWithIdentity("users/credentials", "access")
|
|
409
450
|
);
|
|
451
|
+
r.get("/magic-link", proxyWithIdentity("magic-link", "preAuth", "GET"));
|
|
452
|
+
r.get("/magic-link/verify/:token", async (req, res) => {
|
|
453
|
+
const upstream = await authFetch(
|
|
454
|
+
`${resolvedOpts.authServerUrl}/magic-link/verify/${req.params.token}`,
|
|
455
|
+
{ method: "GET" }
|
|
456
|
+
);
|
|
457
|
+
const data = await upstream.json();
|
|
458
|
+
res.status(upstream.status).json(data);
|
|
459
|
+
});
|
|
460
|
+
r.get(
|
|
461
|
+
"/magic-link/check",
|
|
462
|
+
(req, res) => pollMagicLinkConfirmation(req, res, resolvedOpts)
|
|
463
|
+
);
|
|
410
464
|
return r;
|
|
411
465
|
}
|
|
412
466
|
|
|
@@ -420,8 +474,12 @@ function requireAuth(opts) {
|
|
|
420
474
|
return function(req, res, next) {
|
|
421
475
|
const token = req.cookies?.[cookieName];
|
|
422
476
|
if (!token) {
|
|
477
|
+
console.error(
|
|
478
|
+
"[SEAMLESS-AUTH-EXPRESS] - (requireAuth) - Missing expected cookie. Ensure you are using `cookieParser` in your express server",
|
|
479
|
+
cookieName
|
|
480
|
+
);
|
|
423
481
|
res.status(401).json({
|
|
424
|
-
error: "
|
|
482
|
+
error: "Failed to find authentication token required"
|
|
425
483
|
});
|
|
426
484
|
return;
|
|
427
485
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seamless-auth/express",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Express adapter for Seamless Auth passwordless authentication",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"express": ">=4.18.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@seamless-auth/core": "
|
|
40
|
+
"@seamless-auth/core": "^0.2.0",
|
|
41
41
|
"cookie-parser": "^1.4.6",
|
|
42
42
|
"jsonwebtoken": "^9.0.3"
|
|
43
43
|
},
|