@authing/react-ui-components 3.0.2-beta.9 → 3.1.1-rc.6
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/.eslintignore +6 -0
- package/.eslintrc.js +7 -0
- package/.prettierrc +5 -0
- package/.vscode/settings.json +31 -0
- package/LICENSE +21 -0
- package/config/antdReplacer.js +51 -0
- package/config/env.js +106 -0
- package/config/getHttpsConfig.js +66 -0
- package/config/jest/cssTransform.js +14 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/modules.js +134 -0
- package/config/paths.js +71 -0
- package/config/pnpTs.js +35 -0
- package/config/webpack.config.js +857 -0
- package/config/webpackDevServer.config.js +130 -0
- package/lib/index.d.ts +211 -1669
- package/lib/index.min.css +1 -2
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.LICENSE.txt +0 -32
- package/package.json +18 -42
- package/public/favicon.ico +0 -0
- package/public/index.html +43 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +25 -0
- package/public/robots.txt +3 -0
- package/scripts/build.js +212 -0
- package/scripts/lib.js +200 -0
- package/scripts/start.js +166 -0
- package/scripts/test.js +53 -0
- package/src/common/AuthingDropdown/index.tsx +52 -0
- package/src/common/AuthingDropdown/style.less +43 -0
- package/src/common/AuthingTabs/index.tsx +98 -0
- package/src/common/AuthingTabs/style.less +135 -0
- package/src/common/CopyAbleText/index.tsx +54 -0
- package/src/common/CopyAbleText/style.less +13 -0
- package/src/common/VerifyCodeInput/index.tsx +76 -0
- package/src/common/VerifyCodeInput/style.less +24 -0
- package/src/components/AuthingGuard/AppMFALayout/index.tsx +74 -0
- package/src/components/AuthingGuard/AppMFALayout/style.less +12 -0
- package/src/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +29 -0
- package/src/components/AuthingGuard/CompleteUserInfoLayout/style.less +8 -0
- package/src/components/AuthingGuard/Forms/ADLoginForm/index.tsx +117 -0
- package/src/components/AuthingGuard/Forms/Agreements/index.tsx +81 -0
- package/src/components/AuthingGuard/Forms/Agreements/style.less +44 -0
- package/src/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +139 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +86 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +116 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +40 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +181 -0
- package/src/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +161 -0
- package/src/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +76 -0
- package/src/components/AuthingGuard/Forms/LoginFormFooter/style.less +6 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +86 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +53 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +65 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +20 -0
- package/src/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +105 -0
- package/src/components/AuthingGuard/Forms/MfaVerifyForm/style.less +12 -0
- package/src/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +261 -0
- package/src/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +133 -0
- package/src/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +202 -0
- package/src/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +61 -0
- package/src/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +14 -0
- package/src/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +56 -0
- package/src/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +21 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +86 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +127 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +141 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +51 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +96 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/style.less +3 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +88 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +50 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/style.less +26 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +86 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +113 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +40 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +3 -0
- package/src/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +325 -0
- package/src/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +75 -0
- package/src/components/AuthingGuard/Forms/UploadImage/index.tsx +70 -0
- package/src/components/AuthingGuard/Forms/index.ts +13 -0
- package/src/components/AuthingGuard/GuardLayout/index.tsx +488 -0
- package/src/components/AuthingGuard/GuardLayout/style.less +111 -0
- package/src/components/AuthingGuard/Header/index.tsx +28 -0
- package/src/components/AuthingGuard/Header/style.less +71 -0
- package/src/components/AuthingGuard/IconFont/iconfont.js +74 -0
- package/src/components/AuthingGuard/IconFont/index.tsx +19 -0
- package/src/components/AuthingGuard/IconFont/style.less +6 -0
- package/src/components/AuthingGuard/IconFont/svg.js +2 -0
- package/src/components/AuthingGuard/LoginLayout/index.tsx +205 -0
- package/src/components/AuthingGuard/LoginLayout/style.less +0 -0
- package/src/components/AuthingGuard/MfaLayout/Steps.ts +4 -0
- package/src/components/AuthingGuard/MfaLayout/index.tsx +49 -0
- package/src/components/AuthingGuard/MfaLayout/style.less +3 -0
- package/src/components/AuthingGuard/RegisterLayout/index.tsx +89 -0
- package/src/components/AuthingGuard/RegisterLayout/style.less +0 -0
- package/src/components/AuthingGuard/ResetPwdLayout/index.tsx +20 -0
- package/src/components/AuthingGuard/ToggleLang/index.tsx +51 -0
- package/src/components/AuthingGuard/api/appConfig.ts +154 -0
- package/src/components/AuthingGuard/api/http.ts +88 -0
- package/src/components/AuthingGuard/api/index.ts +3 -0
- package/src/components/AuthingGuard/api/sso.ts +29 -0
- package/src/components/AuthingGuard/api/userPoolConfig.ts +112 -0
- package/src/components/AuthingGuard/constants.ts +107 -0
- package/src/components/AuthingGuard/hooks/index.tsx +70 -0
- package/src/components/AuthingGuard/hooks/useScreenSize.tsx +68 -0
- package/src/components/AuthingGuard/index.tsx +134 -0
- package/src/components/AuthingGuard/locales/en/common.json +185 -0
- package/src/components/AuthingGuard/locales/en/index.ts +6 -0
- package/src/components/AuthingGuard/locales/en/login.json +94 -0
- package/src/components/AuthingGuard/locales/en/map.json +4 -0
- package/src/components/AuthingGuard/locales/en/user.json +81 -0
- package/src/components/AuthingGuard/locales/index.ts +45 -0
- package/src/components/AuthingGuard/locales/zh/common.json +185 -0
- package/src/components/AuthingGuard/locales/zh/index.ts +6 -0
- package/src/components/AuthingGuard/locales/zh/login.json +94 -0
- package/src/components/AuthingGuard/locales/zh/map.json +4 -0
- package/src/components/AuthingGuard/locales/zh/user.json +81 -0
- package/src/components/AuthingGuard/style.less +108 -0
- package/src/components/AuthingGuard/types/Forms.ts +95 -0
- package/src/components/AuthingGuard/types/GuardConfig.ts +424 -0
- package/src/components/AuthingGuard/types/GuardState.ts +7 -0
- package/src/components/AuthingGuard/types/Locales.ts +12 -0
- package/src/components/AuthingGuard/types/index.ts +4 -0
- package/src/components/index.ts +7 -0
- package/src/context/base.tsx +28 -0
- package/src/context/global/context.tsx +39 -0
- package/src/context/global/reducer.tsx +56 -0
- package/src/index.tsx +142 -0
- package/src/logo.svg +7 -0
- package/src/react-app-env.d.ts +71 -0
- package/src/reportWebVitals.ts +15 -0
- package/src/setupTests.ts +5 -0
- package/src/utils/clipboard.ts +27 -0
- package/src/utils/index.ts +180 -0
- package/src/utils/popupCenter.ts +48 -0
- package/tsconfig.json +24 -0
- package/lib/static/media/loading.4a67a5f3.svg +0 -29
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { requestClient } from './http'
|
|
2
|
+
import {
|
|
3
|
+
Lang,
|
|
4
|
+
LoginMethods,
|
|
5
|
+
Protocol,
|
|
6
|
+
} from '../../../components/AuthingGuard/types'
|
|
7
|
+
import {
|
|
8
|
+
IAzureAdConnectionConfig,
|
|
9
|
+
ICasConnectionConfig,
|
|
10
|
+
ISamlConnectionConfig,
|
|
11
|
+
OIDCConnectionConfig,
|
|
12
|
+
SocialConnectionItem,
|
|
13
|
+
} from './userPoolConfig'
|
|
14
|
+
import { i18n } from '../locales'
|
|
15
|
+
|
|
16
|
+
export enum ApplicationMfaType {
|
|
17
|
+
SMS = 'SMS',
|
|
18
|
+
EMAIL = 'EMAIL',
|
|
19
|
+
// OTP = 'OTP',
|
|
20
|
+
// FACE = 'FACE',
|
|
21
|
+
// FINGERPRINT = 'FINGERPRINT',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const ApplicationMfaTypeLabel: () => Record<
|
|
25
|
+
ApplicationMfaType,
|
|
26
|
+
string
|
|
27
|
+
> = () => ({
|
|
28
|
+
[ApplicationMfaType.SMS]: i18n.t('common.SMS'),
|
|
29
|
+
[ApplicationMfaType.EMAIL]: i18n.t('common.EmailVerification'),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export type QrcodeTabsSettings = Record<
|
|
33
|
+
LoginMethods,
|
|
34
|
+
Array<{
|
|
35
|
+
id: string
|
|
36
|
+
title: string
|
|
37
|
+
isDefault?: boolean
|
|
38
|
+
}>
|
|
39
|
+
>
|
|
40
|
+
|
|
41
|
+
export interface OidcClientMetadata {
|
|
42
|
+
grant_types: string[]
|
|
43
|
+
client_id: string
|
|
44
|
+
redirect_uris: string[]
|
|
45
|
+
scope: string
|
|
46
|
+
response_types: ResponseType[]
|
|
47
|
+
}
|
|
48
|
+
export interface InternalExtendsField {
|
|
49
|
+
type: 'internal'
|
|
50
|
+
name: string
|
|
51
|
+
label: string
|
|
52
|
+
inputType: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface UserExtendsField {
|
|
56
|
+
type: 'user'
|
|
57
|
+
id: string
|
|
58
|
+
name: string
|
|
59
|
+
label: string
|
|
60
|
+
inputType: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type ExtendsField = InternalExtendsField | UserExtendsField
|
|
64
|
+
|
|
65
|
+
export interface ApplicationPasswordTabConfig {
|
|
66
|
+
enabledLoginMethods?: PasswordLoginMethods[]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface Agreement {
|
|
70
|
+
id: number
|
|
71
|
+
title: string
|
|
72
|
+
required: boolean
|
|
73
|
+
lang: Lang
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type PasswordLoginMethods =
|
|
77
|
+
| 'username-password'
|
|
78
|
+
| 'email-password'
|
|
79
|
+
| 'phone-password'
|
|
80
|
+
|
|
81
|
+
export interface ApplicationConfig {
|
|
82
|
+
id: string
|
|
83
|
+
cdnBase: string
|
|
84
|
+
userPoolId: string
|
|
85
|
+
rootUserPoolId: string
|
|
86
|
+
publicKey: string
|
|
87
|
+
// 登录框自定义 css 代码
|
|
88
|
+
css: string
|
|
89
|
+
name: string
|
|
90
|
+
logo: string
|
|
91
|
+
description?: string
|
|
92
|
+
redirectUris: string[]
|
|
93
|
+
registerDisabled: boolean
|
|
94
|
+
registerTabs: {
|
|
95
|
+
list: string[]
|
|
96
|
+
default: string
|
|
97
|
+
title: { [x: string]: string }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
qrcodeTabsSettings: QrcodeTabsSettings
|
|
101
|
+
|
|
102
|
+
loginTabs: {
|
|
103
|
+
list: string[]
|
|
104
|
+
default: string
|
|
105
|
+
defaultV2?: string
|
|
106
|
+
title: { [x: string]: string }
|
|
107
|
+
}
|
|
108
|
+
socialConnections: SocialConnectionItem[]
|
|
109
|
+
|
|
110
|
+
extendsFieldsEnabled: boolean
|
|
111
|
+
extendsFields: ExtendsField[]
|
|
112
|
+
|
|
113
|
+
identityProviders: {
|
|
114
|
+
identifier: string
|
|
115
|
+
protocol: Protocol
|
|
116
|
+
displayName: string
|
|
117
|
+
logo: string
|
|
118
|
+
config:
|
|
119
|
+
| ISamlConnectionConfig
|
|
120
|
+
| OIDCConnectionConfig
|
|
121
|
+
| ICasConnectionConfig
|
|
122
|
+
| IAzureAdConnectionConfig
|
|
123
|
+
}[]
|
|
124
|
+
|
|
125
|
+
ssoPageComponentDisplay: {
|
|
126
|
+
autoRegisterThenLoginHintInfo: boolean
|
|
127
|
+
forgetPasswordBtn: boolean
|
|
128
|
+
idpBtns: boolean
|
|
129
|
+
loginBtn: boolean
|
|
130
|
+
loginByPhoneCodeTab: boolean
|
|
131
|
+
loginByUserPasswordTab: boolean
|
|
132
|
+
loginMethodNav: boolean
|
|
133
|
+
phoneCodeInput: boolean
|
|
134
|
+
registerBtn: boolean
|
|
135
|
+
registerByEmailTab: boolean
|
|
136
|
+
registerByPhoneTab: boolean
|
|
137
|
+
registerMethodNav: boolean
|
|
138
|
+
socialLoginBtns: boolean
|
|
139
|
+
userPasswordInput: boolean
|
|
140
|
+
wxMpScanTab: boolean
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
protocol: Protocol
|
|
144
|
+
oidcConfig: OidcClientMetadata
|
|
145
|
+
passwordTabConfig: ApplicationPasswordTabConfig
|
|
146
|
+
|
|
147
|
+
agreementEnabled: boolean
|
|
148
|
+
agreements: Agreement[]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const fetchAppConfig = (appId: string) =>
|
|
152
|
+
requestClient.get<ApplicationConfig>(
|
|
153
|
+
`/api/v2/applications/${appId}/public-config`
|
|
154
|
+
)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import qs from 'qs'
|
|
2
|
+
import { i18n } from '../locales'
|
|
3
|
+
|
|
4
|
+
export const requestClient = async (...rest: Parameters<typeof fetch>) => {
|
|
5
|
+
const res = await fetch(...rest)
|
|
6
|
+
return res.json()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AuthingResponse<T = any> {
|
|
10
|
+
code: number
|
|
11
|
+
message?: string
|
|
12
|
+
data?: T
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
requestClient.get = async <T>(
|
|
16
|
+
path: string,
|
|
17
|
+
query: Record<string, any> = {},
|
|
18
|
+
init?: RequestInit
|
|
19
|
+
): Promise<AuthingResponse<T>> => {
|
|
20
|
+
const headers: Record<string, any> = {
|
|
21
|
+
...init?.headers,
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
[requestClient.langHeader]: i18n.language,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (requestClient.tenantId !== '')
|
|
27
|
+
headers[requestClient.tenantHeader] = requestClient.tenantId
|
|
28
|
+
|
|
29
|
+
const res = await fetch(
|
|
30
|
+
`${requestClient.baseUrl}${path}${qs.stringify(query, {
|
|
31
|
+
addQueryPrefix: true,
|
|
32
|
+
})}`,
|
|
33
|
+
{
|
|
34
|
+
...init,
|
|
35
|
+
credentials: 'include',
|
|
36
|
+
headers,
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return res.json()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
requestClient.post = async <T>(
|
|
44
|
+
path: string,
|
|
45
|
+
data: any,
|
|
46
|
+
config?: {
|
|
47
|
+
headers: any
|
|
48
|
+
}
|
|
49
|
+
): Promise<AuthingResponse<T>> => {
|
|
50
|
+
const headers: Record<string, any> = {
|
|
51
|
+
...config?.headers,
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
[requestClient.langHeader]: i18n.language,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (requestClient.tenantId !== '')
|
|
57
|
+
headers[requestClient.tenantHeader] = requestClient.tenantId
|
|
58
|
+
|
|
59
|
+
const res = await fetch(`${requestClient.baseUrl}${path}`, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
body: JSON.stringify(data),
|
|
62
|
+
credentials: 'include',
|
|
63
|
+
headers: headers,
|
|
64
|
+
})
|
|
65
|
+
return res.json()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
requestClient.baseUrl = ''
|
|
69
|
+
requestClient.setBaseUrl = (base: string) => {
|
|
70
|
+
requestClient.baseUrl = base.replace(/\/$/, '')
|
|
71
|
+
}
|
|
72
|
+
const DEFAULT_LANG_HEADER = 'x-authing-lang'
|
|
73
|
+
const DEFAULT_TENANT_HEADER = 'x-authing-app-tenant-idåå'
|
|
74
|
+
requestClient.langHeader = DEFAULT_LANG_HEADER
|
|
75
|
+
requestClient.tenantHeader = DEFAULT_TENANT_HEADER
|
|
76
|
+
requestClient.tenantId = ''
|
|
77
|
+
|
|
78
|
+
requestClient.setLangHeader = (key: string | undefined) => {
|
|
79
|
+
requestClient.langHeader = key || DEFAULT_LANG_HEADER
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
requestClient.setTenantHeader = (key: string | undefined) => {
|
|
83
|
+
requestClient.tenantHeader = key || DEFAULT_LANG_HEADER
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
requestClient.setTenantId = (tenantId: string) => {
|
|
87
|
+
requestClient.tenantId = tenantId
|
|
88
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { User } from '../types'
|
|
2
|
+
import { requestClient } from './http'
|
|
3
|
+
|
|
4
|
+
export interface SessionData {
|
|
5
|
+
session: null | {
|
|
6
|
+
_id: string
|
|
7
|
+
cookie: {
|
|
8
|
+
originalMaxAge: number
|
|
9
|
+
expires: Date
|
|
10
|
+
secure: boolean
|
|
11
|
+
httpOnly: boolean
|
|
12
|
+
path: string
|
|
13
|
+
sameSite: string
|
|
14
|
+
}
|
|
15
|
+
appId?: string
|
|
16
|
+
type: string
|
|
17
|
+
userId: string
|
|
18
|
+
}
|
|
19
|
+
userInfo?: User
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const trackSession = () =>
|
|
23
|
+
requestClient.get<SessionData>(
|
|
24
|
+
`/cas/session`,
|
|
25
|
+
{},
|
|
26
|
+
{
|
|
27
|
+
credentials: 'include',
|
|
28
|
+
}
|
|
29
|
+
)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Lang, Protocol } from '../../../components/AuthingGuard/types'
|
|
2
|
+
import { SocialConnectionProvider } from 'authing-js-sdk'
|
|
3
|
+
|
|
4
|
+
export interface OIDCConnectionConfig {
|
|
5
|
+
issuerUrl: string
|
|
6
|
+
authorizationEdpoint: string
|
|
7
|
+
responseType: string
|
|
8
|
+
mode: OIDCConnectionMode
|
|
9
|
+
clientId: string
|
|
10
|
+
clientSecret: string
|
|
11
|
+
scopes: string
|
|
12
|
+
redirectUri: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IOAuthConnectionConfig {
|
|
16
|
+
authEndPoint: string
|
|
17
|
+
tokenEndPoint: string
|
|
18
|
+
scope: string
|
|
19
|
+
clientId: string
|
|
20
|
+
clientSecret: string
|
|
21
|
+
authUrlTemplate: string
|
|
22
|
+
codeToTokenScript: string
|
|
23
|
+
tokenToUserInfoScript: string
|
|
24
|
+
tokenToUserInfoScriptFuncId: string
|
|
25
|
+
codeToTokenScriptFuncId: string
|
|
26
|
+
authUrl?: string // 根据模板拼接出来的授权 url
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IAzureAdConnectionConfig {
|
|
30
|
+
microsoftAzureAdDomain: string
|
|
31
|
+
clientId: string
|
|
32
|
+
syncUserProfileOnLogin: string
|
|
33
|
+
emailVerifiedDefault: boolean
|
|
34
|
+
authorizationUrl: string
|
|
35
|
+
callbackUrl: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export enum OIDCConnectionMode {
|
|
39
|
+
FRONT_CHANNEL = 'FRONT_CHANNEL',
|
|
40
|
+
BACK_CHANNEL = 'BACK_CHANNEL',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ISamlConnectionConfig {
|
|
44
|
+
signInEndPoint: string
|
|
45
|
+
samlRequest?: string
|
|
46
|
+
|
|
47
|
+
// saml assertion 验签公钥
|
|
48
|
+
|
|
49
|
+
samlIdpCert: string
|
|
50
|
+
|
|
51
|
+
// saml request 验签公钥
|
|
52
|
+
|
|
53
|
+
samlSpCert: string
|
|
54
|
+
|
|
55
|
+
// saml request 签名私钥
|
|
56
|
+
|
|
57
|
+
samlSpKey: string
|
|
58
|
+
|
|
59
|
+
signOutEndPoint: string
|
|
60
|
+
|
|
61
|
+
signSamlRequest: boolean
|
|
62
|
+
|
|
63
|
+
signatureAlgorithm: string
|
|
64
|
+
|
|
65
|
+
digestAlgorithm: string
|
|
66
|
+
|
|
67
|
+
protocolBinding: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ICasConnectionConfig {
|
|
71
|
+
casConnectionLoginUrl: string
|
|
72
|
+
}
|
|
73
|
+
export interface SocialConnectionItem {
|
|
74
|
+
name: string
|
|
75
|
+
displayName: string
|
|
76
|
+
logo: string
|
|
77
|
+
description: string
|
|
78
|
+
identifier: string
|
|
79
|
+
provider: SocialConnectionProvider
|
|
80
|
+
authorizationUrl: string
|
|
81
|
+
tooltip: Record<Lang, string>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface EnterpriseConnectionItem {
|
|
85
|
+
id: string
|
|
86
|
+
createdAt: Date
|
|
87
|
+
updatedAt: Date
|
|
88
|
+
userPoolId: string
|
|
89
|
+
protocol: Protocol
|
|
90
|
+
identifier: string
|
|
91
|
+
displayName: string
|
|
92
|
+
logo: string
|
|
93
|
+
enabled: boolean
|
|
94
|
+
config:
|
|
95
|
+
| OIDCConnectionConfig
|
|
96
|
+
| ISamlConnectionConfig
|
|
97
|
+
| ICasConnectionConfig
|
|
98
|
+
| IAzureAdConnectionConfig
|
|
99
|
+
| IOAuthConnectionConfig
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface UserPoolConfig {
|
|
103
|
+
name: string
|
|
104
|
+
logo: string
|
|
105
|
+
socialConnections: SocialConnectionItem[]
|
|
106
|
+
enterpriseConnections: EnterpriseConnectionItem[]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// export const fetchUserPoolConfig = (userPoolId: string) =>
|
|
110
|
+
// requestClient.get<UserPoolConfig>(
|
|
111
|
+
// `/api/v2/userpools/${userPoolId}/public-config`
|
|
112
|
+
// )
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GuardMode,
|
|
3
|
+
UserConfig,
|
|
4
|
+
GuardScenes,
|
|
5
|
+
LoginMethods,
|
|
6
|
+
RegisterMethods,
|
|
7
|
+
LocalesConfig,
|
|
8
|
+
} from '../../components/AuthingGuard/types'
|
|
9
|
+
import { i18n } from './locales'
|
|
10
|
+
|
|
11
|
+
// 个人版 OTP MFA 的 error code
|
|
12
|
+
export const OTP_MFA_CODE = 1635
|
|
13
|
+
// 企业版手机和短信验证吗 MFA 的 error code
|
|
14
|
+
export const APP_MFA_CODE = 1636
|
|
15
|
+
|
|
16
|
+
// 需要验证吗
|
|
17
|
+
export const NEED_CAPTCHA = 2000
|
|
18
|
+
|
|
19
|
+
export const LOGIN_METHODS_MAP = () => ({
|
|
20
|
+
[LoginMethods.Password]: i18n.t('login.pwdLogin'),
|
|
21
|
+
[LoginMethods.PhoneCode]: i18n.t('login.verifyCodeLogin'),
|
|
22
|
+
[LoginMethods.AppQr]: i18n.t('login.appScanLogin'),
|
|
23
|
+
[LoginMethods.WxMinQr]: i18n.t('login.scanLogin'),
|
|
24
|
+
[LoginMethods.LDAP]: i18n.t('login.ldapLogin'),
|
|
25
|
+
[LoginMethods.AD]: i18n.t('login.adLogin'),
|
|
26
|
+
[LoginMethods.WechatMpQrcode]: i18n.t('login.wechatmpQrcode'),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const REGISTER_METHODS_MAP = () => ({
|
|
30
|
+
[RegisterMethods.Email]: i18n.t('login.emailRegister'),
|
|
31
|
+
[RegisterMethods.Phone]: i18n.t('login.phoneRegister'),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// 某些社会化登录会在 tabs 中显示,或者无法在 Guard 中使用,所以底部不显示了
|
|
35
|
+
export const HIDE_SOCIALS = [
|
|
36
|
+
'wechat:miniprogram:app-launch',
|
|
37
|
+
'wechat:miniprogram:qrconnect',
|
|
38
|
+
'wechat:webpage-authorization',
|
|
39
|
+
'wechat:miniprogram:default',
|
|
40
|
+
'wechatwork:addressbook',
|
|
41
|
+
'wechat:mobile',
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
// 企业版 MFA 支持的方式
|
|
45
|
+
export enum ApplicationMfaType {
|
|
46
|
+
SMS = 'SMS',
|
|
47
|
+
EMAIL = 'EMAIL',
|
|
48
|
+
// OTP = 'OTP',
|
|
49
|
+
// FACE = 'FACE',
|
|
50
|
+
// FINGERPRINT = 'FINGERPRINT',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const defaultGuardConfig: Partial<UserConfig> = {
|
|
54
|
+
isSSO: false,
|
|
55
|
+
title: 'Authing',
|
|
56
|
+
text: {
|
|
57
|
+
loginTabs: LOGIN_METHODS_MAP(),
|
|
58
|
+
loginBtn: {
|
|
59
|
+
normal: '登录',
|
|
60
|
+
loading: '登录',
|
|
61
|
+
},
|
|
62
|
+
registerBtn: {
|
|
63
|
+
normal: '注册',
|
|
64
|
+
loading: '注册',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
escCloseable: true,
|
|
68
|
+
autoRegister: false,
|
|
69
|
+
clickCloseable: true,
|
|
70
|
+
mode: GuardMode.Normal,
|
|
71
|
+
disableRegister: false,
|
|
72
|
+
disableResetPwd: false,
|
|
73
|
+
defaultScenes: GuardScenes.Login,
|
|
74
|
+
appHost: 'https://core.authing.cn',
|
|
75
|
+
defaultLoginMethod: LoginMethods.Password,
|
|
76
|
+
defaultRegisterMethod: RegisterMethods.Email,
|
|
77
|
+
loginMethods: [LoginMethods.Password, LoginMethods.PhoneCode],
|
|
78
|
+
registerMethods: [RegisterMethods.Email, RegisterMethods.Phone],
|
|
79
|
+
logo:
|
|
80
|
+
'https://files.authing.co/user-contents/photos/0a4c99ff-b8ce-4030-aaaf-584c807cb21c.png',
|
|
81
|
+
passwordLoginMethods: [
|
|
82
|
+
'email-password',
|
|
83
|
+
'username-password',
|
|
84
|
+
'phone-password',
|
|
85
|
+
],
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const defaultLocalesConfig: LocalesConfig = {
|
|
89
|
+
defaultLang: 'zh-CN',
|
|
90
|
+
isShowChange: false,
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const defaultHeaders: {
|
|
94
|
+
'userpool-id': string
|
|
95
|
+
'app-id': string
|
|
96
|
+
'sdk-version': string
|
|
97
|
+
'request-from': string
|
|
98
|
+
'tenant-id': string
|
|
99
|
+
lang: string
|
|
100
|
+
} = {
|
|
101
|
+
'userpool-id': 'x-authing-userpool-id',
|
|
102
|
+
'app-id': 'x-authing-app-id',
|
|
103
|
+
'tenant-id': 'x-authing-app-tenant-id',
|
|
104
|
+
'request-from': 'x-authing-request-from',
|
|
105
|
+
'sdk-version': 'x-authing-sdk-version',
|
|
106
|
+
lang: 'x-authing-lang',
|
|
107
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthenticationClient,
|
|
3
|
+
AuthenticationClientOptions,
|
|
4
|
+
} from 'authing-js-sdk'
|
|
5
|
+
import { defaultGuardConfig } from '../constants'
|
|
6
|
+
|
|
7
|
+
let authClient: AuthenticationClient | null = null
|
|
8
|
+
|
|
9
|
+
export interface AuthClientConfig extends AuthenticationClientOptions {
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated 使用 appHost
|
|
12
|
+
*/
|
|
13
|
+
appDomain?: string
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated 无需传入
|
|
16
|
+
*/
|
|
17
|
+
isSSO?: boolean
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated 使用 appHost
|
|
20
|
+
*/
|
|
21
|
+
host?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const initAuthClient = (config: AuthClientConfig) => {
|
|
25
|
+
if (authClient) {
|
|
26
|
+
return authClient
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { appHost, appDomain, host } = config
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 兼容之前的参数
|
|
33
|
+
*/
|
|
34
|
+
let realHost
|
|
35
|
+
if (appHost) {
|
|
36
|
+
realHost = appHost
|
|
37
|
+
} else if (appDomain) {
|
|
38
|
+
const parsedUrl = new URL(host || defaultGuardConfig.appHost!)
|
|
39
|
+
realHost = `${parsedUrl.protocol}//${appDomain}${
|
|
40
|
+
parsedUrl.port ? ':' + parsedUrl.port : ''
|
|
41
|
+
}`
|
|
42
|
+
} else if (host) {
|
|
43
|
+
realHost = host
|
|
44
|
+
} else {
|
|
45
|
+
realHost = defaultGuardConfig.appHost
|
|
46
|
+
}
|
|
47
|
+
config.appHost = realHost!
|
|
48
|
+
|
|
49
|
+
authClient = new AuthenticationClient(config)
|
|
50
|
+
|
|
51
|
+
return authClient
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const useAuthing = (config?: AuthClientConfig) => {
|
|
55
|
+
return { authClient: getAuthClient(config) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const getAuthClient = (config?: AuthClientConfig) => {
|
|
59
|
+
if (!authClient && !config) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
'Please `initAuthClient` first or pass `AuthClientConfig` to useAuthing.'
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (config) {
|
|
66
|
+
initAuthClient(config)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return authClient
|
|
70
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
// import { inRange, debounce } from 'lodash'
|
|
3
|
+
|
|
4
|
+
function debounce(fn: Function, delay: number, immediate = true) {
|
|
5
|
+
let timer: any
|
|
6
|
+
|
|
7
|
+
return function (this: any) {
|
|
8
|
+
let context = this
|
|
9
|
+
let args = arguments
|
|
10
|
+
timer && clearTimeout(timer)
|
|
11
|
+
|
|
12
|
+
if (immediate && !timer) {
|
|
13
|
+
fn.apply(context, args)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
timer = setTimeout(function () {
|
|
17
|
+
fn.apply(context, args)
|
|
18
|
+
}, delay)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function inRange(n: number, start: number, end?: number): boolean {
|
|
23
|
+
if (end || end === 0) {
|
|
24
|
+
return n >= start && n <= end
|
|
25
|
+
}
|
|
26
|
+
return n >= start
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export enum ScreenSize {
|
|
30
|
+
Mobile = 'mobile',
|
|
31
|
+
Desktop = 'desktop',
|
|
32
|
+
}
|
|
33
|
+
export const SCREEN_SIZE_RANG: {
|
|
34
|
+
size: ScreenSize
|
|
35
|
+
range: [number, number]
|
|
36
|
+
}[] = [
|
|
37
|
+
{
|
|
38
|
+
size: ScreenSize.Mobile,
|
|
39
|
+
range: [0, 719],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
size: ScreenSize.Desktop,
|
|
43
|
+
range: [720, Infinity],
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
export const getScreenSize = () => {
|
|
48
|
+
const viewportWidth = document.body.clientWidth
|
|
49
|
+
return (
|
|
50
|
+
SCREEN_SIZE_RANG.find((item) => inRange(viewportWidth, ...item.range))
|
|
51
|
+
?.size ?? ScreenSize.Desktop
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const useScreenSize = () => {
|
|
56
|
+
const [screenSize, setScreenSize] = useState(getScreenSize)
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const onResize = debounce(() => {
|
|
60
|
+
setScreenSize(getScreenSize())
|
|
61
|
+
}, 200)
|
|
62
|
+
window.addEventListener('resize', onResize)
|
|
63
|
+
|
|
64
|
+
return () => window.removeEventListener('resize', onResize)
|
|
65
|
+
}, [])
|
|
66
|
+
|
|
67
|
+
return [screenSize]
|
|
68
|
+
}
|