@springmicro/auth 0.7.5 → 0.7.7
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 +60 -60
- package/package.json +2 -2
- package/src/components/forms/AgreementModal.tsx +88 -88
- package/src/components/forms/CaptchaController.tsx +94 -94
- package/src/components/forms/CaptchaModal.jsx +171 -171
- package/src/components/forms/CaptchaWidget.jsx +146 -146
- package/src/components/forms/PasswordChecker.ts +88 -88
- package/src/components/forms/util/auth-api.ts +198 -198
- package/src/components/forms/util/auth-util.tsx +346 -346
- package/src/components/forms/util/core.ts +493 -493
- package/src/components/forms/util/invitation-api.ts +132 -132
- package/src/components/forms/util/provider.tsx +603 -603
- package/src/components/provider/AdfsLoginButton.jsx +38 -38
- package/src/components/provider/AlipayLoginButton.jsx +38 -38
- package/src/components/provider/AppleLoginButton.jsx +38 -38
- package/src/components/provider/AzureADB2CLoginButton.jsx +38 -38
- package/src/components/provider/AzureADLoginButton.jsx +38 -38
- package/src/components/provider/BaiduLoginButton.jsx +38 -38
- package/src/components/provider/BilibiliLoginButton.jsx +37 -37
- package/src/components/provider/CasdoorLoginButton.jsx +38 -38
- package/src/components/provider/DingTalkLoginButton.jsx +37 -37
- package/src/components/provider/DouyinLoginButton.jsx +38 -38
- package/src/components/provider/FacebookLoginButton.jsx +37 -37
- package/src/components/provider/GitHubLoginButton.jsx +37 -37
- package/src/components/provider/GitLabLoginButton.jsx +38 -38
- package/src/components/provider/GiteeLoginButton.jsx +34 -34
- package/src/components/provider/GoogleLoginButton.jsx +68 -68
- package/src/components/provider/InfoflowLoginButton.jsx +38 -38
- package/src/components/provider/LarkLoginButton.jsx +38 -38
- package/src/components/provider/LinkedInLoginButton.jsx +37 -37
- package/src/components/provider/LoginButton.jsx +33 -33
- package/src/components/provider/OktaLoginButton.jsx +38 -38
- package/src/components/provider/Provider.jsx +3 -3
- package/src/components/provider/ProviderButton.jsx +327 -327
- package/src/components/provider/QqLoginButton.jsx +31 -31
- package/src/components/provider/SelfLoginButton.jsx +47 -47
- package/src/components/provider/SlackLoginButton.jsx +38 -38
- package/src/components/provider/SteamLoginButton.jsx +38 -38
- package/src/components/provider/WeComLoginButton.jsx +34 -34
- package/src/components/provider/Web3Auth.jsx +365 -365
- package/src/components/provider/WechatLoginButton.jsx +37 -37
- package/src/components/provider/WeiboLoginButton.jsx +34 -34
- package/src/i18n/en/signup.json +48 -48
- package/src/i18n/index.ts +17 -17
- package/vite.config.ts +33 -33
|
@@ -1,346 +1,346 @@
|
|
|
1
|
-
// https://github.com/casdoor/casdoor/blob/master/web/src/auth/Util.js
|
|
2
|
-
|
|
3
|
-
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
|
4
|
-
//
|
|
5
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
// you may not use this file except in compliance with the License.
|
|
7
|
-
// You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
// See the License for the specific language governing permissions and
|
|
15
|
-
// limitations under the License.
|
|
16
|
-
|
|
17
|
-
import React from "react";
|
|
18
|
-
// import { Alert, Button, Modal, Result } from "antd";
|
|
19
|
-
import { getWechatMessageEvent } from "./auth-api";
|
|
20
|
-
import * as Setting from "./core";
|
|
21
|
-
import * as Provider from "./provider";
|
|
22
|
-
import * as AuthBackend from "./auth-api";
|
|
23
|
-
|
|
24
|
-
export function renderMessage(msg: string | null) {
|
|
25
|
-
if (msg !== null) {
|
|
26
|
-
return (
|
|
27
|
-
<div role="alert" className="alert alert-error">
|
|
28
|
-
<svg
|
|
29
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
30
|
-
className="stroke-current shrink-0 h-6 w-6"
|
|
31
|
-
fill="none"
|
|
32
|
-
viewBox="0 0 24 24"
|
|
33
|
-
>
|
|
34
|
-
<path
|
|
35
|
-
stroke-linecap="round"
|
|
36
|
-
stroke-linejoin="round"
|
|
37
|
-
stroke-width="2"
|
|
38
|
-
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
39
|
-
/>
|
|
40
|
-
</svg>
|
|
41
|
-
<div>
|
|
42
|
-
<h3 className="font-bold">Failed to sign in.</h3>
|
|
43
|
-
<div className="text-xs">{msg}</div>
|
|
44
|
-
</div>
|
|
45
|
-
</div>
|
|
46
|
-
// <div style={{ display: "inline" }}>
|
|
47
|
-
// <Alert
|
|
48
|
-
// message={i18next.t("application:Failed to sign in")}
|
|
49
|
-
// showIcon
|
|
50
|
-
// description={msg}
|
|
51
|
-
// type="error"
|
|
52
|
-
// action={
|
|
53
|
-
// <Button size="small" type="primary" danger>
|
|
54
|
-
// {i18next.t("product:Detail")}
|
|
55
|
-
// </Button>
|
|
56
|
-
// }
|
|
57
|
-
// />
|
|
58
|
-
// </div>
|
|
59
|
-
);
|
|
60
|
-
} else {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function renderMessageLarge(ths: any, msg: string | null) {
|
|
66
|
-
if (msg !== null) {
|
|
67
|
-
return (
|
|
68
|
-
// <Result
|
|
69
|
-
// style={{margin: "0px auto"}}
|
|
70
|
-
// status="error"
|
|
71
|
-
// title={i18next.t("general:There was a problem signing you in..")}
|
|
72
|
-
// subTitle={msg}
|
|
73
|
-
// extra={[
|
|
74
|
-
// <Button type="primary" key="back" onClick={() => {
|
|
75
|
-
// window.history.go(-2);
|
|
76
|
-
// }}>
|
|
77
|
-
// {i18next.t("general:Back")}
|
|
78
|
-
// </Button>,
|
|
79
|
-
// ]}
|
|
80
|
-
// >
|
|
81
|
-
// </Result>
|
|
82
|
-
<div role="alert" className="alert alert-error shadow-lg">
|
|
83
|
-
<svg
|
|
84
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
85
|
-
className="stroke-current shrink-0 h-6 w-6"
|
|
86
|
-
fill="none"
|
|
87
|
-
viewBox="0 0 24 24"
|
|
88
|
-
>
|
|
89
|
-
<path
|
|
90
|
-
stroke-linecap="round"
|
|
91
|
-
stroke-linejoin="round"
|
|
92
|
-
stroke-width="2"
|
|
93
|
-
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
94
|
-
/>
|
|
95
|
-
</svg>
|
|
96
|
-
<div>
|
|
97
|
-
<h3 className="font-bold">There was a problem signing you in.</h3>
|
|
98
|
-
<div className="text-xs">{msg}</div>
|
|
99
|
-
</div>
|
|
100
|
-
<button
|
|
101
|
-
className="btn btn-sm btn-primary"
|
|
102
|
-
onClick={() => window.history.go(-2)}
|
|
103
|
-
>
|
|
104
|
-
Back
|
|
105
|
-
</button>
|
|
106
|
-
</div>
|
|
107
|
-
);
|
|
108
|
-
} else {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function getRefinedValue(value?: string | null) {
|
|
114
|
-
return value ?? "";
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function getCasParameters(params?: URLSearchParams) {
|
|
118
|
-
const queries =
|
|
119
|
-
params !== undefined ? params : new URLSearchParams(window.location.search);
|
|
120
|
-
const service = getRefinedValue(queries.get("service"));
|
|
121
|
-
const renew = getRefinedValue(queries.get("renew"));
|
|
122
|
-
const gateway = getRefinedValue(queries.get("gateway"));
|
|
123
|
-
return {
|
|
124
|
-
service: service,
|
|
125
|
-
renew: renew,
|
|
126
|
-
gateway: gateway,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function getRawGetParameter(key: string) {
|
|
131
|
-
const fullUrl = window.location.href;
|
|
132
|
-
const token = fullUrl.split(`${key}=`)[1];
|
|
133
|
-
if (!token) {
|
|
134
|
-
return "";
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let res = token.split("&")[0];
|
|
138
|
-
if (!res) {
|
|
139
|
-
return "";
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
res = decodeURIComponent(res);
|
|
143
|
-
return res;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function getCasLoginParameters(owner: string, name: string) {
|
|
147
|
-
const queries = new URLSearchParams(window.location.search);
|
|
148
|
-
// CAS service
|
|
149
|
-
let service = getRawGetParameter("service");
|
|
150
|
-
if (service === "") {
|
|
151
|
-
service = getRefinedValue(queries.get("service"));
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
id: `${owner}/${encodeURIComponent(name)}`, // application ID,
|
|
155
|
-
service: service,
|
|
156
|
-
type: "cas",
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function getOAuthGetParameters(params?: URLSearchParams) {
|
|
161
|
-
const queries =
|
|
162
|
-
params !== undefined ? params : new URLSearchParams(window.location.search);
|
|
163
|
-
const clientId = getRefinedValue(queries.get("client_id"));
|
|
164
|
-
const responseType = getRefinedValue(queries.get("response_type"));
|
|
165
|
-
|
|
166
|
-
let redirectUri = getRawGetParameter("redirect_uri");
|
|
167
|
-
if (redirectUri === "") {
|
|
168
|
-
redirectUri = getRefinedValue(queries.get("redirect_uri"));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
let scope = getRefinedValue(queries.get("scope"));
|
|
172
|
-
if (redirectUri.includes("#") && scope === "") {
|
|
173
|
-
scope = getRawGetParameter("scope");
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let state = getRefinedValue(queries.get("state"));
|
|
177
|
-
if (state.startsWith("/auth/oauth2/login.php?wantsurl=")) {
|
|
178
|
-
// state contains URL param encoding for Moodle, URLSearchParams automatically decoded it, so here encode it again
|
|
179
|
-
state = encodeURIComponent(state);
|
|
180
|
-
}
|
|
181
|
-
if (redirectUri.includes("#") && state === "") {
|
|
182
|
-
state = getRawGetParameter("state");
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const nonce = getRefinedValue(queries.get("nonce"));
|
|
186
|
-
const challengeMethod = getRefinedValue(queries.get("code_challenge_method"));
|
|
187
|
-
const codeChallenge = getRefinedValue(queries.get("code_challenge"));
|
|
188
|
-
const samlRequest = getRefinedValue(queries.get("SAMLRequest"));
|
|
189
|
-
const relayState = getRefinedValue(queries.get("RelayState"));
|
|
190
|
-
const noRedirect = getRefinedValue(queries.get("noRedirect"));
|
|
191
|
-
|
|
192
|
-
if (clientId === "" && samlRequest === "") {
|
|
193
|
-
// login
|
|
194
|
-
return null;
|
|
195
|
-
} else {
|
|
196
|
-
// code
|
|
197
|
-
return {
|
|
198
|
-
clientId: clientId,
|
|
199
|
-
responseType: responseType,
|
|
200
|
-
redirectUri: redirectUri,
|
|
201
|
-
scope: scope,
|
|
202
|
-
state: state,
|
|
203
|
-
nonce: nonce,
|
|
204
|
-
challengeMethod: challengeMethod,
|
|
205
|
-
codeChallenge: codeChallenge,
|
|
206
|
-
samlRequest: samlRequest,
|
|
207
|
-
relayState: relayState,
|
|
208
|
-
noRedirect: noRedirect,
|
|
209
|
-
type: "code",
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function getStateFromQueryParams(
|
|
215
|
-
applicationName: string,
|
|
216
|
-
providerName: string,
|
|
217
|
-
method: string,
|
|
218
|
-
isShortState: boolean
|
|
219
|
-
) {
|
|
220
|
-
let query = window.location.search;
|
|
221
|
-
query = `${query}&application=${encodeURIComponent(
|
|
222
|
-
applicationName
|
|
223
|
-
)}&provider=${encodeURIComponent(providerName)}&method=${method}`;
|
|
224
|
-
if (method === "link") {
|
|
225
|
-
query = `${query}&from=${window.location.pathname}`;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (!isShortState) {
|
|
229
|
-
return btoa(query);
|
|
230
|
-
} else {
|
|
231
|
-
const state = providerName;
|
|
232
|
-
sessionStorage.setItem(state, query);
|
|
233
|
-
return state;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function getQueryParamsFromState(state: string) {
|
|
238
|
-
const query = sessionStorage.getItem(state);
|
|
239
|
-
if (query === null) {
|
|
240
|
-
return atob(state);
|
|
241
|
-
} else {
|
|
242
|
-
return query;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export function getEvent(
|
|
247
|
-
application: Provider.Application | null,
|
|
248
|
-
provider: Provider.Provider | null,
|
|
249
|
-
ticket: string,
|
|
250
|
-
method: string
|
|
251
|
-
) {
|
|
252
|
-
getWechatMessageEvent(ticket).then((res) => {
|
|
253
|
-
if (res.data === "SCAN" || res.data === "subscribe") {
|
|
254
|
-
const code = res?.data2;
|
|
255
|
-
Setting.goToLink(
|
|
256
|
-
Provider.getAuthUrl(application, provider, method ?? "signup", code)
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export async function WechatOfficialAccountModal(
|
|
263
|
-
application: Provider.Application,
|
|
264
|
-
provider: Provider.Provider,
|
|
265
|
-
method: string
|
|
266
|
-
) {
|
|
267
|
-
// Add an event listener to close the dialog when the user clicks outside of it
|
|
268
|
-
document.addEventListener("click", function (event) {
|
|
269
|
-
const dialog = document.getElementById("WechatOfficialAccountModal");
|
|
270
|
-
if (dialog && event.target === dialog) {
|
|
271
|
-
// @ts-ignore
|
|
272
|
-
dialog!.close();
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
// Function to create and display the dialog
|
|
277
|
-
function showDialog(res: any, t1: any) {
|
|
278
|
-
// Define a function to open the dialog
|
|
279
|
-
function openDialog() {
|
|
280
|
-
const dialog = document.getElementById("WechatOfficialAccountModal");
|
|
281
|
-
if (dialog) {
|
|
282
|
-
//@ts-ignore
|
|
283
|
-
dialog!.showModal();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Define a function to close the dialog
|
|
288
|
-
function closeDialog() {
|
|
289
|
-
window.clearInterval(t1);
|
|
290
|
-
const dialog = document.getElementById("WechatOfficialAccountModal");
|
|
291
|
-
if (dialog) {
|
|
292
|
-
//@ts-ignore
|
|
293
|
-
dialog!.close();
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
// @ts-ignore
|
|
297
|
-
window.closeDialog = closeDialog;
|
|
298
|
-
const dialogContent = `
|
|
299
|
-
<div style="margin-right: 34px;">
|
|
300
|
-
<img src="data:image/png;base64,${res.data}" alt="Wechat QR code" style="width: 100%;" />
|
|
301
|
-
</div>
|
|
302
|
-
<button onclick="window.closeDialog()">Close</button>
|
|
303
|
-
`;
|
|
304
|
-
|
|
305
|
-
const dialog = document.createElement("dialog");
|
|
306
|
-
dialog.innerHTML = dialogContent;
|
|
307
|
-
dialog.id = "WechatOfficialAccountModal";
|
|
308
|
-
|
|
309
|
-
// Append the dialog to the document body
|
|
310
|
-
document.body.appendChild(dialog);
|
|
311
|
-
|
|
312
|
-
// Open the dialog
|
|
313
|
-
openDialog();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
AuthBackend.getWechatQRCode(`${provider.owner}/${provider.name}`).then(
|
|
317
|
-
async (res) => {
|
|
318
|
-
if (res.status !== "ok") {
|
|
319
|
-
Setting.showMessage("error", res?.msg);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const t1 = setInterval(
|
|
324
|
-
await getEvent,
|
|
325
|
-
1000,
|
|
326
|
-
application,
|
|
327
|
-
provider,
|
|
328
|
-
res.data2,
|
|
329
|
-
method
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
showDialog(res, t1);
|
|
333
|
-
// {Modal.info({
|
|
334
|
-
// title: i18next.t("provider:Please use WeChat to scan the QR code and follow the official account for sign in"),
|
|
335
|
-
// content: (
|
|
336
|
-
// <div style={{marginRight: "34px"}}>
|
|
337
|
-
// <img src = {"data:image/png;base64," + res.data} alt="Wechat QR code" style={{width: "100%"}} />
|
|
338
|
-
// </div>
|
|
339
|
-
// ),
|
|
340
|
-
// onOk() {
|
|
341
|
-
// window.clearInterval(t1);
|
|
342
|
-
// },
|
|
343
|
-
// });}
|
|
344
|
-
}
|
|
345
|
-
);
|
|
346
|
-
}
|
|
1
|
+
// https://github.com/casdoor/casdoor/blob/master/web/src/auth/Util.js
|
|
2
|
+
|
|
3
|
+
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
import React from "react";
|
|
18
|
+
// import { Alert, Button, Modal, Result } from "antd";
|
|
19
|
+
import { getWechatMessageEvent } from "./auth-api";
|
|
20
|
+
import * as Setting from "./core";
|
|
21
|
+
import * as Provider from "./provider";
|
|
22
|
+
import * as AuthBackend from "./auth-api";
|
|
23
|
+
|
|
24
|
+
export function renderMessage(msg: string | null) {
|
|
25
|
+
if (msg !== null) {
|
|
26
|
+
return (
|
|
27
|
+
<div role="alert" className="alert alert-error">
|
|
28
|
+
<svg
|
|
29
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
30
|
+
className="stroke-current shrink-0 h-6 w-6"
|
|
31
|
+
fill="none"
|
|
32
|
+
viewBox="0 0 24 24"
|
|
33
|
+
>
|
|
34
|
+
<path
|
|
35
|
+
stroke-linecap="round"
|
|
36
|
+
stroke-linejoin="round"
|
|
37
|
+
stroke-width="2"
|
|
38
|
+
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
39
|
+
/>
|
|
40
|
+
</svg>
|
|
41
|
+
<div>
|
|
42
|
+
<h3 className="font-bold">Failed to sign in.</h3>
|
|
43
|
+
<div className="text-xs">{msg}</div>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
// <div style={{ display: "inline" }}>
|
|
47
|
+
// <Alert
|
|
48
|
+
// message={i18next.t("application:Failed to sign in")}
|
|
49
|
+
// showIcon
|
|
50
|
+
// description={msg}
|
|
51
|
+
// type="error"
|
|
52
|
+
// action={
|
|
53
|
+
// <Button size="small" type="primary" danger>
|
|
54
|
+
// {i18next.t("product:Detail")}
|
|
55
|
+
// </Button>
|
|
56
|
+
// }
|
|
57
|
+
// />
|
|
58
|
+
// </div>
|
|
59
|
+
);
|
|
60
|
+
} else {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function renderMessageLarge(ths: any, msg: string | null) {
|
|
66
|
+
if (msg !== null) {
|
|
67
|
+
return (
|
|
68
|
+
// <Result
|
|
69
|
+
// style={{margin: "0px auto"}}
|
|
70
|
+
// status="error"
|
|
71
|
+
// title={i18next.t("general:There was a problem signing you in..")}
|
|
72
|
+
// subTitle={msg}
|
|
73
|
+
// extra={[
|
|
74
|
+
// <Button type="primary" key="back" onClick={() => {
|
|
75
|
+
// window.history.go(-2);
|
|
76
|
+
// }}>
|
|
77
|
+
// {i18next.t("general:Back")}
|
|
78
|
+
// </Button>,
|
|
79
|
+
// ]}
|
|
80
|
+
// >
|
|
81
|
+
// </Result>
|
|
82
|
+
<div role="alert" className="alert alert-error shadow-lg">
|
|
83
|
+
<svg
|
|
84
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
85
|
+
className="stroke-current shrink-0 h-6 w-6"
|
|
86
|
+
fill="none"
|
|
87
|
+
viewBox="0 0 24 24"
|
|
88
|
+
>
|
|
89
|
+
<path
|
|
90
|
+
stroke-linecap="round"
|
|
91
|
+
stroke-linejoin="round"
|
|
92
|
+
stroke-width="2"
|
|
93
|
+
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
94
|
+
/>
|
|
95
|
+
</svg>
|
|
96
|
+
<div>
|
|
97
|
+
<h3 className="font-bold">There was a problem signing you in.</h3>
|
|
98
|
+
<div className="text-xs">{msg}</div>
|
|
99
|
+
</div>
|
|
100
|
+
<button
|
|
101
|
+
className="btn btn-sm btn-primary"
|
|
102
|
+
onClick={() => window.history.go(-2)}
|
|
103
|
+
>
|
|
104
|
+
Back
|
|
105
|
+
</button>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
} else {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function getRefinedValue(value?: string | null) {
|
|
114
|
+
return value ?? "";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function getCasParameters(params?: URLSearchParams) {
|
|
118
|
+
const queries =
|
|
119
|
+
params !== undefined ? params : new URLSearchParams(window.location.search);
|
|
120
|
+
const service = getRefinedValue(queries.get("service"));
|
|
121
|
+
const renew = getRefinedValue(queries.get("renew"));
|
|
122
|
+
const gateway = getRefinedValue(queries.get("gateway"));
|
|
123
|
+
return {
|
|
124
|
+
service: service,
|
|
125
|
+
renew: renew,
|
|
126
|
+
gateway: gateway,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getRawGetParameter(key: string) {
|
|
131
|
+
const fullUrl = window.location.href;
|
|
132
|
+
const token = fullUrl.split(`${key}=`)[1];
|
|
133
|
+
if (!token) {
|
|
134
|
+
return "";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let res = token.split("&")[0];
|
|
138
|
+
if (!res) {
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
res = decodeURIComponent(res);
|
|
143
|
+
return res;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function getCasLoginParameters(owner: string, name: string) {
|
|
147
|
+
const queries = new URLSearchParams(window.location.search);
|
|
148
|
+
// CAS service
|
|
149
|
+
let service = getRawGetParameter("service");
|
|
150
|
+
if (service === "") {
|
|
151
|
+
service = getRefinedValue(queries.get("service"));
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
id: `${owner}/${encodeURIComponent(name)}`, // application ID,
|
|
155
|
+
service: service,
|
|
156
|
+
type: "cas",
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function getOAuthGetParameters(params?: URLSearchParams) {
|
|
161
|
+
const queries =
|
|
162
|
+
params !== undefined ? params : new URLSearchParams(window.location.search);
|
|
163
|
+
const clientId = getRefinedValue(queries.get("client_id"));
|
|
164
|
+
const responseType = getRefinedValue(queries.get("response_type"));
|
|
165
|
+
|
|
166
|
+
let redirectUri = getRawGetParameter("redirect_uri");
|
|
167
|
+
if (redirectUri === "") {
|
|
168
|
+
redirectUri = getRefinedValue(queries.get("redirect_uri"));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let scope = getRefinedValue(queries.get("scope"));
|
|
172
|
+
if (redirectUri.includes("#") && scope === "") {
|
|
173
|
+
scope = getRawGetParameter("scope");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let state = getRefinedValue(queries.get("state"));
|
|
177
|
+
if (state.startsWith("/auth/oauth2/login.php?wantsurl=")) {
|
|
178
|
+
// state contains URL param encoding for Moodle, URLSearchParams automatically decoded it, so here encode it again
|
|
179
|
+
state = encodeURIComponent(state);
|
|
180
|
+
}
|
|
181
|
+
if (redirectUri.includes("#") && state === "") {
|
|
182
|
+
state = getRawGetParameter("state");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const nonce = getRefinedValue(queries.get("nonce"));
|
|
186
|
+
const challengeMethod = getRefinedValue(queries.get("code_challenge_method"));
|
|
187
|
+
const codeChallenge = getRefinedValue(queries.get("code_challenge"));
|
|
188
|
+
const samlRequest = getRefinedValue(queries.get("SAMLRequest"));
|
|
189
|
+
const relayState = getRefinedValue(queries.get("RelayState"));
|
|
190
|
+
const noRedirect = getRefinedValue(queries.get("noRedirect"));
|
|
191
|
+
|
|
192
|
+
if (clientId === "" && samlRequest === "") {
|
|
193
|
+
// login
|
|
194
|
+
return null;
|
|
195
|
+
} else {
|
|
196
|
+
// code
|
|
197
|
+
return {
|
|
198
|
+
clientId: clientId,
|
|
199
|
+
responseType: responseType,
|
|
200
|
+
redirectUri: redirectUri,
|
|
201
|
+
scope: scope,
|
|
202
|
+
state: state,
|
|
203
|
+
nonce: nonce,
|
|
204
|
+
challengeMethod: challengeMethod,
|
|
205
|
+
codeChallenge: codeChallenge,
|
|
206
|
+
samlRequest: samlRequest,
|
|
207
|
+
relayState: relayState,
|
|
208
|
+
noRedirect: noRedirect,
|
|
209
|
+
type: "code",
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function getStateFromQueryParams(
|
|
215
|
+
applicationName: string,
|
|
216
|
+
providerName: string,
|
|
217
|
+
method: string,
|
|
218
|
+
isShortState: boolean
|
|
219
|
+
) {
|
|
220
|
+
let query = window.location.search;
|
|
221
|
+
query = `${query}&application=${encodeURIComponent(
|
|
222
|
+
applicationName
|
|
223
|
+
)}&provider=${encodeURIComponent(providerName)}&method=${method}`;
|
|
224
|
+
if (method === "link") {
|
|
225
|
+
query = `${query}&from=${window.location.pathname}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!isShortState) {
|
|
229
|
+
return btoa(query);
|
|
230
|
+
} else {
|
|
231
|
+
const state = providerName;
|
|
232
|
+
sessionStorage.setItem(state, query);
|
|
233
|
+
return state;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function getQueryParamsFromState(state: string) {
|
|
238
|
+
const query = sessionStorage.getItem(state);
|
|
239
|
+
if (query === null) {
|
|
240
|
+
return atob(state);
|
|
241
|
+
} else {
|
|
242
|
+
return query;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function getEvent(
|
|
247
|
+
application: Provider.Application | null,
|
|
248
|
+
provider: Provider.Provider | null,
|
|
249
|
+
ticket: string,
|
|
250
|
+
method: string
|
|
251
|
+
) {
|
|
252
|
+
getWechatMessageEvent(ticket).then((res) => {
|
|
253
|
+
if (res.data === "SCAN" || res.data === "subscribe") {
|
|
254
|
+
const code = res?.data2;
|
|
255
|
+
Setting.goToLink(
|
|
256
|
+
Provider.getAuthUrl(application, provider, method ?? "signup", code)
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export async function WechatOfficialAccountModal(
|
|
263
|
+
application: Provider.Application,
|
|
264
|
+
provider: Provider.Provider,
|
|
265
|
+
method: string
|
|
266
|
+
) {
|
|
267
|
+
// Add an event listener to close the dialog when the user clicks outside of it
|
|
268
|
+
document.addEventListener("click", function (event) {
|
|
269
|
+
const dialog = document.getElementById("WechatOfficialAccountModal");
|
|
270
|
+
if (dialog && event.target === dialog) {
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
dialog!.close();
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Function to create and display the dialog
|
|
277
|
+
function showDialog(res: any, t1: any) {
|
|
278
|
+
// Define a function to open the dialog
|
|
279
|
+
function openDialog() {
|
|
280
|
+
const dialog = document.getElementById("WechatOfficialAccountModal");
|
|
281
|
+
if (dialog) {
|
|
282
|
+
//@ts-ignore
|
|
283
|
+
dialog!.showModal();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Define a function to close the dialog
|
|
288
|
+
function closeDialog() {
|
|
289
|
+
window.clearInterval(t1);
|
|
290
|
+
const dialog = document.getElementById("WechatOfficialAccountModal");
|
|
291
|
+
if (dialog) {
|
|
292
|
+
//@ts-ignore
|
|
293
|
+
dialog!.close();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// @ts-ignore
|
|
297
|
+
window.closeDialog = closeDialog;
|
|
298
|
+
const dialogContent = `
|
|
299
|
+
<div style="margin-right: 34px;">
|
|
300
|
+
<img src="data:image/png;base64,${res.data}" alt="Wechat QR code" style="width: 100%;" />
|
|
301
|
+
</div>
|
|
302
|
+
<button onclick="window.closeDialog()">Close</button>
|
|
303
|
+
`;
|
|
304
|
+
|
|
305
|
+
const dialog = document.createElement("dialog");
|
|
306
|
+
dialog.innerHTML = dialogContent;
|
|
307
|
+
dialog.id = "WechatOfficialAccountModal";
|
|
308
|
+
|
|
309
|
+
// Append the dialog to the document body
|
|
310
|
+
document.body.appendChild(dialog);
|
|
311
|
+
|
|
312
|
+
// Open the dialog
|
|
313
|
+
openDialog();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
AuthBackend.getWechatQRCode(`${provider.owner}/${provider.name}`).then(
|
|
317
|
+
async (res) => {
|
|
318
|
+
if (res.status !== "ok") {
|
|
319
|
+
Setting.showMessage("error", res?.msg);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const t1 = setInterval(
|
|
324
|
+
await getEvent,
|
|
325
|
+
1000,
|
|
326
|
+
application,
|
|
327
|
+
provider,
|
|
328
|
+
res.data2,
|
|
329
|
+
method
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
showDialog(res, t1);
|
|
333
|
+
// {Modal.info({
|
|
334
|
+
// title: i18next.t("provider:Please use WeChat to scan the QR code and follow the official account for sign in"),
|
|
335
|
+
// content: (
|
|
336
|
+
// <div style={{marginRight: "34px"}}>
|
|
337
|
+
// <img src = {"data:image/png;base64," + res.data} alt="Wechat QR code" style={{width: "100%"}} />
|
|
338
|
+
// </div>
|
|
339
|
+
// ),
|
|
340
|
+
// onOk() {
|
|
341
|
+
// window.clearInterval(t1);
|
|
342
|
+
// },
|
|
343
|
+
// });}
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
}
|