@authing/react-ui-components 3.0.0-alpha → 3.0.0-rc.3

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 (232) hide show
  1. package/lib/index.d.ts +781 -110
  2. package/lib/index.min.css +2 -2
  3. package/lib/index.min.js +1 -1
  4. package/lib/index.min.js.LICENSE.txt +2 -0
  5. package/package.json +34 -12
  6. package/.eslintignore +0 -6
  7. package/.eslintrc.js +0 -7
  8. package/.prettierrc +0 -5
  9. package/.vscode/settings.json +0 -31
  10. package/build/favicon.ico +0 -0
  11. package/build/logo192.png +0 -0
  12. package/build/logo512.png +0 -0
  13. package/build/manifest.json +0 -25
  14. package/build/robots.txt +0 -3
  15. package/components/AuthingDropdown/index.tsx +0 -52
  16. package/components/AuthingDropdown/style.less +0 -43
  17. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  18. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  19. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  20. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  21. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  22. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  23. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  24. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  25. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  26. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  27. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  28. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  29. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  30. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  31. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  32. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  33. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  34. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  35. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  36. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  37. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  38. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  39. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  40. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  41. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  42. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  43. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  44. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  45. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  46. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  47. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  48. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  49. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  50. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  51. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  52. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  53. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  54. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  55. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  56. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  57. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  58. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  59. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  60. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  61. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  62. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  63. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  64. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  65. package/components/AuthingGuard/Forms/index.ts +0 -13
  66. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  67. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  68. package/components/AuthingGuard/Header/index.tsx +0 -25
  69. package/components/AuthingGuard/Header/style.less +0 -52
  70. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  71. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  72. package/components/AuthingGuard/IconFont/style.less +0 -6
  73. package/components/AuthingGuard/IconFont/svg.js +0 -2
  74. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  75. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  76. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  77. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  78. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  79. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  80. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  81. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  82. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  83. package/components/AuthingGuard/api/appConfig.ts +0 -146
  84. package/components/AuthingGuard/api/index.ts +0 -3
  85. package/components/AuthingGuard/api/sso.ts +0 -29
  86. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  87. package/components/AuthingGuard/constants.ts +0 -105
  88. package/components/AuthingGuard/hooks/index.tsx +0 -70
  89. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  90. package/components/AuthingGuard/index.tsx +0 -126
  91. package/components/AuthingGuard/style.less +0 -103
  92. package/components/AuthingGuard/types/Forms.ts +0 -94
  93. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  94. package/components/AuthingGuard/types/GuardState.ts +0 -7
  95. package/components/AuthingGuard/types/Locales.ts +0 -12
  96. package/components/AuthingGuard/types/index.ts +0 -4
  97. package/components/AuthingTabs/index.tsx +0 -98
  98. package/components/AuthingTabs/style.less +0 -135
  99. package/components/BindTotp/core/bindSuccess.tsx +0 -61
  100. package/components/BindTotp/core/securityCode.tsx +0 -119
  101. package/components/BindTotp/index.tsx +0 -134
  102. package/components/BindTotp/props.ts +0 -30
  103. package/components/BindTotp/styles.less +0 -56
  104. package/components/ChangeLanguage/index.tsx +0 -35
  105. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  106. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  107. package/components/ChangePassword/index.tsx +0 -59
  108. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  109. package/components/CompleteInfo/index.tsx +0 -45
  110. package/components/CompleteInfo/props.ts +0 -40
  111. package/components/CompleteInfo/styles.less +0 -7
  112. package/components/CompleteUserInfo/index.tsx +0 -49
  113. package/components/CompleteUserInfo/props.ts +0 -25
  114. package/components/ComponentsRender/index.back +0 -64
  115. package/components/CopyAbleText/index.tsx +0 -54
  116. package/components/CopyAbleText/style.less +0 -13
  117. package/components/DownloadAuthenticator/index.tsx +0 -97
  118. package/components/DownloadAuthenticator/props.ts +0 -22
  119. package/components/DownloadAuthenticator/styles.less +0 -52
  120. package/components/ForgetPassword/core/resetPassword.tsx +0 -150
  121. package/components/ForgetPassword/index.tsx +0 -51
  122. package/components/Guard/Guard.tsx +0 -226
  123. package/components/Guard/authClient.ts +0 -55
  124. package/components/Guard/config.ts +0 -19
  125. package/components/Guard/event.ts +0 -18
  126. package/components/Guard/index.tsx +0 -10
  127. package/components/Guard/module.ts +0 -19
  128. package/components/Guard/stateMachine.ts +0 -133
  129. package/components/Guard/styles.less +0 -444
  130. package/components/IconFont/iconfont.js +0 -74
  131. package/components/IconFont/index.tsx +0 -16
  132. package/components/IconFont/style.less +0 -6
  133. package/components/IconFont/svg.js +0 -2
  134. package/components/ImagePro/index.tsx +0 -52
  135. package/components/ImagePro/styles.less +0 -40
  136. package/components/Login/codemap.ts +0 -35
  137. package/components/Login/core/withAD.tsx +0 -9
  138. package/components/Login/core/withAppQrcode.tsx +0 -49
  139. package/components/Login/core/withLDAP.tsx +0 -145
  140. package/components/Login/core/withPassword.tsx +0 -176
  141. package/components/Login/core/withPhonecode.tsx +0 -135
  142. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  143. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  144. package/components/Login/index.tsx +0 -359
  145. package/components/Login/props.ts +0 -90
  146. package/components/Login/socialLogin/index.tsx +0 -413
  147. package/components/Login/socialLogin/style.less +0 -61
  148. package/components/Login/styles.less +0 -53
  149. package/components/MFA/codemap.ts +0 -21
  150. package/components/MFA/core/email.tsx +0 -226
  151. package/components/MFA/core/face.tsx +0 -297
  152. package/components/MFA/core/face_deps.tsx +0 -37
  153. package/components/MFA/core/sms.tsx +0 -222
  154. package/components/MFA/core/totp.tsx +0 -137
  155. package/components/MFA/index.tsx +0 -135
  156. package/components/MFA/mfaMethods/index.tsx +0 -81
  157. package/components/MFA/mfaMethods/style.less +0 -39
  158. package/components/MFA/props.ts +0 -51
  159. package/components/MFA/styles.less +0 -92
  160. package/components/NeedHelpView/core/describeQuestions.tsx +0 -227
  161. package/components/NeedHelpView/index.tsx +0 -99
  162. package/components/RecoveryCode/core/useCode.tsx +0 -71
  163. package/components/RecoveryCode/index.tsx +0 -27
  164. package/components/RecoveryCode/interface.ts +0 -31
  165. package/components/RecoveryCode/style.less +0 -13
  166. package/components/Register/codemap.ts +0 -16
  167. package/components/Register/components/Agreements/index.tsx +0 -81
  168. package/components/Register/components/Agreements/style.less +0 -44
  169. package/components/Register/core/WithEmail.tsx +0 -250
  170. package/components/Register/core/WithPhone.tsx +0 -190
  171. package/components/Register/index.tsx +0 -122
  172. package/components/Register/props.ts +0 -50
  173. package/components/SendCode/SendCodeBtn.tsx +0 -96
  174. package/components/SendCode/index.tsx +0 -98
  175. package/components/SendCode/style.less +0 -31
  176. package/components/ShieldSpin/index.tsx +0 -27
  177. package/components/ShieldSpin/loading.svg +0 -29
  178. package/components/SubmitButton/index.tsx +0 -50
  179. package/components/Type/index.ts +0 -61
  180. package/components/VerifyCodeInput/index.tsx +0 -76
  181. package/components/VerifyCodeInput/style.less +0 -24
  182. package/components/_utils/GuardErrorCode.ts +0 -8
  183. package/components/_utils/clipboard.ts +0 -27
  184. package/components/_utils/config.ts +0 -123
  185. package/components/_utils/guradHttp.ts +0 -93
  186. package/components/_utils/hooks/index.ts +0 -56
  187. package/components/_utils/http.ts +0 -85
  188. package/components/_utils/index.ts +0 -310
  189. package/components/_utils/locales/en/common.json +0 -218
  190. package/components/_utils/locales/en/index.ts +0 -6
  191. package/components/_utils/locales/en/login.json +0 -95
  192. package/components/_utils/locales/en/map.json +0 -4
  193. package/components/_utils/locales/en/user.json +0 -82
  194. package/components/_utils/locales/index.ts +0 -45
  195. package/components/_utils/locales/zh/common.json +0 -218
  196. package/components/_utils/locales/zh/index.ts +0 -6
  197. package/components/_utils/locales/zh/login.json +0 -95
  198. package/components/_utils/locales/zh/map.json +0 -4
  199. package/components/_utils/locales/zh/user.json +0 -82
  200. package/components/_utils/popupCenter.ts +0 -48
  201. package/components/context/base.tsx +0 -28
  202. package/components/context/global/context.tsx +0 -39
  203. package/components/context/global/reducer.tsx +0 -56
  204. package/components/context/module/context.tsx +0 -23
  205. package/components/index.ts +0 -10
  206. package/config/antdReplacer.js +0 -51
  207. package/config/env.js +0 -104
  208. package/config/getHttpsConfig.js +0 -66
  209. package/config/jest/cssTransform.js +0 -14
  210. package/config/jest/fileTransform.js +0 -40
  211. package/config/modules.js +0 -134
  212. package/config/paths.js +0 -71
  213. package/config/pnpTs.js +0 -35
  214. package/config/webpack.config.js +0 -835
  215. package/config/webpackDevServer.config.js +0 -130
  216. package/examples.tsx +0 -100
  217. package/index.js +0 -1
  218. package/logo.svg +0 -7
  219. package/public/favicon.ico +0 -0
  220. package/public/index.html +0 -43
  221. package/public/logo192.png +0 -0
  222. package/public/logo512.png +0 -0
  223. package/public/manifest.json +0 -25
  224. package/public/robots.txt +0 -3
  225. package/react-app-env.d.ts +0 -71
  226. package/reportWebVitals.ts +0 -15
  227. package/scripts/build.js +0 -208
  228. package/scripts/lib.js +0 -200
  229. package/scripts/start.js +0 -162
  230. package/scripts/test.js +0 -49
  231. package/setupTests.ts +0 -5
  232. package/tsconfig.json +0 -30
@@ -1,50 +0,0 @@
1
- import { message } from 'antd'
2
- import React, { FC } from 'react'
3
- import { CommonMessage } from 'authing-js-sdk'
4
-
5
- import { SendCodeBtn } from './SendCodeBtn'
6
- import { validate } from '../../../_utils'
7
- import { useGuardContext } from '../../../context/global/context'
8
-
9
- import './style.less'
10
- import { useTranslation } from 'react-i18next'
11
-
12
- export interface SendPhoneCodeProps {
13
- phone: string
14
- onSend?: () => void
15
- onError?: (error: CommonMessage) => void
16
- }
17
-
18
- export const SendPhoneCode: FC<SendPhoneCodeProps> = ({
19
- phone,
20
- onSend,
21
- onError,
22
- }) => {
23
- const { t } = useTranslation()
24
- const {
25
- state: { authClient },
26
- } = useGuardContext()
27
-
28
- return (
29
- <SendCodeBtn
30
- beforeSend={async () => {
31
- if (!phone) {
32
- message.error(t('login.inputPhone'))
33
- return false
34
- }
35
- if (!validate('phone', phone)) {
36
- message.error(t('common.phoneFormateError'))
37
- return false
38
- }
39
- try {
40
- await authClient.sendSmsCode(phone)
41
- onSend?.()
42
- return true
43
- } catch (error) {
44
- onError?.(error)
45
- return false
46
- }
47
- }}
48
- />
49
- )
50
- }
@@ -1,26 +0,0 @@
1
- .authing-send-code-btn {
2
- display: inline-block;
3
- border: none;
4
- background-color: transparent;
5
- font-size: inherit;
6
- color: #396aff;
7
- cursor: pointer;
8
- padding: 0;
9
- user-select: none;
10
- outline: none;
11
- }
12
-
13
- .authing-send-code-btn:focus {
14
- outline: none;
15
- }
16
-
17
- .authing-send-code-btn[disabled] {
18
- cursor: not-allowed;
19
- filter: opacity(0.5);
20
- }
21
-
22
- @media only screen and (max-width: 719px) {
23
- .authing-send-code-btn {
24
- font-size: 14px;
25
- }
26
- }
@@ -1,86 +0,0 @@
1
- import React, { FC, useState } from 'react'
2
- import { Button, Form, Input, message } from 'antd'
3
-
4
- import { useGuardContext } from '../../../context/global/context'
5
- import { MFACheckPhoneFormProps } from '../../types'
6
-
7
- import './style.less'
8
- import { VALIDATE_PATTERN } from '../../../_utils'
9
- import { useTranslation } from 'react-i18next'
10
-
11
- export const CheckPhoneForm: FC<MFACheckPhoneFormProps> = ({
12
- onSuccess,
13
- mfaToken,
14
- }) => {
15
- const {
16
- state: { authClient },
17
- } = useGuardContext()
18
- const { t } = useTranslation()
19
-
20
- const [rawForm] = Form.useForm()
21
-
22
- const [loading, setLoading] = useState(false)
23
-
24
- const onFinish = async ({ phone }: any) => {
25
- try {
26
- const bindable = await authClient.mfa.phoneOrEmailBindable({
27
- mfaToken,
28
- phone,
29
- })
30
- if (!bindable) {
31
- message.error(
32
- t('common.unBindEmaileDoc', {
33
- email: phone,
34
- })
35
- )
36
- return
37
- }
38
- onSuccess(phone!)
39
- } catch (e) {
40
- // do nothing
41
- } finally {
42
- setLoading(false)
43
- }
44
- }
45
-
46
- return (
47
- <>
48
- <h3 className="authing-guard-mfa-title">{t('common.bindPhone')}</h3>
49
- <p className="authing-guard-mfa-tips">{t('login.bindPhoneInfo')}</p>
50
- <Form
51
- className="authing-mfa-check-phone-from"
52
- form={rawForm}
53
- onSubmitCapture={() => setLoading(true)}
54
- onFinish={onFinish}
55
- onFinishFailed={() => setLoading(false)}
56
- >
57
- <Form.Item
58
- name="phone"
59
- rules={[
60
- {
61
- required: true,
62
- message: t('login.inputPhone'),
63
- },
64
- {
65
- pattern: VALIDATE_PATTERN.phone,
66
- message: t('login.phoneError'),
67
- },
68
- ]}
69
- >
70
- <Input size="large" placeholder={t('login.inputPhone')} />
71
- </Form.Item>
72
-
73
- <Button
74
- className="authing-guard-mfa-confirm-btn"
75
- loading={loading}
76
- block
77
- htmlType="submit"
78
- type="primary"
79
- size="large"
80
- >
81
- {t('common.sure')}
82
- </Button>
83
- </Form>
84
- </>
85
- )
86
- }
@@ -1,113 +0,0 @@
1
- import { User } from 'authing-js-sdk'
2
- import React, { FC, useState } from 'react'
3
- import { Button, Form } from 'antd'
4
-
5
- import { VerifyCodeInput } from '../../../VerifyCodeInput'
6
- import { useGuardContext } from '../../../context/global/context'
7
- import { SmsMFAVerifyFormProps } from '../../../../components/AuthingGuard/types'
8
-
9
- import './style.less'
10
- import { SendCodeBtn } from '../SendPhoneCode/SendCodeBtn'
11
- import { useTranslation } from 'react-i18next'
12
-
13
- const CODE_LEN = 4
14
-
15
- export const VerifyCodeForm: FC<SmsMFAVerifyFormProps> = ({
16
- onSuccess,
17
- onFail,
18
- phone,
19
- mfaToken,
20
- sendCodeRef,
21
- }) => {
22
- const {
23
- state: { authClient },
24
- } = useGuardContext()
25
- const { t } = useTranslation()
26
-
27
- const [rawForm] = Form.useForm()
28
-
29
- const [MfaCode, setMFACode] = useState(new Array(CODE_LEN).fill(''))
30
- const [loading, setLoading] = useState(false)
31
- const [sending, setSending] = useState(false)
32
- const [sent, setSent] = useState(false)
33
-
34
- const onFinish = async (values: any) => {
35
- try {
36
- const user: User = await authClient.mfa.verifyAppSmsMfa({
37
- mfaToken,
38
- phone: phone!,
39
- code: MfaCode.join(''),
40
- })
41
- onSuccess && onSuccess(user)
42
- } catch (e) {
43
- onFail?.(e)
44
- } finally {
45
- setLoading(false)
46
- }
47
- }
48
-
49
- const sendVerifyCode = async () => {
50
- setSending(true)
51
- try {
52
- await authClient.sendSmsCode(phone!)
53
- setSent(true)
54
- return true
55
- } catch (e) {
56
- return false
57
- } finally {
58
- setSending(false)
59
- }
60
- }
61
-
62
- return (
63
- <>
64
- <h3 className="authing-guard-mfa-title">{t('login.inputPhoneCode')}</h3>
65
- <p className="authing-guard-mfa-tips">
66
- {sending
67
- ? t('login.sendingVerifyCode')
68
- : sent
69
- ? `${t('login.verifyCodeSended')} ${phone}`
70
- : t('login.clickSent')}
71
- </p>
72
- <Form
73
- form={rawForm}
74
- onSubmitCapture={() => setLoading(true)}
75
- onFinish={onFinish}
76
- onFinishFailed={() => setLoading(false)}
77
- >
78
- <Form.Item
79
- name="mfaCode"
80
- rules={[
81
- {
82
- validateTrigger: [],
83
- validator() {
84
- if (MfaCode.some((item) => !item)) {
85
- return Promise.reject(t('login.inputFullMfaCode'))
86
- }
87
- return Promise.resolve()
88
- },
89
- },
90
- ]}
91
- >
92
- <VerifyCodeInput
93
- length={CODE_LEN}
94
- verifyCode={MfaCode}
95
- setVerifyCode={setMFACode}
96
- />
97
- </Form.Item>
98
- <SendCodeBtn btnRef={sendCodeRef} beforeSend={() => sendVerifyCode()} />
99
-
100
- <Button
101
- className="authing-guard-mfa-confirm-btn"
102
- loading={loading}
103
- block
104
- htmlType="submit"
105
- type="primary"
106
- size="large"
107
- >
108
- {t('common.sure')}
109
- </Button>
110
- </Form>
111
- </>
112
- )
113
- }
@@ -1,40 +0,0 @@
1
- import React, { FC, useRef, useState } from 'react'
2
- import { useGuardContext } from '../../../context/global/context'
3
- import { CheckPhoneForm } from './CheckPhoneForm'
4
- import { VerifyCodeForm } from './VerifyCodeForm'
5
- import { SmsMFAFormProps } from '../../types'
6
-
7
- export const SmsMfaVerifyForm: FC<SmsMFAFormProps> = ({
8
- onSuccess,
9
- onFail,
10
- }) => {
11
- const {
12
- state: {
13
- mfaData: { mfaToken, phone: userPhone },
14
- },
15
- } = useGuardContext()
16
- const [phone, setPhone] = useState(userPhone)
17
- const sendCodeRef = useRef<HTMLButtonElement>(null)
18
-
19
- return (
20
- <>
21
- {phone ? (
22
- <VerifyCodeForm
23
- sendCodeRef={sendCodeRef}
24
- onSuccess={onSuccess}
25
- onFail={onFail}
26
- phone={phone!}
27
- mfaToken={mfaToken}
28
- ></VerifyCodeForm>
29
- ) : (
30
- <CheckPhoneForm
31
- mfaToken={mfaToken}
32
- onSuccess={(phone) => {
33
- setPhone(phone)
34
- sendCodeRef.current?.click()
35
- }}
36
- ></CheckPhoneForm>
37
- )}
38
- </>
39
- )
40
- }
@@ -1,3 +0,0 @@
1
- .authing-mfa-check-phone-from {
2
- text-align: center;
3
- }
@@ -1,325 +0,0 @@
1
- import qs from 'qs'
2
- import shortid from 'shortid'
3
- import React, { FC, useEffect } from 'react'
4
- import { Button, Avatar, Space, Tooltip, message } from 'antd'
5
-
6
- import { isWechatBrowser, popupCenter } from '../../../_utils'
7
- import { useGuardContext } from '../../../context/global/context'
8
- import {
9
- APP_MFA_CODE,
10
- OTP_MFA_CODE,
11
- } from '../../../../components/AuthingGuard/constants'
12
- import {
13
- Lang,
14
- Protocol,
15
- SocialAndIdpLoginProps,
16
- } from '../../../../components/AuthingGuard/types'
17
- import {
18
- OIDCConnectionConfig,
19
- ICasConnectionConfig,
20
- ISamlConnectionConfig,
21
- IAzureAdConnectionConfig,
22
- IOAuthConnectionConfig,
23
- } from '../../../../components/AuthingGuard/api'
24
- import { requestClient } from '../../../_utils/http'
25
-
26
- import './style.less'
27
- import { IconFont } from '../../IconFont'
28
- import { useScreenSize } from '../../hooks/useScreenSize'
29
- import { SocialConnectionProvider } from 'authing-js-sdk'
30
- import { useTranslation } from 'react-i18next'
31
- import { i18n } from '../../../_utils/locales'
32
-
33
- export const SocialAndIdpLogin: FC<SocialAndIdpLoginProps> = ({
34
- onFail = () => {},
35
- onSuccess = () => {},
36
- }) => {
37
- const {
38
- state: { config, userPoolId, appId, authClient },
39
- } = useGuardContext()
40
- const { t } = useTranslation()
41
-
42
- const noForm = !config.loginMethods?.length
43
-
44
- const [screenSize] = useScreenSize()
45
-
46
- useEffect(() => {
47
- const onMessage = (evt: MessageEvent) => {
48
- // TODO: event.origin是指发送的消息源,一定要进行验证!!!
49
-
50
- const { code, message: errMsg, data, event } = evt.data
51
-
52
- const { source, eventType } = event || {}
53
-
54
- // 社会化登录是用 authing-js-sdk 实现的,不用再在这里回调了
55
- if (source === 'authing' && eventType === 'socialLogin') {
56
- return
57
- }
58
-
59
- try {
60
- const parsedMsg = JSON.parse(errMsg)
61
- const { code: authingCode } = parsedMsg
62
- if ([OTP_MFA_CODE, APP_MFA_CODE].includes(authingCode)) {
63
- onFail(parsedMsg)
64
- return
65
- }
66
- } catch (e) {
67
- // do nothing...
68
- }
69
-
70
- if (code !== undefined) {
71
- if (code === 200) {
72
- localStorage.setItem('_authing_token', data?.token)
73
- onSuccess(data)
74
- } else {
75
- message.error(errMsg)
76
- }
77
- }
78
- }
79
- window.addEventListener('message', onMessage)
80
- return () => {
81
- window.removeEventListener('message', onMessage)
82
- }
83
- }, [onFail, onSuccess])
84
-
85
- const idpButtons = config.enterpriseConnectionObjs.map((i) => {
86
- if (i.protocol === Protocol.OIDC) {
87
- const configItem = i.config as OIDCConnectionConfig
88
- const state = shortid.generate()
89
-
90
- const query = qs.stringify({
91
- client_id: configItem.clientId,
92
- redirect_uri: configItem.redirectUri,
93
- scope: configItem.scopes,
94
- response_type: configItem.responseType,
95
- state,
96
- nonce: shortid.generate(),
97
- })
98
- const url = `${configItem.authorizationEdpoint}?${query}`
99
-
100
- return (
101
- <Button
102
- key={i.identifier}
103
- className="authing-guard-third-login-btn"
104
- block
105
- size="large"
106
- icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
107
- onClick={async () => {
108
- await requestClient.post(
109
- '/api/v2/connections/oidc/start-interaction',
110
- {
111
- state,
112
- protocol: i.protocol,
113
- userPoolId,
114
- appId,
115
- referer: window.location.href,
116
- connection: { providerIentifier: i.identifier },
117
- }
118
- )
119
- popupCenter(url)
120
- }}
121
- >
122
- {t('login.loginBy', {
123
- name: i.displayName,
124
- })}
125
- </Button>
126
- )
127
- } else if (i.protocol === Protocol.SAML) {
128
- const config = i.config as ISamlConnectionConfig
129
- return (
130
- <Button
131
- key={i.identifier}
132
- className="authing-guard-third-login-btn"
133
- block
134
- size="large"
135
- icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
136
- onClick={async () => {
137
- popupCenter(config.samlRequest!)
138
- }}
139
- >
140
- {t('login.loginBy', {
141
- name: i.displayName,
142
- })}
143
- </Button>
144
- )
145
- } else if (i.protocol === Protocol.CAS) {
146
- const config = i.config as ICasConnectionConfig
147
-
148
- return (
149
- <Button
150
- key={i.identifier}
151
- className="authing-guard-third-login-btn"
152
- block
153
- size="large"
154
- icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
155
- onClick={async () => {
156
- popupCenter(config.casConnectionLoginUrl!)
157
- }}
158
- >
159
- {t('login.loginBy', {
160
- name: i.displayName,
161
- })}
162
- </Button>
163
- )
164
- } else if (i.protocol === Protocol.OAUTH) {
165
- const config = i.config as IOAuthConnectionConfig
166
-
167
- return (
168
- <Button
169
- key={i.identifier}
170
- className="authing-guard-third-login-btn"
171
- block
172
- size="large"
173
- icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
174
- onClick={async () => {
175
- popupCenter(config.authUrl!)
176
- }}
177
- >
178
- {t('login.loginBy', {
179
- name: i.displayName,
180
- })}
181
- </Button>
182
- )
183
- } else if (i.protocol === Protocol.AZURE_AD) {
184
- const configItem = i.config as IAzureAdConnectionConfig
185
- return (
186
- <Button
187
- key={i.identifier}
188
- className="authing-guard-third-login-btn"
189
- block
190
- size="large"
191
- icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
192
- onClick={async () => {
193
- popupCenter(configItem.authorizationUrl)
194
- }}
195
- >
196
- {t('login.loginBy', {
197
- name: i.displayName,
198
- })}
199
- </Button>
200
- )
201
- } else {
202
- return null
203
- }
204
- })
205
-
206
- const socialLoginButtons = config.socialConnectionObjs
207
- .filter((item) =>
208
- isWechatBrowser()
209
- ? item.provider === SocialConnectionProvider.WECHATMP
210
- : item.provider !== SocialConnectionProvider.WECHATMP
211
- )
212
- .map((item) => {
213
- const iconType = `authing-${item.provider.replace(/:/g, '-')}`
214
-
215
- const authorization_params: Record<string, any> = {}
216
- if (item.provider === SocialConnectionProvider.BAIDU) {
217
- authorization_params.display = screenSize
218
- }
219
-
220
- const onLogin = () => {
221
- authClient.social.authorize(item.provider, {
222
- onSuccess(user) {
223
- onSuccess(user)
224
- },
225
- onError(code, msg) {
226
- try {
227
- const parsedMsg = JSON.parse(msg)
228
- const { code: authingCode } = parsedMsg
229
- if ([OTP_MFA_CODE, APP_MFA_CODE].includes(authingCode)) {
230
- onFail(parsedMsg)
231
- return
232
- }
233
- } catch (e) {
234
- // do nothing...
235
- }
236
-
237
- message.error(msg)
238
- },
239
- authorization_params,
240
- })
241
- }
242
-
243
- return noForm ? (
244
- <Button
245
- key={item.provider}
246
- block
247
- size="large"
248
- className="authing-guard-third-login-btn"
249
- icon={
250
- <IconFont
251
- type={iconType}
252
- style={{ fontSize: 20, marginRight: 8 }}
253
- />
254
- }
255
- onClick={onLogin}
256
- >
257
- {item.tooltip?.[i18n.language as Lang] || item.name}
258
- </Button>
259
- ) : (
260
- <Tooltip
261
- key={item.provider}
262
- title={item.tooltip?.[i18n.language as Lang] || item.name}
263
- >
264
- <div className="authing-social-login-item" onClick={onLogin}>
265
- <IconFont type={iconType} />
266
- </div>
267
- </Tooltip>
268
- )
269
- })
270
-
271
- const idp =
272
- config.enterpriseConnectionObjs.length > 0 ? (
273
- <>
274
- {!noForm && <div className="authing-social-login-title">OR</div>}
275
- <Space
276
- size={12}
277
- className="authing-guard-full-width-space"
278
- direction="vertical"
279
- >
280
- {idpButtons}
281
- </Space>
282
- </>
283
- ) : null
284
-
285
- const socialLogin =
286
- socialLoginButtons.length > 0 && noForm ? (
287
- <Space
288
- size={12}
289
- className="authing-guard-full-width-space"
290
- direction="vertical"
291
- >
292
- {socialLoginButtons}
293
- </Space>
294
- ) : (
295
- socialLoginButtons.length > 0 && (
296
- <>
297
- <div className="authing-social-login-title">
298
- {t('login.thridAccLogin')}
299
- </div>
300
- <div className="authing-social-login-list">{socialLoginButtons}</div>
301
- </>
302
- )
303
- )
304
-
305
- return (
306
- <>
307
- {!noForm && (
308
- <div
309
- style={{
310
- flex: 1,
311
- minHeight: 26,
312
- }}
313
- ></div>
314
- )}
315
- <Space
316
- size={12}
317
- direction="vertical"
318
- className="authing-guard-full-width-space"
319
- >
320
- {idp}
321
- {socialLogin}
322
- </Space>
323
- </>
324
- )
325
- }