@micha.bigler/ui-core-micha 1.4.34 → 1.4.35
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/pages/LoginPage.js
CHANGED
|
@@ -2,8 +2,14 @@ import { getPasskeyRegistrationOptions, completePasskeyRegistration, getPasskeyL
|
|
|
2
2
|
import { ensureWebAuthnSupport, serializeCredential } from '../utils/webauthn';
|
|
3
3
|
import { normaliseApiError } from '../utils/auth-errors';
|
|
4
4
|
import apiClient from '../auth/apiClient';
|
|
5
|
-
// Falls du die Konstanten importieren möchtest, um Hardcoding zu vermeiden:
|
|
6
5
|
import { HEADLESS_BASE } from '../auth/authConfig';
|
|
6
|
+
// HILFSFUNKTION: Entpackt die Optionen, falls sie in 'publicKey' stecken
|
|
7
|
+
function resolveWebAuthnOptions(options) {
|
|
8
|
+
if (options && options.publicKey) {
|
|
9
|
+
return options.publicKey;
|
|
10
|
+
}
|
|
11
|
+
return options;
|
|
12
|
+
}
|
|
7
13
|
export async function registerPasskey(name = 'Passkey') {
|
|
8
14
|
ensureWebAuthnSupport();
|
|
9
15
|
// 1. Get Options from Server
|
|
@@ -11,8 +17,10 @@ export async function registerPasskey(name = 'Passkey') {
|
|
|
11
17
|
// 2. Call Browser API
|
|
12
18
|
let credential;
|
|
13
19
|
try {
|
|
20
|
+
// FIX: Erst entpacken (JSON -> JSON ohne publicKey Wrapper)
|
|
21
|
+
const optionsJson = resolveWebAuthnOptions(creationOptions);
|
|
22
|
+
// Dann parsen (JSON -> ArrayBuffer)
|
|
14
23
|
const publicKeyOptions = window.PublicKeyCredential.parseCreationOptionsFromJSON(creationOptions);
|
|
15
|
-
// KORREKTUR: Wir MÜSSEN { publicKey: ... } wrappen!
|
|
16
24
|
credential = await navigator.credentials.create({ publicKey: publicKeyOptions });
|
|
17
25
|
}
|
|
18
26
|
catch (err) {
|
|
@@ -32,8 +40,10 @@ export async function loginWithPasskey() {
|
|
|
32
40
|
// 2. Browser Sign
|
|
33
41
|
let assertion;
|
|
34
42
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
// FIX: Erst entpacken
|
|
44
|
+
const optionsJson = resolveWebAuthnOptions(requestOptions);
|
|
45
|
+
// Dann parsen
|
|
46
|
+
const publicKeyOptions = window.PublicKeyCredential.parseRequestOptionsFromJSON(optionsJson);
|
|
37
47
|
assertion = await navigator.credentials.get({ publicKey: publicKeyOptions });
|
|
38
48
|
}
|
|
39
49
|
catch (err) {
|
|
@@ -56,11 +66,11 @@ export async function authenticateMfaWithPasskey() {
|
|
|
56
66
|
ensureWebAuthnSupport();
|
|
57
67
|
let requestOptions;
|
|
58
68
|
try {
|
|
59
|
-
// Nutze HEADLESS_BASE falls verfügbar, sonst den Pfad
|
|
60
69
|
const url = typeof HEADLESS_BASE !== 'undefined'
|
|
61
70
|
? `${HEADLESS_BASE}/auth/2fa/authenticate`
|
|
62
71
|
: '/api/auth/browser/v1/auth/2fa/authenticate';
|
|
63
72
|
const res = await apiClient.get(url);
|
|
73
|
+
// Allauth liefert oft: { data: { request_options: { publicKey: ... } } }
|
|
64
74
|
const data = ((_a = res.data) === null || _a === void 0 ? void 0 : _a.data) || res.data;
|
|
65
75
|
requestOptions = data.request_options || data;
|
|
66
76
|
}
|
|
@@ -73,8 +83,11 @@ export async function authenticateMfaWithPasskey() {
|
|
|
73
83
|
// 2. Browser Sign
|
|
74
84
|
let assertion;
|
|
75
85
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
// FIX: Erst entpacken
|
|
87
|
+
const optionsJson = resolveWebAuthnOptions(requestOptions);
|
|
88
|
+
// Dann parsen
|
|
89
|
+
const publicKeyOptions = window.PublicKeyCredential.parseRequestOptionsFromJSON(optionsJson);
|
|
90
|
+
// Dann wrappen
|
|
78
91
|
assertion = await navigator.credentials.get({ publicKey: publicKeyOptions });
|
|
79
92
|
}
|
|
80
93
|
catch (err) {
|
package/package.json
CHANGED
package/src/pages/LoginPage.jsx
CHANGED
|
@@ -92,7 +92,7 @@ export function LoginPage() {
|
|
|
92
92
|
setSubmitting(true);
|
|
93
93
|
try {
|
|
94
94
|
// Service handles browser interaction + API calls
|
|
95
|
-
const
|
|
95
|
+
const user = await loginWithPasskey();
|
|
96
96
|
handleLoginSuccess(user);
|
|
97
97
|
} catch (err) {
|
|
98
98
|
// 'Auth.PASSKEY_CANCELLED' is generic, maybe ignore visually or show specific hint
|
package/src/utils/authService.js
CHANGED
|
@@ -13,9 +13,16 @@ import {
|
|
|
13
13
|
} from '../utils/webauthn';
|
|
14
14
|
import { normaliseApiError } from '../utils/auth-errors';
|
|
15
15
|
import apiClient from '../auth/apiClient';
|
|
16
|
-
// Falls du die Konstanten importieren möchtest, um Hardcoding zu vermeiden:
|
|
17
16
|
import { HEADLESS_BASE } from '../auth/authConfig';
|
|
18
17
|
|
|
18
|
+
// HILFSFUNKTION: Entpackt die Optionen, falls sie in 'publicKey' stecken
|
|
19
|
+
function resolveWebAuthnOptions(options) {
|
|
20
|
+
if (options && options.publicKey) {
|
|
21
|
+
return options.publicKey;
|
|
22
|
+
}
|
|
23
|
+
return options;
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
export async function registerPasskey(name = 'Passkey') {
|
|
20
27
|
ensureWebAuthnSupport();
|
|
21
28
|
|
|
@@ -25,8 +32,12 @@ export async function registerPasskey(name = 'Passkey') {
|
|
|
25
32
|
// 2. Call Browser API
|
|
26
33
|
let credential;
|
|
27
34
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
// FIX: Erst entpacken (JSON -> JSON ohne publicKey Wrapper)
|
|
36
|
+
const optionsJson = resolveWebAuthnOptions(creationOptions);
|
|
37
|
+
|
|
38
|
+
// Dann parsen (JSON -> ArrayBuffer)
|
|
39
|
+
const publicKeyOptions =
|
|
40
|
+
window.PublicKeyCredential.parseCreationOptionsFromJSON(creationOptions);
|
|
30
41
|
credential = await navigator.credentials.create({ publicKey: publicKeyOptions });
|
|
31
42
|
} catch (err) {
|
|
32
43
|
if (err.name === 'NotAllowedError') {
|
|
@@ -49,8 +60,12 @@ export async function loginWithPasskey() {
|
|
|
49
60
|
// 2. Browser Sign
|
|
50
61
|
let assertion;
|
|
51
62
|
try {
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
// FIX: Erst entpacken
|
|
64
|
+
const optionsJson = resolveWebAuthnOptions(requestOptions);
|
|
65
|
+
|
|
66
|
+
// Dann parsen
|
|
67
|
+
const publicKeyOptions =
|
|
68
|
+
window.PublicKeyCredential.parseRequestOptionsFromJSON(optionsJson);
|
|
54
69
|
assertion = await navigator.credentials.get({ publicKey: publicKeyOptions });
|
|
55
70
|
} catch (err) {
|
|
56
71
|
if (err.name === 'NotAllowedError') {
|
|
@@ -75,12 +90,12 @@ export async function authenticateMfaWithPasskey() {
|
|
|
75
90
|
|
|
76
91
|
let requestOptions;
|
|
77
92
|
try {
|
|
78
|
-
// Nutze HEADLESS_BASE falls verfügbar, sonst den Pfad
|
|
79
93
|
const url = typeof HEADLESS_BASE !== 'undefined'
|
|
80
94
|
? `${HEADLESS_BASE}/auth/2fa/authenticate`
|
|
81
95
|
: '/api/auth/browser/v1/auth/2fa/authenticate';
|
|
82
96
|
|
|
83
97
|
const res = await apiClient.get(url);
|
|
98
|
+
// Allauth liefert oft: { data: { request_options: { publicKey: ... } } }
|
|
84
99
|
const data = res.data?.data || res.data;
|
|
85
100
|
requestOptions = data.request_options || data;
|
|
86
101
|
} catch (err) {
|
|
@@ -94,8 +109,13 @@ export async function authenticateMfaWithPasskey() {
|
|
|
94
109
|
// 2. Browser Sign
|
|
95
110
|
let assertion;
|
|
96
111
|
try {
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
// FIX: Erst entpacken
|
|
113
|
+
const optionsJson = resolveWebAuthnOptions(requestOptions);
|
|
114
|
+
|
|
115
|
+
// Dann parsen
|
|
116
|
+
const publicKeyOptions = window.PublicKeyCredential.parseRequestOptionsFromJSON(optionsJson);
|
|
117
|
+
|
|
118
|
+
// Dann wrappen
|
|
99
119
|
assertion = await navigator.credentials.get({ publicKey: publicKeyOptions });
|
|
100
120
|
} catch (err) {
|
|
101
121
|
if (err.name === 'NotAllowedError') {
|