@springmicro/auth 0.7.0 → 0.7.1

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.
Files changed (144) hide show
  1. package/.eslintrc.cjs +18 -18
  2. package/README.md +60 -60
  3. package/dist/Index-64ac63ff-ChMmeIY7.js +0 -0
  4. package/dist/Index-6c094240-hn_S7Xeg.js +0 -0
  5. package/dist/Web3Auth-CGD96zai.js +0 -0
  6. package/dist/alphawallet-B7eovdf-.js +0 -0
  7. package/dist/apexwallet-ysP20G9D.js +0 -0
  8. package/dist/atoken-BBnNTzcz.js +0 -0
  9. package/dist/bifrostwallet-CNNBO92h.js +0 -0
  10. package/dist/binance-DvPgAzCw.js +0 -0
  11. package/dist/bitget-DZOUrwgy.js +0 -0
  12. package/dist/bitpie-C_uxmEzw.js +0 -0
  13. package/dist/bitski-DpzkHNkv.js +0 -0
  14. package/dist/blockwallet-BL69cqkA.js +0 -0
  15. package/dist/brave-DnRzMQYW.js +0 -0
  16. package/dist/ccip-c78d2f16-DLcRlwod.js +0 -0
  17. package/dist/coin98wallet-CkFdOvXt.js +0 -0
  18. package/dist/coinbase-CaGNx5if.js +0 -0
  19. package/dist/core-9rK8tWud.js +0 -0
  20. package/dist/defiwallet-0AsgJBSy.js +0 -0
  21. package/dist/detected-CX_JZaUk.js +0 -0
  22. package/dist/echooo-CmaetT_Z.js +0 -0
  23. package/dist/enkrypt-BibtwvK7.js +0 -0
  24. package/dist/exodus-BxzkDWWP.js +0 -0
  25. package/dist/fordefi-CvKyVwhI.js +0 -0
  26. package/dist/foxwallet-D7c_LDTf.js +0 -0
  27. package/dist/frame-CDfNmjUy.js +0 -0
  28. package/dist/frontier-DqKNSj2z.js +0 -0
  29. package/dist/hashMessage-Bdgmx0rg.js +0 -0
  30. package/dist/huobiwallet-CxSwqa5L.js +0 -0
  31. package/dist/hyperpay-nmHE3WqM.js +0 -0
  32. package/dist/icon-2Zqy7pqQ.js +0 -0
  33. package/dist/icon-CGWI1Ies.js +0 -0
  34. package/dist/icon-C_O4nprO.js +0 -0
  35. package/dist/icon-DbgmZCnU.js +0 -0
  36. package/dist/icon-Dbjb6jc5.js +0 -0
  37. package/dist/icon-cAd7RhSC.js +0 -0
  38. package/dist/imtoken-yENtOTS3.js +0 -0
  39. package/dist/index-021f6a62-Zz543EDB.js +0 -0
  40. package/dist/index-40a497ea-Bn2mC0r7.js +0 -0
  41. package/dist/index-62liFLUM.js +0 -0
  42. package/dist/index-BBx_mvyX.js +0 -0
  43. package/dist/index-C6leUA25.js +0 -0
  44. package/dist/index-CAVvArYp.js +0 -0
  45. package/dist/index-Ct7cFdFm.js +0 -0
  46. package/dist/index-DA32_Pfh.js +0 -0
  47. package/dist/index-Dna0rycp.js +0 -0
  48. package/dist/index.d.ts +0 -0
  49. package/dist/index.js +0 -0
  50. package/dist/index.umd.cjs +0 -0
  51. package/dist/infinitywallet-C8J4FUYw.js +0 -0
  52. package/dist/kayros-AIrUK1za.js +0 -0
  53. package/dist/keplr-CyLTca9B.js +0 -0
  54. package/dist/lif3wallet-C5D6r8pg.js +0 -0
  55. package/dist/liquality-nbCtErVq.js +0 -0
  56. package/dist/mathwallet-CWkivCXo.js +0 -0
  57. package/dist/meetone-kKmvI8md.js +0 -0
  58. package/dist/metamask-BN7yiDV1.js +0 -0
  59. package/dist/mykey-CQZ6UcLH.js +0 -0
  60. package/dist/native-FDN9oNjc.js +0 -0
  61. package/dist/number-C-98SESp.js +0 -0
  62. package/dist/okxwallet-CJLVogh2.js +0 -0
  63. package/dist/oneInch-CciyZ4Pz.js +0 -0
  64. package/dist/onekey-Dal8kYjU.js +0 -0
  65. package/dist/opera-DnKg-TJU.js +0 -0
  66. package/dist/ownbit-BshJUVuW.js +0 -0
  67. package/dist/phantom-CJ8dIcov.js +0 -0
  68. package/dist/rabby-D4thTcd6.js +0 -0
  69. package/dist/rainbow-mXld6yWV.js +0 -0
  70. package/dist/roninwallet-ZyYrd-D1.js +0 -0
  71. package/dist/safeheron-Eg1Jb29V.js +0 -0
  72. package/dist/safepal-DVIKy94N.js +0 -0
  73. package/dist/sequence-BS2IbtDg.js +0 -0
  74. package/dist/stablewallet-jyB079Wb.js +0 -0
  75. package/dist/status-FrAvQjfn.js +0 -0
  76. package/dist/subwallet-DMvFqKyY.js +0 -0
  77. package/dist/talisman-Bp8zUXqB.js +0 -0
  78. package/dist/tallywallet-B4OS9nIr.js +0 -0
  79. package/dist/tokenary-C7jjcbQa.js +0 -0
  80. package/dist/tokenpocket-9ZRPmAFA.js +0 -0
  81. package/dist/tp-V2em5bdl.js +0 -0
  82. package/dist/transactionRequest-be6a8ea9-CUKWo5mx.js +0 -0
  83. package/dist/trust-SgHubMq7.js +0 -0
  84. package/dist/xdefi-COVIyGz4.js +0 -0
  85. package/dist/zeal-DxHbDqm0.js +0 -0
  86. package/dist/zerion-BfW0UElc.js +0 -0
  87. package/dist/zodiacpilot-CrId6F4w.js +0 -0
  88. package/index.html +13 -13
  89. package/package.json +2 -2
  90. package/springmicro-auth-0.6.1.tgz +0 -0
  91. package/src/auth/config.ts +0 -0
  92. package/src/components/SignUp.tsx +0 -0
  93. package/src/components/forms/AgreementModal.tsx +88 -88
  94. package/src/components/forms/CaptchaController.tsx +94 -94
  95. package/src/components/forms/CaptchaModal.jsx +171 -171
  96. package/src/components/forms/CaptchaWidget.jsx +146 -146
  97. package/src/components/forms/PasswordChecker.ts +88 -88
  98. package/src/components/forms/SendCodeInput.tsx +0 -0
  99. package/src/components/forms/SignUpFormItem.tsx +0 -0
  100. package/src/components/forms/util/application-api.ts +0 -0
  101. package/src/components/forms/util/auth-api.ts +198 -198
  102. package/src/components/forms/util/auth-util.tsx +346 -346
  103. package/src/components/forms/util/core.ts +493 -493
  104. package/src/components/forms/util/invitation-api.ts +132 -132
  105. package/src/components/forms/util/provider.tsx +603 -603
  106. package/src/components/forms/util/user-api.ts +0 -0
  107. package/src/components/provider/AdfsLoginButton.jsx +38 -38
  108. package/src/components/provider/AlipayLoginButton.jsx +38 -38
  109. package/src/components/provider/AppleLoginButton.jsx +38 -38
  110. package/src/components/provider/AzureADB2CLoginButton.jsx +38 -38
  111. package/src/components/provider/AzureADLoginButton.jsx +38 -38
  112. package/src/components/provider/BaiduLoginButton.jsx +38 -38
  113. package/src/components/provider/BilibiliLoginButton.jsx +37 -37
  114. package/src/components/provider/CasdoorLoginButton.jsx +38 -38
  115. package/src/components/provider/DingTalkLoginButton.jsx +37 -37
  116. package/src/components/provider/DouyinLoginButton.jsx +38 -38
  117. package/src/components/provider/FacebookLoginButton.jsx +37 -37
  118. package/src/components/provider/GitHubLoginButton.jsx +37 -37
  119. package/src/components/provider/GitLabLoginButton.jsx +38 -38
  120. package/src/components/provider/GiteeLoginButton.jsx +34 -34
  121. package/src/components/provider/GoogleLoginButton.jsx +68 -68
  122. package/src/components/provider/InfoflowLoginButton.jsx +38 -38
  123. package/src/components/provider/LarkLoginButton.jsx +38 -38
  124. package/src/components/provider/LinkedInLoginButton.jsx +37 -37
  125. package/src/components/provider/LoginButton.jsx +33 -33
  126. package/src/components/provider/OktaLoginButton.jsx +38 -38
  127. package/src/components/provider/Provider.jsx +3 -3
  128. package/src/components/provider/ProviderButton.jsx +327 -327
  129. package/src/components/provider/QqLoginButton.jsx +31 -31
  130. package/src/components/provider/SelfLoginButton.jsx +47 -47
  131. package/src/components/provider/SlackLoginButton.jsx +38 -38
  132. package/src/components/provider/SteamLoginButton.jsx +38 -38
  133. package/src/components/provider/WeComLoginButton.jsx +34 -34
  134. package/src/components/provider/Web3Auth.jsx +365 -365
  135. package/src/components/provider/WechatLoginButton.jsx +37 -37
  136. package/src/components/provider/WeiboLoginButton.jsx +34 -34
  137. package/src/components/util.tsx +0 -0
  138. package/src/i18n/en/signup.json +48 -48
  139. package/src/i18n/index.ts +17 -17
  140. package/src/index.tsx +0 -0
  141. package/src/vite-env.d.ts +1 -1
  142. package/tsconfig.json +23 -23
  143. package/tsconfig.node.json +10 -10
  144. package/vite.config.ts +33 -33
@@ -1,493 +1,493 @@
1
- import type { Application, Provider } from "./provider";
2
- import * as phoneNumber from "libphonenumber-js";
3
-
4
- export const StaticBaseUrl = "https://cdn.casbin.org";
5
- export const ROOT_URLS: { casdoor: string; springmicro: string | undefined } = {
6
- casdoor: "https://casdoor",
7
- springmicro: undefined,
8
- };
9
-
10
- export function getLanguage() {
11
- return "en";
12
- }
13
-
14
- export function getAcceptLanguage() {
15
- // https://github.com/casdoor/casdoor/blob/739cfd84ed232159226f514c4a0b5168a995eeb0/web/src/Setting.js#L891
16
- return "en;q=0.9,en;q=0.8";
17
- }
18
-
19
- export function deepCopy(obj: any) {
20
- // https://github.com/casdoor/casdoor/blob/739cfd84ed232159226f514c4a0b5168a995eeb0/web/src/Setting.js#L755
21
- return Object.assign({}, obj);
22
- }
23
-
24
- export function showMessage(obj: string, text: string) {
25
- // https://github.com/casdoor/casdoor/blob/739cfd84ed232159226f514c4a0b5168a995eeb0/web/src/Setting.js#L731
26
- // message is the antd toast api
27
- // if (type === "success") {
28
- // message.success(text);
29
- // } else if (type === "error") {
30
- // message.error(text);
31
- // } else if (type === "info") {
32
- // message.info(text);
33
- // }
34
- // temporary workaround
35
- alert(text);
36
- }
37
-
38
- export function goToLink(link?: string) {
39
- if (link === undefined) return;
40
- window.location.href = link;
41
- }
42
-
43
- type ProviderItem = { provider?: Provider | null; prompted: boolean };
44
-
45
- export function isProviderVisible(providerItem: ProviderItem) {
46
- if (providerItem.provider === undefined || providerItem.provider === null) {
47
- return false;
48
- }
49
-
50
- if (!["OAuth", "SAML", "Web3"].includes(providerItem.provider.category)) {
51
- return false;
52
- }
53
-
54
- if (providerItem.provider.type === "WeChatMiniProgram") {
55
- return false;
56
- }
57
-
58
- return true;
59
- }
60
-
61
- export function isProviderPrompted(providerItem: ProviderItem) {
62
- return isProviderVisible(providerItem) && providerItem.prompted;
63
- }
64
-
65
- type SignupItem = {
66
- visible: boolean;
67
- prompted: boolean;
68
- };
69
-
70
- export function isSignupItemPrompted(signupItem: SignupItem) {
71
- return signupItem.visible && signupItem.prompted;
72
- }
73
-
74
- export function getAllPromptedProviderItems(application: Application) {
75
- return application.providers?.filter((providerItem) =>
76
- isProviderPrompted(providerItem)
77
- );
78
- }
79
-
80
- export function getAllPromptedSignupItems(application: Application) {
81
- return application.signupItems?.filter((signupItem) =>
82
- isSignupItemPrompted(signupItem)
83
- );
84
- }
85
-
86
- export function getSignupItem(application: Application, itemName: string) {
87
- const signupItems = application.signupItems?.filter(
88
- (signupItem) => signupItem.name === itemName
89
- );
90
- if (signupItems?.length ?? 0 > 0) {
91
- return signupItems![0];
92
- }
93
- return null;
94
- }
95
-
96
- export function isAffiliationPrompted(application: Application) {
97
- const signupItem = getSignupItem(application, "Affiliation");
98
- if (signupItem === null) {
99
- return false;
100
- }
101
-
102
- return signupItem.prompted;
103
- }
104
-
105
- export function isValidIdCard(idCard: string) {
106
- return idCard !== "";
107
-
108
- // const idCardRegex = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9X]$/;
109
- // return idCardRegex.test(idCard);
110
- }
111
-
112
- export function isValidEmail(email: string) {
113
- // https://github.com/yiminghe/async-validator/blob/057b0b047f88fac65457bae691d6cb7c6fe48ce1/src/rule/type.ts#L9
114
- const emailRegex =
115
- /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
116
- return emailRegex.test(email);
117
- }
118
-
119
- export function isValidPhone(phone: string, countryCode = "") {
120
- if (countryCode !== "" && countryCode !== "CN") {
121
- // @ts-ignore
122
- return phoneNumber.isValidPhoneNumber(phone, countryCode);
123
- }
124
-
125
- // https://learnku.com/articles/31543, `^s*$` filter empty email individually.
126
- const phoneCnRegex =
127
- /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
128
- const phoneRegex = /[0-9]{4,15}$/;
129
-
130
- return countryCode === "CN"
131
- ? phoneCnRegex.test(phone)
132
- : phoneRegex.test(phone);
133
- }
134
-
135
- function isSigninMethodEnabled(
136
- application: Application | null,
137
- signinMethod: string
138
- ) {
139
- if (application && application.signinMethods) {
140
- return (
141
- application.signinMethods.filter((item) => item.name === signinMethod)
142
- .length > 0
143
- );
144
- } else {
145
- return false;
146
- }
147
- }
148
-
149
- export function isPasswordEnabled(application: Application | null) {
150
- return isSigninMethodEnabled(application, "Password");
151
- }
152
-
153
- export function isCodeSigninEnabled(application: Application | null) {
154
- return isSigninMethodEnabled(application, "Verification code");
155
- }
156
-
157
- export function isWebAuthnEnabled(application: Application | null) {
158
- return isSigninMethodEnabled(application, "WebAuthn");
159
- }
160
-
161
- export function isLdapEnabled(application: Application | null) {
162
- return isSigninMethodEnabled(application, "LDAP");
163
- }
164
-
165
- export function isFaceIdEnabled(application: Application | null) {
166
- return isSigninMethodEnabled(application, "Face ID");
167
- }
168
-
169
- export function hasPromptPage(application: Application) {
170
- const providerItems = getAllPromptedProviderItems(application);
171
- if (providerItems?.length ?? 0 > 0) {
172
- return true;
173
- }
174
-
175
- const signupItems = getAllPromptedSignupItems(application);
176
- if (signupItems?.length ?? 0 > 0) {
177
- return true;
178
- }
179
-
180
- return isAffiliationPrompted(application);
181
- }
182
-
183
- export function getProviderLogoURL(provider: Provider) {
184
- if (provider.type === "Custom" && provider.customLogo) {
185
- return provider.customLogo;
186
- }
187
- if (provider.category === "OAuth") {
188
- return `${StaticBaseUrl}/img/social_${provider.type.toLowerCase()}.png`;
189
- } else {
190
- const info: { logo: string; url: string } =
191
- OtherProviderInfo[provider.category as OPIKey][
192
- provider.type as OPITypeKey
193
- ];
194
- // avoid crash when provider is not found
195
- if (info) {
196
- return info.logo;
197
- }
198
- return "";
199
- }
200
- }
201
-
202
- export type OPIKey = keyof typeof OtherProviderInfo;
203
-
204
- export type OPITypeKey = keyof (typeof OtherProviderInfo)[OPIKey];
205
-
206
- export const OtherProviderInfo = {
207
- SMS: {
208
- "Aliyun SMS": {
209
- logo: `${StaticBaseUrl}/img/social_aliyun.png`,
210
- url: "https://aliyun.com/product/sms",
211
- },
212
- "Amazon SNS": {
213
- logo: `${StaticBaseUrl}/img/social_aws.png`,
214
- url: "https://aws.amazon.com/cn/sns/",
215
- },
216
- "Azure ACS": {
217
- logo: `${StaticBaseUrl}/img/social_azure.png`,
218
- url: "https://azure.microsoft.com/en-us/products/communication-services",
219
- },
220
- "Infobip SMS": {
221
- logo: `${StaticBaseUrl}/img/social_infobip.png`,
222
- url: "https://portal.infobip.com/homepage/",
223
- },
224
- "Tencent Cloud SMS": {
225
- logo: `${StaticBaseUrl}/img/social_tencent_cloud.jpg`,
226
- url: "https://cloud.tencent.com/product/sms",
227
- },
228
- "Baidu Cloud SMS": {
229
- logo: `${StaticBaseUrl}/img/social_baidu_cloud.png`,
230
- url: "https://cloud.baidu.com/product/sms.html",
231
- },
232
- "Volc Engine SMS": {
233
- logo: `${StaticBaseUrl}/img/social_volc_engine.jpg`,
234
- url: "https://www.volcengine.com/products/cloud-sms",
235
- },
236
- "Huawei Cloud SMS": {
237
- logo: `${StaticBaseUrl}/img/social_huawei.png`,
238
- url: "https://www.huaweicloud.com/product/msgsms.html",
239
- },
240
- "UCloud SMS": {
241
- logo: `${StaticBaseUrl}/img/social_ucloud.png`,
242
- url: "https://www.ucloud.cn/site/product/usms.html",
243
- },
244
- "Twilio SMS": {
245
- logo: `${StaticBaseUrl}/img/social_twilio.svg`,
246
- url: "https://www.twilio.com/messaging",
247
- },
248
- "SmsBao SMS": {
249
- logo: `${StaticBaseUrl}/img/social_smsbao.png`,
250
- url: "https://www.smsbao.com/",
251
- },
252
- "SUBMAIL SMS": {
253
- logo: `${StaticBaseUrl}/img/social_submail.svg`,
254
- url: "https://www.mysubmail.com",
255
- },
256
- "Msg91 SMS": {
257
- logo: `${StaticBaseUrl}/img/social_msg91.ico`,
258
- url: "https://control.msg91.com/app/",
259
- },
260
- "OSON SMS": {
261
- logo: "https://osonsms.com/images/osonsms-logo.svg",
262
- url: "https://osonsms.com/",
263
- },
264
- "Custom HTTP SMS": {
265
- logo: `${StaticBaseUrl}/img/social_default.png`,
266
- url: "https://casdoor.org/docs/provider/sms/overview",
267
- },
268
- "Mock SMS": {
269
- logo: `${StaticBaseUrl}/img/social_default.png`,
270
- url: "",
271
- },
272
- },
273
- Email: {
274
- Default: {
275
- logo: `${StaticBaseUrl}/img/email_default.png`,
276
- url: "",
277
- },
278
- SUBMAIL: {
279
- logo: `${StaticBaseUrl}/img/social_submail.svg`,
280
- url: "https://www.mysubmail.com",
281
- },
282
- Mailtrap: {
283
- logo: `${StaticBaseUrl}/img/email_mailtrap.png`,
284
- url: "https://mailtrap.io",
285
- },
286
- "Azure ACS": {
287
- logo: `${StaticBaseUrl}/img/social_azure.png`,
288
- url: "https://learn.microsoft.com/zh-cn/azure/communication-services",
289
- },
290
- SendGrid: {
291
- logo: `${StaticBaseUrl}/img/email_sendgrid.png`,
292
- url: "https://sendgrid.com/",
293
- },
294
- "Custom HTTP Email": {
295
- logo: `${StaticBaseUrl}/img/social_default.png`,
296
- url: "https://casdoor.org/docs/provider/email/overview",
297
- },
298
- },
299
- Storage: {
300
- "Local File System": {
301
- logo: `${StaticBaseUrl}/img/social_file.png`,
302
- url: "",
303
- },
304
- "AWS S3": {
305
- logo: `${StaticBaseUrl}/img/social_aws.png`,
306
- url: "https://aws.amazon.com/s3",
307
- },
308
- MinIO: {
309
- logo: "https://min.io/resources/img/logo.svg",
310
- url: "https://min.io/",
311
- },
312
- "Aliyun OSS": {
313
- logo: `${StaticBaseUrl}/img/social_aliyun.png`,
314
- url: "https://aliyun.com/product/oss",
315
- },
316
- "Tencent Cloud COS": {
317
- logo: `${StaticBaseUrl}/img/social_tencent_cloud.jpg`,
318
- url: "https://cloud.tencent.com/product/cos",
319
- },
320
- "Azure Blob": {
321
- logo: `${StaticBaseUrl}/img/social_azure.png`,
322
- url: "https://azure.microsoft.com/en-us/services/storage/blobs/",
323
- },
324
- "Qiniu Cloud Kodo": {
325
- logo: `${StaticBaseUrl}/img/social_qiniu_cloud.png`,
326
- url: "https://www.qiniu.com/solutions/storage",
327
- },
328
- "Google Cloud Storage": {
329
- logo: `${StaticBaseUrl}/img/social_google_cloud.png`,
330
- url: "https://cloud.google.com/storage",
331
- },
332
- Synology: {
333
- logo: `${StaticBaseUrl}/img/social_synology.png`,
334
- url: "https://www.synology.com/en-global/dsm/feature/file_sharing",
335
- },
336
- },
337
- SAML: {
338
- "Aliyun IDaaS": {
339
- logo: `${StaticBaseUrl}/img/social_aliyun.png`,
340
- url: "https://aliyun.com/product/idaas",
341
- },
342
- Keycloak: {
343
- logo: `${StaticBaseUrl}/img/social_keycloak.png`,
344
- url: "https://www.keycloak.org/",
345
- },
346
- Custom: {
347
- logo: `${StaticBaseUrl}/img/social_custom.png`,
348
- url: "https://door.casdoor.com/",
349
- },
350
- },
351
- Payment: {
352
- Dummy: {
353
- logo: `${StaticBaseUrl}/img/payment_paypal.png`,
354
- url: "",
355
- },
356
- Alipay: {
357
- logo: `${StaticBaseUrl}/img/payment_alipay.png`,
358
- url: "https://www.alipay.com/",
359
- },
360
- "WeChat Pay": {
361
- logo: `${StaticBaseUrl}/img/payment_wechat_pay.png`,
362
- url: "https://pay.weixin.qq.com/",
363
- },
364
- PayPal: {
365
- logo: `${StaticBaseUrl}/img/payment_paypal.png`,
366
- url: "https://www.paypal.com/",
367
- },
368
- Stripe: {
369
- logo: `${StaticBaseUrl}/img/social_stripe.png`,
370
- url: "https://stripe.com/",
371
- },
372
- GC: {
373
- logo: `${StaticBaseUrl}/img/payment_gc.png`,
374
- url: "https://gc.org",
375
- },
376
- },
377
- Captcha: {
378
- Default: {
379
- logo: `${StaticBaseUrl}/img/captcha_default.png`,
380
- url: "https://pkg.go.dev/github.com/dchest/captcha",
381
- },
382
- reCAPTCHA: {
383
- logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
384
- url: "https://www.google.com/recaptcha",
385
- },
386
- hCaptcha: {
387
- logo: `${StaticBaseUrl}/img/social_hcaptcha.png`,
388
- url: "https://www.hcaptcha.com",
389
- },
390
- "Aliyun Captcha": {
391
- logo: `${StaticBaseUrl}/img/social_aliyun.png`,
392
- url: "https://help.aliyun.com/product/28308.html",
393
- },
394
- GEETEST: {
395
- logo: `${StaticBaseUrl}/img/social_geetest.png`,
396
- url: "https://www.geetest.com",
397
- },
398
- "Cloudflare Turnstile": {
399
- logo: `${StaticBaseUrl}/img/social_cloudflare.png`,
400
- url: "https://www.cloudflare.com/products/turnstile/",
401
- },
402
- },
403
- AI: {
404
- "OpenAI API - GPT": {
405
- logo: `${StaticBaseUrl}/img/social_openai.svg`,
406
- url: "https://platform.openai.com",
407
- },
408
- },
409
- Web3: {
410
- MetaMask: {
411
- logo: `${StaticBaseUrl}/img/social_metamask.svg`,
412
- url: "https://metamask.io/",
413
- },
414
- Web3Onboard: {
415
- logo: `${StaticBaseUrl}/img/social_web3onboard.svg`,
416
- url: "https://onboard.blocknative.com/",
417
- },
418
- },
419
- Notification: {
420
- Telegram: {
421
- logo: `${StaticBaseUrl}/img/social_telegram.png`,
422
- url: "https://telegram.org/",
423
- },
424
- "Custom HTTP": {
425
- logo: `${StaticBaseUrl}/img/email_default.png`,
426
- url: "https://casdoor.org/docs/provider/notification/overview",
427
- },
428
- DingTalk: {
429
- logo: `${StaticBaseUrl}/img/social_dingtalk.png`,
430
- url: "https://www.dingtalk.com/",
431
- },
432
- Lark: {
433
- logo: `${StaticBaseUrl}/img/social_lark.png`,
434
- url: "https://www.larksuite.com/",
435
- },
436
- "Microsoft Teams": {
437
- logo: `${StaticBaseUrl}/img/social_teams.png`,
438
- url: "https://www.microsoft.com/microsoft-teams",
439
- },
440
- Bark: {
441
- logo: `${StaticBaseUrl}/img/social_bark.png`,
442
- url: "https://apps.apple.com/us/app/bark-customed-notifications/id1403753865",
443
- },
444
- Pushover: {
445
- logo: `${StaticBaseUrl}/img/social_pushover.png`,
446
- url: "https://pushover.net/",
447
- },
448
- Pushbullet: {
449
- logo: `${StaticBaseUrl}/img/social_pushbullet.png`,
450
- url: "https://www.pushbullet.com/",
451
- },
452
- Slack: {
453
- logo: `${StaticBaseUrl}/img/social_slack.png`,
454
- url: "https://slack.com/",
455
- },
456
- Webpush: {
457
- logo: `${StaticBaseUrl}/img/email_default.png`,
458
- url: "https://developer.mozilla.org/en-US/docs/Web/API/Push_API",
459
- },
460
- Discord: {
461
- logo: `${StaticBaseUrl}/img/social_discord.png`,
462
- url: "https://discord.com/",
463
- },
464
- "Google Chat": {
465
- logo: `${StaticBaseUrl}/img/social_google_chat.png`,
466
- url: "https://workspace.google.com/intl/en/products/chat/",
467
- },
468
- Line: {
469
- logo: `${StaticBaseUrl}/img/social_line.png`,
470
- url: "https://line.me/",
471
- },
472
- Matrix: {
473
- logo: `${StaticBaseUrl}/img/social_matrix.png`,
474
- url: "https://www.matrix.org/",
475
- },
476
- Twitter: {
477
- logo: `${StaticBaseUrl}/img/social_twitter.png`,
478
- url: "https://twitter.com/",
479
- },
480
- Reddit: {
481
- logo: `${StaticBaseUrl}/img/social_reddit.png`,
482
- url: "https://www.reddit.com/",
483
- },
484
- "Rocket Chat": {
485
- logo: `${StaticBaseUrl}/img/social_rocket_chat.png`,
486
- url: "https://rocket.chat/",
487
- },
488
- Viber: {
489
- logo: `${StaticBaseUrl}/img/social_viber.png`,
490
- url: "https://www.viber.com/",
491
- },
492
- },
493
- };
1
+ import type { Application, Provider } from "./provider";
2
+ import * as phoneNumber from "libphonenumber-js";
3
+
4
+ export const StaticBaseUrl = "https://cdn.casbin.org";
5
+ export const ROOT_URLS: { casdoor: string; springmicro: string | undefined } = {
6
+ casdoor: "https://casdoor",
7
+ springmicro: undefined,
8
+ };
9
+
10
+ export function getLanguage() {
11
+ return "en";
12
+ }
13
+
14
+ export function getAcceptLanguage() {
15
+ // https://github.com/casdoor/casdoor/blob/739cfd84ed232159226f514c4a0b5168a995eeb0/web/src/Setting.js#L891
16
+ return "en;q=0.9,en;q=0.8";
17
+ }
18
+
19
+ export function deepCopy(obj: any) {
20
+ // https://github.com/casdoor/casdoor/blob/739cfd84ed232159226f514c4a0b5168a995eeb0/web/src/Setting.js#L755
21
+ return Object.assign({}, obj);
22
+ }
23
+
24
+ export function showMessage(obj: string, text: string) {
25
+ // https://github.com/casdoor/casdoor/blob/739cfd84ed232159226f514c4a0b5168a995eeb0/web/src/Setting.js#L731
26
+ // message is the antd toast api
27
+ // if (type === "success") {
28
+ // message.success(text);
29
+ // } else if (type === "error") {
30
+ // message.error(text);
31
+ // } else if (type === "info") {
32
+ // message.info(text);
33
+ // }
34
+ // temporary workaround
35
+ alert(text);
36
+ }
37
+
38
+ export function goToLink(link?: string) {
39
+ if (link === undefined) return;
40
+ window.location.href = link;
41
+ }
42
+
43
+ type ProviderItem = { provider?: Provider | null; prompted: boolean };
44
+
45
+ export function isProviderVisible(providerItem: ProviderItem) {
46
+ if (providerItem.provider === undefined || providerItem.provider === null) {
47
+ return false;
48
+ }
49
+
50
+ if (!["OAuth", "SAML", "Web3"].includes(providerItem.provider.category)) {
51
+ return false;
52
+ }
53
+
54
+ if (providerItem.provider.type === "WeChatMiniProgram") {
55
+ return false;
56
+ }
57
+
58
+ return true;
59
+ }
60
+
61
+ export function isProviderPrompted(providerItem: ProviderItem) {
62
+ return isProviderVisible(providerItem) && providerItem.prompted;
63
+ }
64
+
65
+ type SignupItem = {
66
+ visible: boolean;
67
+ prompted: boolean;
68
+ };
69
+
70
+ export function isSignupItemPrompted(signupItem: SignupItem) {
71
+ return signupItem.visible && signupItem.prompted;
72
+ }
73
+
74
+ export function getAllPromptedProviderItems(application: Application) {
75
+ return application.providers?.filter((providerItem) =>
76
+ isProviderPrompted(providerItem)
77
+ );
78
+ }
79
+
80
+ export function getAllPromptedSignupItems(application: Application) {
81
+ return application.signupItems?.filter((signupItem) =>
82
+ isSignupItemPrompted(signupItem)
83
+ );
84
+ }
85
+
86
+ export function getSignupItem(application: Application, itemName: string) {
87
+ const signupItems = application.signupItems?.filter(
88
+ (signupItem) => signupItem.name === itemName
89
+ );
90
+ if (signupItems?.length ?? 0 > 0) {
91
+ return signupItems![0];
92
+ }
93
+ return null;
94
+ }
95
+
96
+ export function isAffiliationPrompted(application: Application) {
97
+ const signupItem = getSignupItem(application, "Affiliation");
98
+ if (signupItem === null) {
99
+ return false;
100
+ }
101
+
102
+ return signupItem.prompted;
103
+ }
104
+
105
+ export function isValidIdCard(idCard: string) {
106
+ return idCard !== "";
107
+
108
+ // const idCardRegex = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9X]$/;
109
+ // return idCardRegex.test(idCard);
110
+ }
111
+
112
+ export function isValidEmail(email: string) {
113
+ // https://github.com/yiminghe/async-validator/blob/057b0b047f88fac65457bae691d6cb7c6fe48ce1/src/rule/type.ts#L9
114
+ const emailRegex =
115
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
116
+ return emailRegex.test(email);
117
+ }
118
+
119
+ export function isValidPhone(phone: string, countryCode = "") {
120
+ if (countryCode !== "" && countryCode !== "CN") {
121
+ // @ts-ignore
122
+ return phoneNumber.isValidPhoneNumber(phone, countryCode);
123
+ }
124
+
125
+ // https://learnku.com/articles/31543, `^s*$` filter empty email individually.
126
+ const phoneCnRegex =
127
+ /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
128
+ const phoneRegex = /[0-9]{4,15}$/;
129
+
130
+ return countryCode === "CN"
131
+ ? phoneCnRegex.test(phone)
132
+ : phoneRegex.test(phone);
133
+ }
134
+
135
+ function isSigninMethodEnabled(
136
+ application: Application | null,
137
+ signinMethod: string
138
+ ) {
139
+ if (application && application.signinMethods) {
140
+ return (
141
+ application.signinMethods.filter((item) => item.name === signinMethod)
142
+ .length > 0
143
+ );
144
+ } else {
145
+ return false;
146
+ }
147
+ }
148
+
149
+ export function isPasswordEnabled(application: Application | null) {
150
+ return isSigninMethodEnabled(application, "Password");
151
+ }
152
+
153
+ export function isCodeSigninEnabled(application: Application | null) {
154
+ return isSigninMethodEnabled(application, "Verification code");
155
+ }
156
+
157
+ export function isWebAuthnEnabled(application: Application | null) {
158
+ return isSigninMethodEnabled(application, "WebAuthn");
159
+ }
160
+
161
+ export function isLdapEnabled(application: Application | null) {
162
+ return isSigninMethodEnabled(application, "LDAP");
163
+ }
164
+
165
+ export function isFaceIdEnabled(application: Application | null) {
166
+ return isSigninMethodEnabled(application, "Face ID");
167
+ }
168
+
169
+ export function hasPromptPage(application: Application) {
170
+ const providerItems = getAllPromptedProviderItems(application);
171
+ if (providerItems?.length ?? 0 > 0) {
172
+ return true;
173
+ }
174
+
175
+ const signupItems = getAllPromptedSignupItems(application);
176
+ if (signupItems?.length ?? 0 > 0) {
177
+ return true;
178
+ }
179
+
180
+ return isAffiliationPrompted(application);
181
+ }
182
+
183
+ export function getProviderLogoURL(provider: Provider) {
184
+ if (provider.type === "Custom" && provider.customLogo) {
185
+ return provider.customLogo;
186
+ }
187
+ if (provider.category === "OAuth") {
188
+ return `${StaticBaseUrl}/img/social_${provider.type.toLowerCase()}.png`;
189
+ } else {
190
+ const info: { logo: string; url: string } =
191
+ OtherProviderInfo[provider.category as OPIKey][
192
+ provider.type as OPITypeKey
193
+ ];
194
+ // avoid crash when provider is not found
195
+ if (info) {
196
+ return info.logo;
197
+ }
198
+ return "";
199
+ }
200
+ }
201
+
202
+ export type OPIKey = keyof typeof OtherProviderInfo;
203
+
204
+ export type OPITypeKey = keyof (typeof OtherProviderInfo)[OPIKey];
205
+
206
+ export const OtherProviderInfo = {
207
+ SMS: {
208
+ "Aliyun SMS": {
209
+ logo: `${StaticBaseUrl}/img/social_aliyun.png`,
210
+ url: "https://aliyun.com/product/sms",
211
+ },
212
+ "Amazon SNS": {
213
+ logo: `${StaticBaseUrl}/img/social_aws.png`,
214
+ url: "https://aws.amazon.com/cn/sns/",
215
+ },
216
+ "Azure ACS": {
217
+ logo: `${StaticBaseUrl}/img/social_azure.png`,
218
+ url: "https://azure.microsoft.com/en-us/products/communication-services",
219
+ },
220
+ "Infobip SMS": {
221
+ logo: `${StaticBaseUrl}/img/social_infobip.png`,
222
+ url: "https://portal.infobip.com/homepage/",
223
+ },
224
+ "Tencent Cloud SMS": {
225
+ logo: `${StaticBaseUrl}/img/social_tencent_cloud.jpg`,
226
+ url: "https://cloud.tencent.com/product/sms",
227
+ },
228
+ "Baidu Cloud SMS": {
229
+ logo: `${StaticBaseUrl}/img/social_baidu_cloud.png`,
230
+ url: "https://cloud.baidu.com/product/sms.html",
231
+ },
232
+ "Volc Engine SMS": {
233
+ logo: `${StaticBaseUrl}/img/social_volc_engine.jpg`,
234
+ url: "https://www.volcengine.com/products/cloud-sms",
235
+ },
236
+ "Huawei Cloud SMS": {
237
+ logo: `${StaticBaseUrl}/img/social_huawei.png`,
238
+ url: "https://www.huaweicloud.com/product/msgsms.html",
239
+ },
240
+ "UCloud SMS": {
241
+ logo: `${StaticBaseUrl}/img/social_ucloud.png`,
242
+ url: "https://www.ucloud.cn/site/product/usms.html",
243
+ },
244
+ "Twilio SMS": {
245
+ logo: `${StaticBaseUrl}/img/social_twilio.svg`,
246
+ url: "https://www.twilio.com/messaging",
247
+ },
248
+ "SmsBao SMS": {
249
+ logo: `${StaticBaseUrl}/img/social_smsbao.png`,
250
+ url: "https://www.smsbao.com/",
251
+ },
252
+ "SUBMAIL SMS": {
253
+ logo: `${StaticBaseUrl}/img/social_submail.svg`,
254
+ url: "https://www.mysubmail.com",
255
+ },
256
+ "Msg91 SMS": {
257
+ logo: `${StaticBaseUrl}/img/social_msg91.ico`,
258
+ url: "https://control.msg91.com/app/",
259
+ },
260
+ "OSON SMS": {
261
+ logo: "https://osonsms.com/images/osonsms-logo.svg",
262
+ url: "https://osonsms.com/",
263
+ },
264
+ "Custom HTTP SMS": {
265
+ logo: `${StaticBaseUrl}/img/social_default.png`,
266
+ url: "https://casdoor.org/docs/provider/sms/overview",
267
+ },
268
+ "Mock SMS": {
269
+ logo: `${StaticBaseUrl}/img/social_default.png`,
270
+ url: "",
271
+ },
272
+ },
273
+ Email: {
274
+ Default: {
275
+ logo: `${StaticBaseUrl}/img/email_default.png`,
276
+ url: "",
277
+ },
278
+ SUBMAIL: {
279
+ logo: `${StaticBaseUrl}/img/social_submail.svg`,
280
+ url: "https://www.mysubmail.com",
281
+ },
282
+ Mailtrap: {
283
+ logo: `${StaticBaseUrl}/img/email_mailtrap.png`,
284
+ url: "https://mailtrap.io",
285
+ },
286
+ "Azure ACS": {
287
+ logo: `${StaticBaseUrl}/img/social_azure.png`,
288
+ url: "https://learn.microsoft.com/zh-cn/azure/communication-services",
289
+ },
290
+ SendGrid: {
291
+ logo: `${StaticBaseUrl}/img/email_sendgrid.png`,
292
+ url: "https://sendgrid.com/",
293
+ },
294
+ "Custom HTTP Email": {
295
+ logo: `${StaticBaseUrl}/img/social_default.png`,
296
+ url: "https://casdoor.org/docs/provider/email/overview",
297
+ },
298
+ },
299
+ Storage: {
300
+ "Local File System": {
301
+ logo: `${StaticBaseUrl}/img/social_file.png`,
302
+ url: "",
303
+ },
304
+ "AWS S3": {
305
+ logo: `${StaticBaseUrl}/img/social_aws.png`,
306
+ url: "https://aws.amazon.com/s3",
307
+ },
308
+ MinIO: {
309
+ logo: "https://min.io/resources/img/logo.svg",
310
+ url: "https://min.io/",
311
+ },
312
+ "Aliyun OSS": {
313
+ logo: `${StaticBaseUrl}/img/social_aliyun.png`,
314
+ url: "https://aliyun.com/product/oss",
315
+ },
316
+ "Tencent Cloud COS": {
317
+ logo: `${StaticBaseUrl}/img/social_tencent_cloud.jpg`,
318
+ url: "https://cloud.tencent.com/product/cos",
319
+ },
320
+ "Azure Blob": {
321
+ logo: `${StaticBaseUrl}/img/social_azure.png`,
322
+ url: "https://azure.microsoft.com/en-us/services/storage/blobs/",
323
+ },
324
+ "Qiniu Cloud Kodo": {
325
+ logo: `${StaticBaseUrl}/img/social_qiniu_cloud.png`,
326
+ url: "https://www.qiniu.com/solutions/storage",
327
+ },
328
+ "Google Cloud Storage": {
329
+ logo: `${StaticBaseUrl}/img/social_google_cloud.png`,
330
+ url: "https://cloud.google.com/storage",
331
+ },
332
+ Synology: {
333
+ logo: `${StaticBaseUrl}/img/social_synology.png`,
334
+ url: "https://www.synology.com/en-global/dsm/feature/file_sharing",
335
+ },
336
+ },
337
+ SAML: {
338
+ "Aliyun IDaaS": {
339
+ logo: `${StaticBaseUrl}/img/social_aliyun.png`,
340
+ url: "https://aliyun.com/product/idaas",
341
+ },
342
+ Keycloak: {
343
+ logo: `${StaticBaseUrl}/img/social_keycloak.png`,
344
+ url: "https://www.keycloak.org/",
345
+ },
346
+ Custom: {
347
+ logo: `${StaticBaseUrl}/img/social_custom.png`,
348
+ url: "https://door.casdoor.com/",
349
+ },
350
+ },
351
+ Payment: {
352
+ Dummy: {
353
+ logo: `${StaticBaseUrl}/img/payment_paypal.png`,
354
+ url: "",
355
+ },
356
+ Alipay: {
357
+ logo: `${StaticBaseUrl}/img/payment_alipay.png`,
358
+ url: "https://www.alipay.com/",
359
+ },
360
+ "WeChat Pay": {
361
+ logo: `${StaticBaseUrl}/img/payment_wechat_pay.png`,
362
+ url: "https://pay.weixin.qq.com/",
363
+ },
364
+ PayPal: {
365
+ logo: `${StaticBaseUrl}/img/payment_paypal.png`,
366
+ url: "https://www.paypal.com/",
367
+ },
368
+ Stripe: {
369
+ logo: `${StaticBaseUrl}/img/social_stripe.png`,
370
+ url: "https://stripe.com/",
371
+ },
372
+ GC: {
373
+ logo: `${StaticBaseUrl}/img/payment_gc.png`,
374
+ url: "https://gc.org",
375
+ },
376
+ },
377
+ Captcha: {
378
+ Default: {
379
+ logo: `${StaticBaseUrl}/img/captcha_default.png`,
380
+ url: "https://pkg.go.dev/github.com/dchest/captcha",
381
+ },
382
+ reCAPTCHA: {
383
+ logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
384
+ url: "https://www.google.com/recaptcha",
385
+ },
386
+ hCaptcha: {
387
+ logo: `${StaticBaseUrl}/img/social_hcaptcha.png`,
388
+ url: "https://www.hcaptcha.com",
389
+ },
390
+ "Aliyun Captcha": {
391
+ logo: `${StaticBaseUrl}/img/social_aliyun.png`,
392
+ url: "https://help.aliyun.com/product/28308.html",
393
+ },
394
+ GEETEST: {
395
+ logo: `${StaticBaseUrl}/img/social_geetest.png`,
396
+ url: "https://www.geetest.com",
397
+ },
398
+ "Cloudflare Turnstile": {
399
+ logo: `${StaticBaseUrl}/img/social_cloudflare.png`,
400
+ url: "https://www.cloudflare.com/products/turnstile/",
401
+ },
402
+ },
403
+ AI: {
404
+ "OpenAI API - GPT": {
405
+ logo: `${StaticBaseUrl}/img/social_openai.svg`,
406
+ url: "https://platform.openai.com",
407
+ },
408
+ },
409
+ Web3: {
410
+ MetaMask: {
411
+ logo: `${StaticBaseUrl}/img/social_metamask.svg`,
412
+ url: "https://metamask.io/",
413
+ },
414
+ Web3Onboard: {
415
+ logo: `${StaticBaseUrl}/img/social_web3onboard.svg`,
416
+ url: "https://onboard.blocknative.com/",
417
+ },
418
+ },
419
+ Notification: {
420
+ Telegram: {
421
+ logo: `${StaticBaseUrl}/img/social_telegram.png`,
422
+ url: "https://telegram.org/",
423
+ },
424
+ "Custom HTTP": {
425
+ logo: `${StaticBaseUrl}/img/email_default.png`,
426
+ url: "https://casdoor.org/docs/provider/notification/overview",
427
+ },
428
+ DingTalk: {
429
+ logo: `${StaticBaseUrl}/img/social_dingtalk.png`,
430
+ url: "https://www.dingtalk.com/",
431
+ },
432
+ Lark: {
433
+ logo: `${StaticBaseUrl}/img/social_lark.png`,
434
+ url: "https://www.larksuite.com/",
435
+ },
436
+ "Microsoft Teams": {
437
+ logo: `${StaticBaseUrl}/img/social_teams.png`,
438
+ url: "https://www.microsoft.com/microsoft-teams",
439
+ },
440
+ Bark: {
441
+ logo: `${StaticBaseUrl}/img/social_bark.png`,
442
+ url: "https://apps.apple.com/us/app/bark-customed-notifications/id1403753865",
443
+ },
444
+ Pushover: {
445
+ logo: `${StaticBaseUrl}/img/social_pushover.png`,
446
+ url: "https://pushover.net/",
447
+ },
448
+ Pushbullet: {
449
+ logo: `${StaticBaseUrl}/img/social_pushbullet.png`,
450
+ url: "https://www.pushbullet.com/",
451
+ },
452
+ Slack: {
453
+ logo: `${StaticBaseUrl}/img/social_slack.png`,
454
+ url: "https://slack.com/",
455
+ },
456
+ Webpush: {
457
+ logo: `${StaticBaseUrl}/img/email_default.png`,
458
+ url: "https://developer.mozilla.org/en-US/docs/Web/API/Push_API",
459
+ },
460
+ Discord: {
461
+ logo: `${StaticBaseUrl}/img/social_discord.png`,
462
+ url: "https://discord.com/",
463
+ },
464
+ "Google Chat": {
465
+ logo: `${StaticBaseUrl}/img/social_google_chat.png`,
466
+ url: "https://workspace.google.com/intl/en/products/chat/",
467
+ },
468
+ Line: {
469
+ logo: `${StaticBaseUrl}/img/social_line.png`,
470
+ url: "https://line.me/",
471
+ },
472
+ Matrix: {
473
+ logo: `${StaticBaseUrl}/img/social_matrix.png`,
474
+ url: "https://www.matrix.org/",
475
+ },
476
+ Twitter: {
477
+ logo: `${StaticBaseUrl}/img/social_twitter.png`,
478
+ url: "https://twitter.com/",
479
+ },
480
+ Reddit: {
481
+ logo: `${StaticBaseUrl}/img/social_reddit.png`,
482
+ url: "https://www.reddit.com/",
483
+ },
484
+ "Rocket Chat": {
485
+ logo: `${StaticBaseUrl}/img/social_rocket_chat.png`,
486
+ url: "https://rocket.chat/",
487
+ },
488
+ Viber: {
489
+ logo: `${StaticBaseUrl}/img/social_viber.png`,
490
+ url: "https://www.viber.com/",
491
+ },
492
+ },
493
+ };