@springmicro/auth 0.5.2 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@springmicro/auth",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -54,5 +54,5 @@
54
54
  "react-social-login-buttons": "^4.1.0",
55
55
  "uuid": "^9.0.1"
56
56
  },
57
- "gitHead": "431413a6efc5c939e85c79309967bdc6c88c9ee2"
57
+ "gitHead": "049eb0491834ffa64dd66a1d965ccd3e5751d085"
58
58
  }
@@ -49,6 +49,8 @@ export type SignUpFormState = {
49
49
  type SignUpFormProps = {
50
50
  application: Application | null;
51
51
  applicationName?: string;
52
+ CLIENT_ID: string;
53
+ CLIENT_SECRET: string;
52
54
 
53
55
  // onUpdateAccount: (account: Account) => void;
54
56
  onUpdateApplication: (application: Application | null) => void;
@@ -78,16 +80,19 @@ function SignUpForm(props: SignUpFormProps) {
78
80
  return;
79
81
  }
80
82
 
81
- ApplicationBackend.getApplication("admin", applicationName).then(
82
- (res: any) => {
83
- if (res.status === "error") {
84
- Setting.showMessage("error", res.msg);
85
- return;
86
- }
87
-
88
- onUpdateApplication(res.data);
83
+ ApplicationBackend.getApplication(
84
+ "admin",
85
+ applicationName,
86
+ props.CLIENT_ID,
87
+ props.CLIENT_SECRET
88
+ ).then((res: any) => {
89
+ if (res.status === "error") {
90
+ Setting.showMessage("error", res.msg);
91
+ return;
89
92
  }
90
- );
93
+
94
+ onUpdateApplication(res.data);
95
+ });
91
96
  };
92
97
  const getApplicationLogin = (oAuthParams: any) => {
93
98
  AuthBackend.getApplicationLogin(oAuthParams).then((res) => {
@@ -176,7 +181,15 @@ function SignUpForm(props: SignUpFormProps) {
176
181
  return application.signupItems?.map((signupItem, idx) => {
177
182
  return (
178
183
  <div key={idx}>
179
- {renderFormItem(application, signupItem, state, setState, t)}
184
+ {renderFormItem(
185
+ application,
186
+ signupItem,
187
+ state,
188
+ setState,
189
+ t,
190
+ props.CLIENT_ID,
191
+ props.CLIENT_SECRET
192
+ )}
180
193
  </div>
181
194
  );
182
195
  });
@@ -190,12 +203,16 @@ type SignUpProps = {
190
203
  applicationName: string;
191
204
  casdoorApiRoot: string;
192
205
  springmicroApiRoot?: string;
206
+ CLIENT_ID: string;
207
+ CLIENT_SECRET: string;
193
208
  };
194
209
 
195
210
  export function SignUp({
196
211
  applicationName,
197
212
  casdoorApiRoot,
198
213
  springmicroApiRoot,
214
+ CLIENT_ID,
215
+ CLIENT_SECRET,
199
216
  }: SignUpProps) {
200
217
  Setting.ROOT_URLS.casdoor = casdoorApiRoot;
201
218
  if (springmicroApiRoot) {
@@ -204,19 +221,22 @@ export function SignUp({
204
221
  const [state, setState] = React.useState<SignUpState>({ application: null });
205
222
 
206
223
  const getApplication = () => {
207
- ApplicationBackend.getApplication("admin", applicationName).then(
208
- (res: any) => {
209
- console.log(res);
210
- if (res.status === "error") {
211
- Setting.showMessage("error", res.msg);
212
- return;
213
- }
214
-
215
- setState({
216
- application: res.data,
217
- });
224
+ ApplicationBackend.getApplication(
225
+ "admin",
226
+ applicationName,
227
+ CLIENT_ID,
228
+ CLIENT_SECRET
229
+ ).then((res: any) => {
230
+ console.log(res);
231
+ if (res.status === "error") {
232
+ Setting.showMessage("error", res.msg);
233
+ return;
218
234
  }
219
- );
235
+
236
+ setState({
237
+ application: res.data,
238
+ });
239
+ });
220
240
  };
221
241
 
222
242
  React.useEffect(() => {
@@ -234,6 +254,8 @@ export function SignUp({
234
254
  application: application,
235
255
  });
236
256
  }}
257
+ CLIENT_ID={CLIENT_ID}
258
+ CLIENT_SECRET={CLIENT_SECRET}
237
259
  />
238
260
  </I18nextProvider>
239
261
  );
@@ -265,6 +287,8 @@ export function SignUpProvider({
265
287
  applicationName,
266
288
  casdoorApiRoot,
267
289
  springmicroApiRoot,
290
+ CLIENT_ID,
291
+ CLIENT_SECRET,
268
292
  children,
269
293
  }: React.PropsWithChildren<SignUpProps>) {
270
294
  const { t, i18n } = useTranslation();
@@ -279,19 +303,22 @@ export function SignUpProvider({
279
303
  React.useState<Record<string, boolean>>({});
280
304
 
281
305
  const getApplication = () => {
282
- ApplicationBackend.getApplication("admin", applicationName).then(
283
- (res: any) => {
284
- console.log(res);
285
- if (res.status === "error") {
286
- Setting.showMessage("error", res.msg);
287
- return;
288
- }
289
-
290
- setState({
291
- application: res.data,
292
- });
306
+ ApplicationBackend.getApplication(
307
+ "admin",
308
+ applicationName,
309
+ CLIENT_ID,
310
+ CLIENT_SECRET
311
+ ).then((res: any) => {
312
+ console.log(res);
313
+ if (res.status === "error") {
314
+ Setting.showMessage("error", res.msg);
315
+ return;
293
316
  }
294
- );
317
+
318
+ setState({
319
+ application: res.data,
320
+ });
321
+ });
295
322
  };
296
323
 
297
324
  const onUpdateApplication = (application: Application) => {
@@ -1,149 +1,155 @@
1
- // Copyright 2021 The Casdoor Authors. All Rights Reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import React from "react";
16
- import i18next from "i18next";
17
- import * as UserBackend from "./util/user-api";
18
- import { CaptchaModal } from "./CaptchaModal";
19
- import type { Application } from "./util/provider";
20
- import { useTranslation } from "react-i18next";
21
-
22
- type ButtonClickArgsTuple = [
23
- dest: any,
24
- type: any,
25
- applicationId: any,
26
- checkUser?: string
27
- ];
28
-
29
- export type SendCodeInputProps = {
30
- value?: any;
31
- disabled: boolean;
32
- textBefore?: string;
33
- onChange: Function;
34
- onButtonClickArgs: ButtonClickArgsTuple;
35
- application: Application;
36
- method: string;
37
- countryCode: string;
38
- };
39
-
40
- export const SendCodeInput = ({
41
- value,
42
- disabled,
43
- textBefore,
44
- onChange,
45
- onButtonClickArgs,
46
- application,
47
- method,
48
- countryCode,
49
- }: SendCodeInputProps) => {
50
- const { t } = useTranslation();
51
- const [visible, setVisible] = React.useState(false);
52
- const [buttonLeftTime, setButtonLeftTime] = React.useState(0);
53
- const [buttonLoading, setButtonLoading] = React.useState(false);
54
- const dialogRef = React.useRef<HTMLElement | null>(null);
55
-
56
- const handleCountDown = (leftTime = 60) => {
57
- let leftTimeSecond = leftTime;
58
- setButtonLeftTime(leftTimeSecond);
59
- const countDown = () => {
60
- leftTimeSecond--;
61
- setButtonLeftTime(leftTimeSecond);
62
- if (leftTimeSecond === 0) {
63
- return;
64
- }
65
- setTimeout(countDown, 1000);
66
- };
67
- setTimeout(countDown, 1000);
68
- };
69
-
70
- const handleOk = (
71
- captchaType: string,
72
- captchaToken: string,
73
- clientSecret: string
74
- ) => {
75
- setVisible(false);
76
- setButtonLoading(true);
77
- UserBackend.sendCode(
78
- captchaType,
79
- captchaToken,
80
- clientSecret,
81
- method,
82
- countryCode,
83
- ...onButtonClickArgs
84
- ).then((res: any) => {
85
- setButtonLoading(false);
86
- if (res) {
87
- handleCountDown(60);
88
- }
89
- });
90
- };
91
-
92
- const handleCancel = () => {
93
- setVisible(false);
94
- };
95
-
96
- React.useEffect(() => {
97
- dialogRef.current = document.getElementById("captcha-modal");
98
- }, []);
99
-
100
- React.useEffect(() => {
101
- if (dialogRef.current) {
102
- if (visible) {
103
- // @ts-ignore
104
- dialogRef.current.showModal();
105
- } else {
106
- // @ts-ignore
107
- dialogRef.current.close();
108
- }
109
- }
110
- }, [visible]);
111
-
112
- return (
113
- <React.Fragment>
114
- <div className="flex">
115
- <input
116
- className="input"
117
- // addonBefore={textBefore}
118
- disabled={disabled}
119
- value={value}
120
- // prefix={<SafetyOutlined />}
121
- placeholder={"Enter your code"}
122
- onChange={(e: any) => onChange(e.target.value)}
123
- // onBlur={() => setVisible(true)}
124
- autoComplete="one-time-code"
125
- />
126
- <button
127
- className="btn"
128
- disabled={disabled || buttonLeftTime > 0}
129
- // loading={buttonLoading}
130
- onClick={() => setVisible(true)}
131
- >
132
- {buttonLeftTime > 0
133
- ? `${buttonLeftTime} s`
134
- : buttonLoading
135
- ? t("code.sending")
136
- : t("code.sendCode")}
137
- </button>
138
- </div>
139
- <CaptchaModal
140
- owner={application.owner}
141
- name={application.name}
142
- visible={visible}
143
- onOk={handleOk}
144
- onCancel={handleCancel}
145
- isCurrentProvider={false}
146
- />
147
- </React.Fragment>
148
- );
149
- };
1
+ // Copyright 2021 The Casdoor Authors. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import React from "react";
16
+ import i18next from "i18next";
17
+ import * as UserBackend from "./util/user-api";
18
+ import { CaptchaModal } from "./CaptchaModal";
19
+ import type { Application } from "./util/provider";
20
+ import { useTranslation } from "react-i18next";
21
+
22
+ type ButtonClickArgsTuple = [
23
+ dest: any,
24
+ type: any,
25
+ applicationId: any,
26
+ checkUser?: string
27
+ ];
28
+
29
+ export type SendCodeInputProps = {
30
+ value?: any;
31
+ disabled: boolean;
32
+ textBefore?: string;
33
+ onChange: Function;
34
+ onButtonClickArgs: ButtonClickArgsTuple;
35
+ application: Application;
36
+ method: string;
37
+ countryCode: string;
38
+ CLIENT_ID: string;
39
+ CLIENT_SECRET: string;
40
+ };
41
+
42
+ export const SendCodeInput = ({
43
+ value,
44
+ disabled,
45
+ textBefore,
46
+ onChange,
47
+ onButtonClickArgs,
48
+ application,
49
+ method,
50
+ countryCode,
51
+ CLIENT_ID,
52
+ CLIENT_SECRET,
53
+ }: SendCodeInputProps) => {
54
+ const { t } = useTranslation();
55
+ const [visible, setVisible] = React.useState(false);
56
+ const [buttonLeftTime, setButtonLeftTime] = React.useState(0);
57
+ const [buttonLoading, setButtonLoading] = React.useState(false);
58
+ const dialogRef = React.useRef<HTMLElement | null>(null);
59
+
60
+ const handleCountDown = (leftTime = 60) => {
61
+ let leftTimeSecond = leftTime;
62
+ setButtonLeftTime(leftTimeSecond);
63
+ const countDown = () => {
64
+ leftTimeSecond--;
65
+ setButtonLeftTime(leftTimeSecond);
66
+ if (leftTimeSecond === 0) {
67
+ return;
68
+ }
69
+ setTimeout(countDown, 1000);
70
+ };
71
+ setTimeout(countDown, 1000);
72
+ };
73
+
74
+ const handleOk = (
75
+ captchaType: string,
76
+ captchaToken: string,
77
+ clientSecret: string
78
+ ) => {
79
+ setVisible(false);
80
+ setButtonLoading(true);
81
+ UserBackend.sendCode(
82
+ captchaType,
83
+ captchaToken,
84
+ clientSecret,
85
+ method,
86
+ countryCode,
87
+ ...onButtonClickArgs,
88
+ CLIENT_ID,
89
+ CLIENT_SECRET
90
+ ).then((res: any) => {
91
+ setButtonLoading(false);
92
+ if (res) {
93
+ handleCountDown(60);
94
+ }
95
+ });
96
+ };
97
+
98
+ const handleCancel = () => {
99
+ setVisible(false);
100
+ };
101
+
102
+ React.useEffect(() => {
103
+ dialogRef.current = document.getElementById("captcha-modal");
104
+ }, []);
105
+
106
+ React.useEffect(() => {
107
+ if (dialogRef.current) {
108
+ if (visible) {
109
+ // @ts-ignore
110
+ dialogRef.current.showModal();
111
+ } else {
112
+ // @ts-ignore
113
+ dialogRef.current.close();
114
+ }
115
+ }
116
+ }, [visible]);
117
+
118
+ return (
119
+ <React.Fragment>
120
+ <div className="flex">
121
+ <input
122
+ className="input"
123
+ // addonBefore={textBefore}
124
+ disabled={disabled}
125
+ value={value}
126
+ // prefix={<SafetyOutlined />}
127
+ placeholder={"Enter your code"}
128
+ onChange={(e: any) => onChange(e.target.value)}
129
+ // onBlur={() => setVisible(true)}
130
+ autoComplete="one-time-code"
131
+ />
132
+ <button
133
+ className="btn"
134
+ disabled={disabled || buttonLeftTime > 0}
135
+ // loading={buttonLoading}
136
+ onClick={() => setVisible(true)}
137
+ >
138
+ {buttonLeftTime > 0
139
+ ? `${buttonLeftTime} s`
140
+ : buttonLoading
141
+ ? t("code.sending")
142
+ : t("code.sendCode")}
143
+ </button>
144
+ </div>
145
+ <CaptchaModal
146
+ owner={application.owner}
147
+ name={application.name}
148
+ visible={visible}
149
+ onOk={handleOk}
150
+ onCancel={handleCancel}
151
+ isCurrentProvider={false}
152
+ />
153
+ </React.Fragment>
154
+ );
155
+ };