@arcblock/did-connect-react 3.1.30 → 3.1.31
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/lib/Connect/components/login-item/connect-choose-list.js +104 -102
- package/lib/Connect/plugins/email/list-item.js +13 -11
- package/lib/OAuth/context.js +98 -89
- package/lib/OAuth/passport-switcher.js +3 -112
- package/lib/Passkey/context.js +65 -54
- package/lib/Session/handler.js +55 -0
- package/lib/Session/hooks/use-session-token.js +109 -105
- package/lib/Session/index.js +455 -425
- package/lib/Session/libs/constants.js +5 -2
- package/lib/components/PassportSwitcher.js +128 -0
- package/lib/package.json.js +1 -1
- package/package.json +5 -5
- package/src/Connect/components/login-item/connect-choose-list.jsx +6 -0
- package/src/Connect/plugins/email/list-item.jsx +2 -0
- package/src/OAuth/context.jsx +15 -6
- package/src/OAuth/passport-switcher.jsx +2 -133
- package/src/Passkey/context.jsx +13 -5
- package/src/Session/handler.jsx +98 -0
- package/src/Session/hooks/use-session-token.js +12 -0
- package/src/Session/index.jsx +103 -31
- package/src/Session/libs/constants.js +3 -0
- package/src/components/PassportSwitcher.jsx +160 -0
package/lib/OAuth/context.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { createContext as
|
|
5
|
-
import
|
|
6
|
-
import { useReactive as m, useMemoizedFn as d, useCreation as
|
|
1
|
+
import { jsxs as K, jsx as W } from "react/jsx-runtime";
|
|
2
|
+
import l from "prop-types";
|
|
3
|
+
import Y from "lodash/isUndefined";
|
|
4
|
+
import { createContext as $, use as J } from "react";
|
|
5
|
+
import h from "@arcblock/ux/lib/Toast";
|
|
6
|
+
import { useReactive as m, useMemoizedFn as d, useCreation as Q, useLatest as Z } from "ahooks";
|
|
7
7
|
import v from "lodash/noop";
|
|
8
8
|
import R from "lodash/omit";
|
|
9
|
-
import { joinURL as
|
|
10
|
-
import { translate as
|
|
9
|
+
import { joinURL as ee } from "ufo";
|
|
10
|
+
import { translate as te } from "@arcblock/ux/lib/Locale/util";
|
|
11
11
|
import { getBlockletData as S, getFederatedEnabled as k, getMaster as F } from "@arcblock/ux/lib/Util/federated";
|
|
12
12
|
import { BLOCKLET_SERVICE_PATH_PREFIX as B, LOGIN_PROVIDER_NAME as A } from "@arcblock/ux/lib/Util/constant";
|
|
13
|
-
import { createAxios as
|
|
14
|
-
import { parseResponse as
|
|
15
|
-
const E =
|
|
13
|
+
import { createAxios as oe, openPopup as re, runPopup as ne, sleep as ie, getApiErrorMessage as O } from "../utils.js";
|
|
14
|
+
import { parseResponse as se, PassportSwitcher as ae } from "../components/PassportSwitcher.js";
|
|
15
|
+
const E = $({}), { Provider: de, Consumer: Le } = E, C = `${B}/api/oauth`, ce = {
|
|
16
16
|
zh: {
|
|
17
17
|
bindOAuth: "绑定第三方登录",
|
|
18
18
|
bind: "绑定",
|
|
@@ -40,7 +40,14 @@ const E = Y({}), { Provider: at, Consumer: yt } = E, C = `${B}/api/oauth`, dt =
|
|
|
40
40
|
noPassports: "No passports to switch"
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
function
|
|
43
|
+
function ue({
|
|
44
|
+
children: w,
|
|
45
|
+
locale: p = "en",
|
|
46
|
+
onBindOAuth: T = v,
|
|
47
|
+
onUnbindOAuth: j = v,
|
|
48
|
+
onSwitchPassport: x = v,
|
|
49
|
+
session: M = null
|
|
50
|
+
}) {
|
|
44
51
|
const o = m({
|
|
45
52
|
baseUrl: "/",
|
|
46
53
|
bindFnSession: void 0,
|
|
@@ -54,7 +61,7 @@ function ct({ children: w, locale: p = "en", onBindOAuth: T = v, onUnbindOAuth:
|
|
|
54
61
|
reset() {
|
|
55
62
|
i.open = !1, i.currentUser = null, i.passports = [], i.selectedPassport = void 0;
|
|
56
63
|
}
|
|
57
|
-
}),
|
|
64
|
+
}), b = m({
|
|
58
65
|
user: null,
|
|
59
66
|
// loginLoading: false,
|
|
60
67
|
checking: !1,
|
|
@@ -62,13 +69,13 @@ function ct({ children: w, locale: p = "en", onBindOAuth: T = v, onUnbindOAuth:
|
|
|
62
69
|
error: "",
|
|
63
70
|
status: "",
|
|
64
71
|
// scanned, succeed, error
|
|
65
|
-
reset({ status:
|
|
66
|
-
|
|
72
|
+
reset({ status: t = "" } = {}) {
|
|
73
|
+
b.loading = !!t, b.checking = !1, b.error = "", b.status = t;
|
|
67
74
|
}
|
|
68
|
-
}), s = d((
|
|
75
|
+
}), s = d((t, e = {}) => te(ce, t, p, "en", e)), _ = Q(() => oe({
|
|
69
76
|
// NOTICE: 请求必须向当前站点发起
|
|
70
77
|
baseURL: C
|
|
71
|
-
}), [o.baseUrl, C]),
|
|
78
|
+
}), [o.baseUrl, C]), g = Z(_), P = d(async () => {
|
|
72
79
|
if (o.baseUrl === "/")
|
|
73
80
|
return window.blocklet;
|
|
74
81
|
try {
|
|
@@ -77,158 +84,160 @@ function ct({ children: w, locale: p = "en", onBindOAuth: T = v, onUnbindOAuth:
|
|
|
77
84
|
} catch {
|
|
78
85
|
}
|
|
79
86
|
return await S(o.baseUrl);
|
|
80
|
-
}), U = d(async ({ sourceAppPid:
|
|
81
|
-
const
|
|
82
|
-
return r && n?.appPid &&
|
|
83
|
-
}),
|
|
84
|
-
const
|
|
85
|
-
return Object.entries(
|
|
86
|
-
}), y = d(async ({ provider:
|
|
87
|
-
const
|
|
87
|
+
}), U = d(async ({ sourceAppPid: t } = {}) => {
|
|
88
|
+
const e = await P(), r = k(e), n = F(e);
|
|
89
|
+
return r && n?.appPid && t === n?.appPid ? (await S(n.appUrl))?.settings?.oauth || {} : e?.settings?.oauth || {};
|
|
90
|
+
}), q = d(async ({ sourceAppPid: t } = {}) => {
|
|
91
|
+
const e = await U({ sourceAppPid: t });
|
|
92
|
+
return Object.entries(e).map(([n, c]) => ({ ...c, provider: n })).filter((n) => n.enabled).sort((n, c) => n?.order !== void 0 && c?.order !== void 0 ? n.order - c.order : n?.order !== void 0 ? -1 : 1);
|
|
93
|
+
}), y = d(async ({ provider: t } = {}) => {
|
|
94
|
+
const e = re(ee(o.baseUrl, B, "/oauth/login", t), {
|
|
88
95
|
name: "oauth-login:popup",
|
|
89
96
|
offsetX: 650,
|
|
90
97
|
height: 700,
|
|
91
98
|
width: 500
|
|
92
99
|
});
|
|
93
100
|
try {
|
|
94
|
-
const r = await
|
|
95
|
-
popup:
|
|
101
|
+
const r = await ne({
|
|
102
|
+
popup: e,
|
|
96
103
|
closeTimeout: 0
|
|
97
104
|
});
|
|
98
105
|
return r?.response ? r.response?.code : null;
|
|
99
106
|
} catch (r) {
|
|
100
107
|
throw r?.message === "Popup closed" ? new Error(s("cancelAuth")) : r;
|
|
101
108
|
}
|
|
102
|
-
}),
|
|
103
|
-
o.bindFnSession =
|
|
109
|
+
}), I = async ({ session: t, oauthItem: e } = {}) => {
|
|
110
|
+
o.bindFnSession = t, o.bindAuthLoading = !0;
|
|
104
111
|
try {
|
|
105
|
-
const r = await y(
|
|
106
|
-
await
|
|
112
|
+
const r = await y(e), n = o.bindFnSession?.user?.sourceAppPid;
|
|
113
|
+
await g.current.post("/bind", {
|
|
107
114
|
locale: p,
|
|
108
|
-
provider:
|
|
115
|
+
provider: e.provider,
|
|
109
116
|
code: r,
|
|
110
117
|
sourceAppPid: n
|
|
111
|
-
}),
|
|
118
|
+
}), h.success(s("bindOAuthSucceed", { provider: A[e.provider] })), T(e);
|
|
112
119
|
} catch (r) {
|
|
113
|
-
|
|
120
|
+
h.error(O(r, s("bindOAuthFailed", { provider: A[e.provider] })));
|
|
114
121
|
} finally {
|
|
115
122
|
o.bindAuthLoading = !1;
|
|
116
123
|
}
|
|
117
|
-
},
|
|
124
|
+
}, D = async ({ session: t, connectedAccount: e }) => {
|
|
118
125
|
o.unbindAuthLoading = !0;
|
|
119
126
|
try {
|
|
120
|
-
const r =
|
|
121
|
-
await
|
|
127
|
+
const r = t?.user?.sourceAppPid;
|
|
128
|
+
await g.current.post("/unbind", {
|
|
122
129
|
locale: p,
|
|
123
|
-
connectedAccount: R(
|
|
130
|
+
connectedAccount: R(e, ["showProvider"]),
|
|
124
131
|
sourceAppPid: r
|
|
125
|
-
}),
|
|
132
|
+
}), h.success(
|
|
126
133
|
s("unbindOAuthSucceed", {
|
|
127
|
-
provider: A[
|
|
134
|
+
provider: A[e.showProvider || e.provider]
|
|
128
135
|
})
|
|
129
|
-
),
|
|
136
|
+
), j(e);
|
|
130
137
|
} catch (r) {
|
|
131
|
-
|
|
138
|
+
h.error(
|
|
132
139
|
O(
|
|
133
140
|
r,
|
|
134
141
|
s("unbindOAuthFailed", {
|
|
135
|
-
provider: A[
|
|
142
|
+
provider: A[e.showProvider || e.provider]
|
|
136
143
|
})
|
|
137
144
|
)
|
|
138
145
|
);
|
|
139
146
|
} finally {
|
|
140
147
|
o.unbindAuthLoading = !1;
|
|
141
148
|
}
|
|
142
|
-
},
|
|
149
|
+
}, N = async (t = {}) => {
|
|
143
150
|
try {
|
|
144
|
-
const { data:
|
|
145
|
-
|
|
146
|
-
} catch (
|
|
147
|
-
|
|
151
|
+
const { data: e } = await g.current.get("/passports");
|
|
152
|
+
e.length > 0 ? (i.open = !0, i.currentUser = t, i.passports = e || []) : h.error(s("noPassports"));
|
|
153
|
+
} catch (e) {
|
|
154
|
+
h.error(e.message || s("getPassportFailed"));
|
|
148
155
|
}
|
|
149
|
-
},
|
|
150
|
-
i.reset(),
|
|
151
|
-
}),
|
|
152
|
-
o.baseUrl =
|
|
153
|
-
},
|
|
156
|
+
}, z = d((...t) => {
|
|
157
|
+
i.reset(), x(...t);
|
|
158
|
+
}), V = (t) => {
|
|
159
|
+
o.baseUrl = t || "/";
|
|
160
|
+
}, X = d(async ({ provider: t } = {}, { action: e = "login", ...r } = {}) => {
|
|
154
161
|
const n = o.baseUrl;
|
|
155
162
|
if (r?.sourceAppPid === window.blocklet?.appPid)
|
|
156
163
|
o.baseUrl = window.blocklet?.appUrl || "/";
|
|
157
164
|
else if (r?.sourceAppPid) {
|
|
158
|
-
const u = await P(), a = k(u),
|
|
159
|
-
a &&
|
|
165
|
+
const u = await P(), a = k(u), f = F(u);
|
|
166
|
+
a && f?.appPid && r?.sourceAppPid === f?.appPid && (o.baseUrl = f.appUrl);
|
|
160
167
|
}
|
|
161
168
|
const c = window?.blocklet?.componentId;
|
|
162
169
|
try {
|
|
163
|
-
const u = await y({ provider:
|
|
164
|
-
if (o.baseUrl = n, await
|
|
170
|
+
const u = await y({ provider: t });
|
|
171
|
+
if (o.baseUrl = n, await ie(100), u) {
|
|
165
172
|
const a = {
|
|
166
173
|
...r,
|
|
167
|
-
action:
|
|
174
|
+
action: e,
|
|
168
175
|
locale: p,
|
|
169
176
|
code: u,
|
|
170
|
-
provider:
|
|
177
|
+
provider: t,
|
|
171
178
|
componentId: c
|
|
172
179
|
};
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
return L.provider =
|
|
180
|
+
Y(a.inviter) && window.localStorage.getItem("inviter") && (a.inviter = window.localStorage.getItem("inviter"));
|
|
181
|
+
const f = ["connect-to-did-space", "connect-to-did-domain"].includes(a.action) ? "login" : a.action, { data: H } = await g.current.post("/login", { ...a, action: f }), L = se(H);
|
|
182
|
+
return L.provider = t, L;
|
|
176
183
|
}
|
|
177
184
|
return o.baseUrl = n, null;
|
|
178
185
|
} catch (u) {
|
|
179
|
-
const a = O(u, s("loginOAuthFailed", { provider: A[
|
|
186
|
+
const a = O(u, s("loginOAuthFailed", { provider: A[t] }));
|
|
180
187
|
throw o.baseUrl = n, new Error(a);
|
|
181
188
|
}
|
|
182
|
-
}),
|
|
189
|
+
}), G = d(() => {
|
|
183
190
|
});
|
|
184
|
-
return /* @__PURE__ */
|
|
185
|
-
|
|
191
|
+
return /* @__PURE__ */ K(
|
|
192
|
+
de,
|
|
186
193
|
{
|
|
187
194
|
value: {
|
|
188
195
|
locale: p,
|
|
189
196
|
getOAuthConfigs: U,
|
|
190
|
-
getOAuthConfigList:
|
|
191
|
-
bindOAuth:
|
|
192
|
-
unbindOAuth:
|
|
193
|
-
loginOAuth:
|
|
194
|
-
logoutOAuth:
|
|
195
|
-
switchOAuthPassport:
|
|
197
|
+
getOAuthConfigList: q,
|
|
198
|
+
bindOAuth: I,
|
|
199
|
+
unbindOAuth: D,
|
|
200
|
+
loginOAuth: X,
|
|
201
|
+
logoutOAuth: G,
|
|
202
|
+
switchOAuthPassport: N,
|
|
196
203
|
baseUrl: o.baseUrl,
|
|
197
|
-
setBaseUrl:
|
|
198
|
-
oauthState:
|
|
204
|
+
setBaseUrl: V,
|
|
205
|
+
oauthState: b,
|
|
199
206
|
unbindAuthLoading: o.unbindAuthLoading,
|
|
200
207
|
bindAuthLoading: o.bindAuthLoading,
|
|
201
208
|
t: s
|
|
202
209
|
},
|
|
203
210
|
children: [
|
|
204
211
|
w,
|
|
205
|
-
/* @__PURE__ */
|
|
206
|
-
|
|
212
|
+
/* @__PURE__ */ W(
|
|
213
|
+
ae,
|
|
207
214
|
{
|
|
208
|
-
api:
|
|
215
|
+
api: g.current,
|
|
209
216
|
locale: p,
|
|
210
217
|
switchState: i,
|
|
211
|
-
onSwitchPassport:
|
|
218
|
+
onSwitchPassport: z,
|
|
219
|
+
session: M
|
|
212
220
|
}
|
|
213
221
|
)
|
|
214
222
|
]
|
|
215
223
|
}
|
|
216
224
|
);
|
|
217
225
|
}
|
|
218
|
-
function
|
|
219
|
-
const w =
|
|
226
|
+
function Se() {
|
|
227
|
+
const w = J(E);
|
|
220
228
|
return R(w, ["locale", "getToken"]);
|
|
221
229
|
}
|
|
222
|
-
|
|
223
|
-
children:
|
|
224
|
-
locale:
|
|
225
|
-
onBindOAuth:
|
|
226
|
-
onUnbindOAuth:
|
|
227
|
-
onSwitchPassport:
|
|
230
|
+
ue.propTypes = {
|
|
231
|
+
children: l.node.isRequired,
|
|
232
|
+
locale: l.string,
|
|
233
|
+
onBindOAuth: l.func,
|
|
234
|
+
onUnbindOAuth: l.func,
|
|
235
|
+
onSwitchPassport: l.func,
|
|
236
|
+
session: l.object
|
|
228
237
|
};
|
|
229
238
|
export {
|
|
230
|
-
|
|
239
|
+
Le as OAuthConsumer,
|
|
231
240
|
E as OAuthContext,
|
|
232
|
-
|
|
233
|
-
|
|
241
|
+
ue as OAuthProvider,
|
|
242
|
+
Se as useOAuth
|
|
234
243
|
};
|
|
@@ -1,114 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import h from "lodash/pick";
|
|
3
|
-
import { Confirm as f } from "@arcblock/ux/lib/Dialog";
|
|
4
|
-
import { Box as c } from "@mui/material";
|
|
5
|
-
import a from "@arcblock/ux/lib/Toast";
|
|
6
|
-
import P from "@arcblock/ux/lib/CardSelector";
|
|
7
|
-
import { translate as w } from "@arcblock/ux/lib/Locale/util";
|
|
8
|
-
import { useMemoizedFn as y, useCreation as S } from "ahooks";
|
|
9
|
-
import { createPassportSvg as g } from "@arcblock/ux/lib/Util/passport";
|
|
10
|
-
import C from "./guest.svg.js";
|
|
11
|
-
const T = (e) => e ? typeof e == "string" ? { sessionToken: e } : h(e, ["sessionToken", "refreshToken", "visitorId", "destroySessionId"]) : {}, k = {
|
|
12
|
-
zh: {
|
|
13
|
-
switchPassport: "切换通行证",
|
|
14
|
-
switchPassportFailed: "切换通行证失败",
|
|
15
|
-
switchPassportSucceed: "切换通行证成功",
|
|
16
|
-
selectedPassport: "请选择一个通行证",
|
|
17
|
-
switch: "切换",
|
|
18
|
-
cancel: "取消",
|
|
19
|
-
currentRole: "当前角色:",
|
|
20
|
-
passport: "通行证",
|
|
21
|
-
getPassportFailed: "获取通行证失败"
|
|
22
|
-
},
|
|
23
|
-
en: {
|
|
24
|
-
switchPassport: "Switch passport",
|
|
25
|
-
switchPassportFailed: "Switch passport failed",
|
|
26
|
-
switchPassportSucceed: "Switch passport succeed",
|
|
27
|
-
selectedPassport: "Select a passport to switch",
|
|
28
|
-
switch: "Switch",
|
|
29
|
-
cancel: "Cancel",
|
|
30
|
-
currentRole: "Current role: ",
|
|
31
|
-
passport: "Passport",
|
|
32
|
-
getPassportFailed: "Get passports failed"
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
function G({ api: e, locale: l, switchState: r, onSwitchPassport: d }) {
|
|
36
|
-
const t = y((s, o = {}) => w(k, s, l, "en", o)), i = S(() => r.passports.filter((s) => s.role !== r.currentUser?.role), [r.passports, r.currentUser?.role]), m = async () => {
|
|
37
|
-
try {
|
|
38
|
-
const { data: s } = await e.post("/switch", { passportId: r.selectedPassport }), { sessionToken: o, refreshToken: u } = T(s);
|
|
39
|
-
d({ sessionToken: o, refreshToken: u }), a.success(t("switchPassportSucceed"));
|
|
40
|
-
} catch (s) {
|
|
41
|
-
a.error(s.message || t("switchPassportFailed"));
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
return /* @__PURE__ */ p(
|
|
45
|
-
f,
|
|
46
|
-
{
|
|
47
|
-
open: r.open,
|
|
48
|
-
title: t("switchPassport"),
|
|
49
|
-
onConfirm: m,
|
|
50
|
-
onCancel: r.reset,
|
|
51
|
-
confirmButton: {
|
|
52
|
-
text: t("switch"),
|
|
53
|
-
props: {
|
|
54
|
-
variant: "contained",
|
|
55
|
-
color: "primary"
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
cancelButton: {
|
|
59
|
-
text: t("cancel"),
|
|
60
|
-
props: {
|
|
61
|
-
color: "inherit"
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
PaperProps: { style: { width: 600 } },
|
|
65
|
-
children: [
|
|
66
|
-
/* @__PURE__ */ p(
|
|
67
|
-
c,
|
|
68
|
-
{
|
|
69
|
-
sx: {
|
|
70
|
-
mb: 2
|
|
71
|
-
},
|
|
72
|
-
children: [
|
|
73
|
-
t("currentRole"),
|
|
74
|
-
r.currentUser?.role
|
|
75
|
-
]
|
|
76
|
-
}
|
|
77
|
-
),
|
|
78
|
-
/* @__PURE__ */ n(
|
|
79
|
-
P,
|
|
80
|
-
{
|
|
81
|
-
width: 160,
|
|
82
|
-
height: 240,
|
|
83
|
-
cardSpace: 24,
|
|
84
|
-
list: [
|
|
85
|
-
// eslint-disable-next-line react/no-unstable-nested-components
|
|
86
|
-
() => /* @__PURE__ */ n(C, {}),
|
|
87
|
-
...i.map((s) => s.display ? {
|
|
88
|
-
src: s.display,
|
|
89
|
-
name: s.title
|
|
90
|
-
} : () => /* @__PURE__ */ n(
|
|
91
|
-
c,
|
|
92
|
-
{
|
|
93
|
-
sx: { width: "100%" },
|
|
94
|
-
dangerouslySetInnerHTML: {
|
|
95
|
-
__html: g(s)
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
s.id
|
|
99
|
-
))
|
|
100
|
-
],
|
|
101
|
-
onSelect: (s) => {
|
|
102
|
-
r.selectedPassport = s > 0 ? i[s - 1].id : void 0;
|
|
103
|
-
},
|
|
104
|
-
defaultIndex: 0
|
|
105
|
-
}
|
|
106
|
-
)
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
);
|
|
110
|
-
}
|
|
1
|
+
import { PassportSwitcher as s, parseResponse as o } from "../components/PassportSwitcher.js";
|
|
111
2
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
3
|
+
s as PassportSwitcher,
|
|
4
|
+
o as parseResponse
|
|
114
5
|
};
|
package/lib/Passkey/context.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { createContext as
|
|
5
|
-
import
|
|
6
|
-
import { useReactive as g, useMemoizedFn as i, useCreation as
|
|
1
|
+
import { jsxs as V, jsx as O } from "react/jsx-runtime";
|
|
2
|
+
import p from "prop-types";
|
|
3
|
+
import z from "lodash/isUndefined";
|
|
4
|
+
import { createContext as J, use as K } from "react";
|
|
5
|
+
import u from "@arcblock/ux/lib/Toast";
|
|
6
|
+
import { useReactive as g, useMemoizedFn as i, useCreation as W } from "ahooks";
|
|
7
7
|
import w from "lodash/noop";
|
|
8
8
|
import { joinURL as S } from "ufo";
|
|
9
|
-
import { translate as
|
|
10
|
-
import { BLOCKLET_SERVICE_PATH_PREFIX as
|
|
11
|
-
import { getBlockletData as
|
|
12
|
-
import { startRegistration as
|
|
13
|
-
import { createAxios as
|
|
14
|
-
import { parseResponse as
|
|
15
|
-
const F =
|
|
9
|
+
import { translate as q } from "@arcblock/ux/lib/Locale/util";
|
|
10
|
+
import { BLOCKLET_SERVICE_PATH_PREFIX as G } from "@arcblock/ux/lib/Util/constant";
|
|
11
|
+
import { getBlockletData as H, getFederatedEnabled as X, getMaster as Q } from "@arcblock/ux/lib/Util/federated";
|
|
12
|
+
import { startRegistration as Y, startAuthentication as Z } from "@simplewebauthn/browser";
|
|
13
|
+
import { createAxios as $, getWebAuthnErrorMessage as h, logger as U, getApiErrorMessage as A } from "../utils.js";
|
|
14
|
+
import { parseResponse as ee, PassportSwitcher as se } from "../components/PassportSwitcher.js";
|
|
15
|
+
const F = J({}), { Provider: te, Consumer: he } = F, ae = {
|
|
16
16
|
zh: {
|
|
17
17
|
cancel: "取消",
|
|
18
18
|
usePasskey: "使用 Passkey",
|
|
@@ -76,14 +76,15 @@ const F = z({}), { Provider: se, Consumer: we } = F, te = {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
-
function
|
|
79
|
+
function re({
|
|
80
80
|
children: m,
|
|
81
81
|
locale: l = "en",
|
|
82
82
|
onAddPasskey: E = w,
|
|
83
83
|
onRemovePasskey: C = w,
|
|
84
|
-
onSwitchPassport: I = w
|
|
84
|
+
onSwitchPassport: I = w,
|
|
85
|
+
session: R = null
|
|
85
86
|
}) {
|
|
86
|
-
const v = S(window.env?.apiPrefix ||
|
|
87
|
+
const v = S(window.env?.apiPrefix || G, "/api/passkey"), t = g({
|
|
87
88
|
baseUrl: "/",
|
|
88
89
|
session: void 0,
|
|
89
90
|
connecting: !1,
|
|
@@ -116,7 +117,7 @@ function ae({
|
|
|
116
117
|
reset() {
|
|
117
118
|
d.creating = !1, d.verifying = !1, d.creatingStatus = "", d.verifyingStatus = "", d.error = "";
|
|
118
119
|
}
|
|
119
|
-
}), n = i((s, e = {}) =>
|
|
120
|
+
}), n = i((s, e = {}) => q(ae, s, l, "en", e)), c = W(() => $({ baseURL: S(t.baseUrl, v), sessionTokenKey: "__sst", timeout: 60 * 1e3 }), [t.baseUrl, v]), x = i(async () => {
|
|
120
121
|
if (t.baseUrl === "/")
|
|
121
122
|
return window.blocklet;
|
|
122
123
|
try {
|
|
@@ -124,16 +125,16 @@ function ae({
|
|
|
124
125
|
return window.blocklet;
|
|
125
126
|
} catch {
|
|
126
127
|
}
|
|
127
|
-
return await
|
|
128
|
-
}), P = window?.blocklet?.componentId,
|
|
128
|
+
return await H(t.baseUrl);
|
|
129
|
+
}), P = window?.blocklet?.componentId, B = (s) => {
|
|
129
130
|
t.baseUrl = s || "/";
|
|
130
|
-
},
|
|
131
|
+
}, T = (s) => {
|
|
131
132
|
t.targetAppPid = s;
|
|
132
133
|
}, b = i(async (s) => {
|
|
133
134
|
const { data: e } = await c.get("/register", { params: s });
|
|
134
135
|
console.warn("passkey.create.options", e);
|
|
135
136
|
try {
|
|
136
|
-
const a = await
|
|
137
|
+
const a = await Y({ optionsJSON: e, useAutoRegister: !1 });
|
|
137
138
|
console.warn("passkey.create.response", a);
|
|
138
139
|
const { data: r } = await c.post("/register", a, { params: { challenge: e.challenge } });
|
|
139
140
|
if (console.warn("passkey.create.result", r), !r.verified)
|
|
@@ -146,7 +147,7 @@ function ae({
|
|
|
146
147
|
const { data: e } = await c.get("/auth", { params: s });
|
|
147
148
|
console.warn("passkey.auth.options", e);
|
|
148
149
|
try {
|
|
149
|
-
const a = await
|
|
150
|
+
const a = await Z({ optionsJSON: e });
|
|
150
151
|
console.warn("passkey.auth.response", a);
|
|
151
152
|
const { data: r } = await c.post("/auth", a, {
|
|
152
153
|
params: { challenge: e.challenge, targetAppPid: t.targetAppPid }
|
|
@@ -157,7 +158,7 @@ function ae({
|
|
|
157
158
|
} catch (a) {
|
|
158
159
|
throw a.name ? new Error(h(a, n("verifyPasskeyFailed"), n)) : a;
|
|
159
160
|
}
|
|
160
|
-
}),
|
|
161
|
+
}), M = async (s) => {
|
|
161
162
|
t.connecting = !0;
|
|
162
163
|
try {
|
|
163
164
|
const e = await b({
|
|
@@ -165,13 +166,13 @@ function ae({
|
|
|
165
166
|
locale: l,
|
|
166
167
|
componentId: P
|
|
167
168
|
});
|
|
168
|
-
return
|
|
169
|
+
return u.success(n("connectPasskeySucceed")), E(e), e;
|
|
169
170
|
} catch (e) {
|
|
170
|
-
U.error("Failed to connect passkey", e),
|
|
171
|
+
U.error("Failed to connect passkey", e), u.error(A(e, n("connectPasskeyFailed")));
|
|
171
172
|
} finally {
|
|
172
173
|
t.connecting = !1;
|
|
173
174
|
}
|
|
174
|
-
},
|
|
175
|
+
}, D = async ({ session: s, connectedAccount: e }) => {
|
|
175
176
|
t.session = s, t.disconnecting = !0;
|
|
176
177
|
try {
|
|
177
178
|
const a = await k({
|
|
@@ -181,27 +182,27 @@ function ae({
|
|
|
181
182
|
sourceAppPid: s?.user?.sourceAppPid,
|
|
182
183
|
credentialId: e.id
|
|
183
184
|
});
|
|
184
|
-
|
|
185
|
+
u.success(n("disconnectPasskeySucceed")), C(a);
|
|
185
186
|
} catch (a) {
|
|
186
|
-
U.error("Failed to disconnect passkey", a),
|
|
187
|
+
U.error("Failed to disconnect passkey", a), u.error(A(a, n("disconnectPasskeyFailed")));
|
|
187
188
|
} finally {
|
|
188
189
|
t.disconnecting = !1;
|
|
189
190
|
}
|
|
190
|
-
},
|
|
191
|
+
}, N = async (s = {}) => {
|
|
191
192
|
try {
|
|
192
193
|
const { data: e } = await c.get("/passports");
|
|
193
|
-
e.length ? (o.open = !0, o.currentUser = s, o.passports = e || []) :
|
|
194
|
+
e.length ? (o.open = !0, o.currentUser = s, o.passports = e || []) : u.error(n("noPassports"));
|
|
194
195
|
} catch (e) {
|
|
195
|
-
|
|
196
|
+
u.error(e.message || n("getPassportFailed"));
|
|
196
197
|
}
|
|
197
|
-
},
|
|
198
|
+
}, j = i((...s) => {
|
|
198
199
|
o.reset(), I(...s);
|
|
199
200
|
}), L = i(async ({ action: s = "login", ...e } = {}) => {
|
|
200
201
|
const a = t.baseUrl;
|
|
201
202
|
if (e?.sourceAppPid === window.blocklet?.appPid)
|
|
202
203
|
t.baseUrl = window.blocklet?.appUrl || "/";
|
|
203
204
|
else if (e?.sourceAppPid) {
|
|
204
|
-
const r = await
|
|
205
|
+
const r = await x(), y = X(r), f = Q(r);
|
|
205
206
|
y && f?.appPid && e?.sourceAppPid === f?.appPid && (t.baseUrl = f.appUrl);
|
|
206
207
|
}
|
|
207
208
|
try {
|
|
@@ -211,8 +212,8 @@ function ae({
|
|
|
211
212
|
locale: l,
|
|
212
213
|
componentId: P
|
|
213
214
|
};
|
|
214
|
-
|
|
215
|
-
const y =
|
|
215
|
+
z(r.inviter) && window.localStorage.getItem("inviter") && (r.inviter = window.localStorage.getItem("inviter"));
|
|
216
|
+
const y = ee(await k(r));
|
|
216
217
|
return y.provider = "passkey", y;
|
|
217
218
|
} catch (r) {
|
|
218
219
|
const y = h(r, n("verifyPasskeyFailed"), n);
|
|
@@ -220,22 +221,22 @@ function ae({
|
|
|
220
221
|
}
|
|
221
222
|
}), _ = i(() => {
|
|
222
223
|
});
|
|
223
|
-
return /* @__PURE__ */
|
|
224
|
-
|
|
224
|
+
return /* @__PURE__ */ V(
|
|
225
|
+
te,
|
|
225
226
|
{
|
|
226
227
|
value: {
|
|
227
228
|
api: c,
|
|
228
229
|
locale: l,
|
|
229
|
-
connectPasskey:
|
|
230
|
-
disconnectPasskey:
|
|
230
|
+
connectPasskey: M,
|
|
231
|
+
disconnectPasskey: D,
|
|
231
232
|
createPasskey: b,
|
|
232
233
|
verifyPasskey: k,
|
|
233
234
|
loginPasskey: L,
|
|
234
235
|
logoutPasskey: _,
|
|
235
|
-
switchPassport:
|
|
236
|
+
switchPassport: N,
|
|
236
237
|
baseUrl: t.baseUrl,
|
|
237
|
-
setBaseUrl:
|
|
238
|
-
setTargetAppPid:
|
|
238
|
+
setBaseUrl: B,
|
|
239
|
+
setTargetAppPid: T,
|
|
239
240
|
passkeyState: d,
|
|
240
241
|
disconnecting: t.disconnecting,
|
|
241
242
|
connecting: t.connecting,
|
|
@@ -243,24 +244,34 @@ function ae({
|
|
|
243
244
|
},
|
|
244
245
|
children: [
|
|
245
246
|
m,
|
|
246
|
-
/* @__PURE__ */
|
|
247
|
+
/* @__PURE__ */ O(
|
|
248
|
+
se,
|
|
249
|
+
{
|
|
250
|
+
api: c,
|
|
251
|
+
locale: l,
|
|
252
|
+
switchState: o,
|
|
253
|
+
onSwitchPassport: j,
|
|
254
|
+
session: R
|
|
255
|
+
}
|
|
256
|
+
)
|
|
247
257
|
]
|
|
248
258
|
}
|
|
249
259
|
);
|
|
250
260
|
}
|
|
251
|
-
function
|
|
252
|
-
return
|
|
261
|
+
function me() {
|
|
262
|
+
return K(F);
|
|
253
263
|
}
|
|
254
|
-
|
|
255
|
-
children:
|
|
256
|
-
locale:
|
|
257
|
-
onAddPasskey:
|
|
258
|
-
onRemovePasskey:
|
|
259
|
-
onSwitchPassport:
|
|
264
|
+
re.propTypes = {
|
|
265
|
+
children: p.node.isRequired,
|
|
266
|
+
locale: p.string,
|
|
267
|
+
onAddPasskey: p.func,
|
|
268
|
+
onRemovePasskey: p.func,
|
|
269
|
+
onSwitchPassport: p.func,
|
|
270
|
+
session: p.object
|
|
260
271
|
};
|
|
261
272
|
export {
|
|
262
|
-
|
|
273
|
+
he as PasskeyConsumer,
|
|
263
274
|
F as PasskeyContext,
|
|
264
|
-
|
|
265
|
-
|
|
275
|
+
re as PasskeyProvider,
|
|
276
|
+
me as usePasskey
|
|
266
277
|
};
|