Skip to content

Commit 94cbe16

Browse files
author
YangyangLi
committed
fix
1 parent 2ab400f commit 94cbe16

10 files changed

Lines changed: 70 additions & 66 deletions

File tree

adaptive-mfa-demo/client/src/pages/login-form.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export default function LoginForm() {
2020
//@ts-ignore
2121
window.setLoading(false)
2222
if (err) {
23-
alert('密码输入错误')
23+
// alert('密码输入错误')
24+
return
2425
};
2526
console.log(res);
2627
// if(res)

adaptive-mfa-demo/server/src/api.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ const login = async (req, res) => {
1111
const userPasswordValid = user?.password === password
1212
if (userPasswordValid) {
1313
const ueba = {
14-
"a": "a",
15-
"b": "b",
16-
behaviorType: 'login',
17-
behaviorResult: 'login_success',
18-
originalIdentity: username
14+
behaviorResult: "login_success",
15+
originalIdentity: username,
16+
behaviorType: "login",
17+
ip: "127.0.5.19"
1918
}
2019
const mfaTriggerData = await triggerMFA(ueba)
2120
return {
@@ -25,23 +24,21 @@ const login = async (req, res) => {
2524
} else {
2625
if(user) {
2726
const ueba = {
28-
"a": "a",
29-
"b": "b",
3027
behaviorType: 'login',
31-
behaviorResult: 'login_failed_by_password',
32-
originalIdentity: username
28+
behaviorResult: 'account_wrong',
29+
originalIdentity: username,
30+
ip: "127.0.5.19"
3331
}
34-
await triggerMFA(ueba)
32+
triggerMFA(ueba)
3533
console.log(ueba);
3634
} else {
3735
const ueba = {
38-
"a": "a",
39-
"b": "b",
4036
behaviorType: 'login',
41-
behaviorResult: 'login_failed_by_account',
42-
originalIdentity: username
37+
behaviorResult: 'account_wrong',
38+
originalIdentity: username,
39+
ip: "127.0.5.19"
4340
}
44-
await triggerMFA(ueba)
41+
triggerMFA(ueba)
4542
console.log(ueba);
4643
}
4744
res.send(400)
@@ -51,16 +48,25 @@ const login = async (req, res) => {
5148
const triggerMFA = async (ueba) => {
5249
console.log('ueba', ueba);
5350
// TODO: public/service
54-
const res = await axios.post('https://console.wh.authing-inc.co/public/service/c523d7e6-ea1e-4a55-8a8a-6368af79d10a',
51+
const res = await axios.post('https://console.wh.authing-inc.co/public/service/4428ece3304f431581eb7738125e5582',
5552
{
56-
"query": {
57-
},
58-
"headers": {
59-
},
53+
"query": {},
54+
"headers": {},
6055
"body": ueba
56+
},
57+
{
58+
headers: {
59+
"content-type": "application/json",
60+
"x-authing-userpool-id": "644795124e79ca8a0fb9b281"
61+
}
6162
}
6263
)
63-
return res.data.data.output
64+
if(res.data?.data?.output) {
65+
console.log(res.data);
66+
return res.data.data.output
67+
}
68+
console.log(res.data);
69+
// return res.data.data.output
6470
}
6571

6672
router.post('/login', async function (req, res) {
@@ -77,7 +83,8 @@ router.post('/login', async function (req, res) {
7783
} = loginRes
7884
console.log(mfaTriggerData);
7985

80-
if (mfaTriggerData.applicationMfa.length) {
86+
if (mfaTriggerData?.applicationMfa?.length) {
87+
console.log(JSON.stringify(mfaTriggerData.applicationMfa));
8188
res.send({
8289
status: false,
8390
mfaTriggerData
@@ -92,7 +99,6 @@ router.post('/login', async function (req, res) {
9299
} catch (error) {
93100
console.log(error);
94101
}
95-
96102
});
97103

98104
router.get('/personal', function (req, res) {

adaptive-mfa-demo/server/src/user.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"status": "Activated",
88
"email": "test@dsadsa.com",
99
"phone": "16666666666",
10-
"username": "test",
10+
"username": "lyy",
1111
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
1212
"password": "111111",
1313
"loginsCount": 1,

continuous-adaptive-mfa-demo/client/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function App() {
1212
return (
1313
<AuthingMFAProvider
1414
host="https://console.wh.authing-inc.co"
15-
appId="6421c2b9ce49522bfc07a3f2"
15+
appId="644ccb3a237085bf7c3b57f4"
1616
lang="en-US"
1717
// host="https://console.mfa.authing-inc.co"
1818
// appId="641ae676b72ee5baf98d7345"

continuous-adaptive-mfa-demo/client/src/pages/login-form.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export default function LoginForm() {
2020
//@ts-ignore
2121
window.setLoading(false)
2222
if (err) {
23-
alert('密码输入错误')
23+
// alert('密码输入错误')
24+
return
2425
};
2526
console.log(res);
2627
// if(res)

continuous-adaptive-mfa-demo/server/api-filter.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { uebaCapture } = require('./ueba')
22
const axios = require('axios')
3-
const {authingManagementClient, userPoolId} = require('./authing-client')
3+
const {authingManagementClient, userPoolId, token: authingToken} = require('./authing-client')
44

55
module.exports = async (req, res, next) => {
66
console.log('Time:', Date.now())
@@ -21,12 +21,16 @@ module.exports = async (req, res, next) => {
2121
userIdType: 'username',
2222
},
2323
headers: {
24-
"x-authing-userpool-id": userPoolId
24+
"x-authing-userpool-id": userPoolId,
25+
authorization: authingToken
2526
}
2627
})
2728
if(authingUser.data) {
2829
res.send({
29-
mfaTriggerData: authingUser.data
30+
mfaTriggerData: {
31+
...authingUser.data,
32+
applicationMfa: [ { mfaPolicy: 'SMS', sort: 1, status: 1 } ],
33+
}
3034
})
3135
return
3236
}

continuous-adaptive-mfa-demo/server/api.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
const axios = require('axios')
21
const users = require('./user.json');
3-
const { uebaCapture, generateUEBAData } = require('./ueba')
4-
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cGRhdGVkX2F0IjoiMjAyMy0wMy0yNFQwODozMDoyNi40NjRaIiwiYWRkcmVzcyI6eyJjb3VudHJ5IjpudWxsLCJwb3N0YWxfY29kZSI6bnVsbCwicmVnaW9uIjpudWxsLCJmb3JtYXR0ZWQiOm51bGx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I6IjU5Zjg2YjQ4MzJlYjI4MDcxYmRkOTIxNCIsImF1ZCI6IjYzMmJlMDlmMmM5N2ZjMWM0ODkyOWI2NiIsImV4cCI6MTY4MDg2MTUwNSwiaWF0IjoxNjc5NjUxOTA1LCJpc3MiOiJodHRwczovL2NvbnNvbGUud2guYXV0aGluZy1pbmMuY28vb2lkYyJ9.7uFdSxveMhsuRYdA0x8zQdHHhOa5Bi3UufurCkpK8Hk'
5-
6-
const {authingManagementClient, appId, userPoolId } = require('./authing-client')
2+
const { uebaCapture } = require('./ueba')
73

84
const express = require('express');
95
const router = express.Router();
@@ -16,25 +12,27 @@ const login = async (req, res) => {
1612
const ueba = await uebaCapture(req, {
1713
behaviorType: 'login',
1814
behaviorResult: 'login_success',
19-
originalIdentity: username
15+
originalIdentity: username,
16+
ip: "127.0.5.19"
2017
})
2118
return {
22-
user,
23-
ueba
19+
user
2420
}
2521
} else {
2622
if(user) {
2723
const ueba = await uebaCapture(req, {
2824
behaviorType: 'login',
29-
behaviorResult: 'login_failed_by_password',
30-
originalIdentity: username
25+
behaviorResult: 'account_wrong',
26+
originalIdentity: username,
27+
ip: "127.0.5.19"
3128
})
3229
console.log(ueba);
3330
} else {
3431
await uebaCapture(req, {
3532
behaviorType: 'login',
36-
behaviorResult: 'login_failed_by_account',
37-
originalIdentity: username
33+
behaviorResult: 'account_wrong',
34+
originalIdentity: username,
35+
ip: "127.0.5.19"
3836
})
3937
}
4038
res.send(400)
@@ -50,8 +48,7 @@ router.post('/login', async function (req, res) {
5048
}
5149

5250
const {
53-
user,
54-
ueba
51+
user
5552
} = loginRes
5653

5754
res.cookie('token', JSON.stringify(user));

continuous-adaptive-mfa-demo/server/authing-client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ module.exports.authingMetadataManagementClient = authingMetadataManagementClient
2020
module.exports.authingManagementClient = authingManagementClient
2121
module.exports.ueba = ueba
2222
module.exports.appId = appId
23-
module.exports.userPoolId = userPoolId
23+
module.exports.userPoolId = userPoolId
24+
module.exports.token = token

continuous-adaptive-mfa-demo/server/ueba.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,21 @@ const generateUEBAData = (req) => {
1010
}
1111
}
1212

13-
const mockData = {
14-
appId,
15-
ip: '117.133.11.139',
16-
ua: 'ua',
17-
behaviorType: 'login',
18-
actionType: 'Read',
19-
loginType: 'wechat',
20-
someKey: '这是自定义的',
21-
originalIdentity: "lyy",
22-
browserType: 'Chrome',
23-
originalIdentity: "lyy",
24-
behaviorResult:'account_wrong',
25-
someKey: "a",
26-
}
13+
// const mockData = {
14+
// appId,
15+
// behaviorType: 'login',
16+
// behaviorResult: 'account_wrong',
17+
// originalIdentity: username,
18+
// ip: "127.0.5.19"
19+
// }
20+
2721
const uebaCapture = async (req, data) => {
28-
// const baseData = generateUEBAData(req)
29-
// const res = await ueba.capture({
30-
// ...baseData,
31-
// ...data
32-
// })
33-
const res = await ueba.capture(mockData)
22+
const baseData = generateUEBAData(req)
23+
const res = await ueba.capture({
24+
...baseData,
25+
...data
26+
})
27+
// const res = await ueba.capture(mockData)
3428
console.log(res.data);
3529
return res.data
3630
}

continuous-adaptive-mfa-demo/server/user.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"status": "Activated",
88
"email": "test@dsadsa.com",
99
"phone": "16666666666",
10-
"username": "lyy",
10+
"username": "lyy2",
1111
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
1212
"password": "111111",
1313
"loginsCount": 1,

0 commit comments

Comments
 (0)