@wtfalch/auth 0.20.0 → 0.23.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/README.md +8 -1
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +37 -0
- package/dist/broker.d.ts +9 -0
- package/dist/broker.js +4 -0
- package/dist/browser.js +64 -3
- package/dist/config.d.ts +15 -0
- package/dist/config.js +26 -0
- package/dist/cookies.d.ts +3 -1
- package/dist/cookies.js +22 -2
- package/dist/index.d.ts +1 -0
- package/dist/names.d.ts +8 -0
- package/dist/names.js +11 -3
- package/dist/namespace-server.js +2 -2
- package/dist/namespace-session.js +1 -1
- package/dist/person-token.d.ts +61 -0
- package/dist/person-token.js +191 -0
- package/dist/qr-door-scene.d.ts +66 -0
- package/dist/qr-door-scene.js +404 -0
- package/dist/qr-door.d.ts +15 -0
- package/dist/qr-door.js +71 -0
- package/package.json +18 -3
package/dist/qr-door.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* `<QrDoor>`: the QR sign-in code as a React component. Draws `url` (the
|
|
5
|
+
* `url` from `startQrSignIn()`) and plays the door animation once `approved`
|
|
6
|
+
* turns true -- that is, once `pollQrSignIn()` answered `signed_in`. The
|
|
7
|
+
* drawing itself lives in `qr-door-scene.ts`; this file only owns the canvas,
|
|
8
|
+
* its size, the animation clock and reduced motion.
|
|
9
|
+
*
|
|
10
|
+
* Browser file: nothing here touches OIDC, cookies or `node:`.
|
|
11
|
+
*/
|
|
12
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
13
|
+
import { QR_DOOR_DURATION, QR_DOOR_SIZE, QR_DOOR_THEME, buildQrDoorScene, drawQrDoorRest, drawQrDoorScene, } from './qr-door-scene.js';
|
|
14
|
+
export { QR_DOOR_DURATION, QR_DOOR_THEME, buildQrDoorScene, drawQrDoorRest, drawQrDoorScene, } from './qr-door-scene.js';
|
|
15
|
+
export function QrDoor({ url, mark, approved, onDone, theme, className }) {
|
|
16
|
+
const canvasRef = useRef(null);
|
|
17
|
+
const scene = useMemo(() => buildQrDoorScene(url, mark), [url, mark]);
|
|
18
|
+
const ink = theme?.ink ?? QR_DOOR_THEME.ink;
|
|
19
|
+
const accent = theme?.accent ?? QR_DOOR_THEME.accent;
|
|
20
|
+
const paper = theme?.paper ?? QR_DOOR_THEME.paper;
|
|
21
|
+
const onDoneRef = useRef(onDone);
|
|
22
|
+
onDoneRef.current = onDone;
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const canvas = canvasRef.current;
|
|
25
|
+
const ctx = canvas?.getContext('2d');
|
|
26
|
+
if (!canvas || !ctx)
|
|
27
|
+
return;
|
|
28
|
+
const th = { ink, accent, paper };
|
|
29
|
+
const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
|
|
30
|
+
const start = performance.now();
|
|
31
|
+
let raf = 0;
|
|
32
|
+
let finished = false;
|
|
33
|
+
const fit = () => {
|
|
34
|
+
const dpr = Math.min(window.devicePixelRatio || 1, 2.5);
|
|
35
|
+
const px = Math.round((canvas.clientWidth || QR_DOOR_SIZE) * dpr);
|
|
36
|
+
// A canvas starts at 300×150, so check both sides, not just the width.
|
|
37
|
+
if (canvas.width !== px || canvas.height !== px)
|
|
38
|
+
canvas.width = canvas.height = px;
|
|
39
|
+
ctx.setTransform(px / QR_DOOR_SIZE, 0, 0, px / QR_DOOR_SIZE, 0, 0);
|
|
40
|
+
};
|
|
41
|
+
const paint = () => {
|
|
42
|
+
fit();
|
|
43
|
+
if (!approved) {
|
|
44
|
+
drawQrDoorRest(ctx, scene, th);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const t = reduce ? QR_DOOR_DURATION : (performance.now() - start) / 1000;
|
|
48
|
+
drawQrDoorScene(ctx, scene, t, th);
|
|
49
|
+
if (t >= QR_DOOR_DURATION) {
|
|
50
|
+
if (!finished) {
|
|
51
|
+
finished = true;
|
|
52
|
+
onDoneRef.current?.();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
raf = requestAnimationFrame(paint);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
paint();
|
|
60
|
+
const resize = new ResizeObserver(() => {
|
|
61
|
+
if (!approved || finished)
|
|
62
|
+
paint();
|
|
63
|
+
});
|
|
64
|
+
resize.observe(canvas);
|
|
65
|
+
return () => {
|
|
66
|
+
cancelAnimationFrame(raf);
|
|
67
|
+
resize.disconnect();
|
|
68
|
+
};
|
|
69
|
+
}, [scene, approved, ink, accent, paper]);
|
|
70
|
+
return (_jsx("canvas", { ref: canvasRef, className: className, style: { display: 'block', width: '100%', aspectRatio: '1' }, role: "img", "aria-label": approved ? 'Sign-in approved' : 'Scan this code with your phone to sign in' }));
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtfalch/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Sign in against a self-hosted ZITADEL issuer: a server session for a Next.js app, and a browser client with silent single sign-on across subdomains.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,6 +42,14 @@
|
|
|
42
42
|
"types": "./dist/sessions.d.ts",
|
|
43
43
|
"default": "./dist/sessions.js"
|
|
44
44
|
},
|
|
45
|
+
"./person-token": {
|
|
46
|
+
"types": "./dist/person-token.d.ts",
|
|
47
|
+
"default": "./dist/person-token.js"
|
|
48
|
+
},
|
|
49
|
+
"./qr-door": {
|
|
50
|
+
"types": "./dist/qr-door.d.ts",
|
|
51
|
+
"default": "./dist/qr-door.js"
|
|
52
|
+
},
|
|
45
53
|
"./testing": {
|
|
46
54
|
"types": "./dist/testing.d.ts",
|
|
47
55
|
"default": "./dist/testing.js"
|
|
@@ -59,25 +67,32 @@
|
|
|
59
67
|
"test:cookie-browser": "vitest run --config vitest.cookie-browser.config.ts"
|
|
60
68
|
},
|
|
61
69
|
"dependencies": {
|
|
70
|
+
"@wtfalch/utils": "0.1.0",
|
|
62
71
|
"jose": "^6.2.10",
|
|
63
72
|
"obscenity": "^0.4.6",
|
|
64
73
|
"openid-client": "6.8.7",
|
|
74
|
+
"qrcode": "^1.5.4",
|
|
65
75
|
"reserved-usernames": "^1.1.6"
|
|
66
76
|
},
|
|
67
77
|
"peerDependencies": {
|
|
68
|
-
"next": ">=15.0.0"
|
|
78
|
+
"next": ">=15.0.0",
|
|
79
|
+
"react": ">=19.0.0"
|
|
69
80
|
},
|
|
70
81
|
"peerDependenciesMeta": {
|
|
71
82
|
"next": {
|
|
72
83
|
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"react": {
|
|
86
|
+
"optional": true
|
|
73
87
|
}
|
|
74
88
|
},
|
|
75
89
|
"devDependencies": {
|
|
76
90
|
"@electric-sql/pglite": "^0.5.8",
|
|
77
91
|
"@types/node": "^22",
|
|
92
|
+
"@types/qrcode": "^1.5.6",
|
|
78
93
|
"@types/react": "^19",
|
|
79
94
|
"@wtfalch/auth-broker": "workspace:*",
|
|
80
|
-
"next": "^16",
|
|
95
|
+
"next": "^16.4.0",
|
|
81
96
|
"playwright-core": "^1.62.1",
|
|
82
97
|
"react": "^19",
|
|
83
98
|
"typescript": "^5.9.0",
|