Skip to content

Commit 3f328f9

Browse files
authored
Merge pull request #349 from Authing/feat/verify_device
Feat/verify device
2 parents aadeb09 + d3affd4 commit 3f328f9

File tree

7 files changed

+561
-1
lines changed

7 files changed

+561
-1
lines changed

docs/.vuepress/sidebar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ const zhCnNavBar = {
14221422
"/reference/sdk-for-node/authentication/SocialAuthenticationClient",
14231423
"/reference/sdk-for-node/authentication/EnterpriseAuthenticationClient",
14241424
"/reference/sdk-for-node/authentication/PrincipalAuthentication",
1425+
"/reference/sdk-for-node/authentication/BrowserFingerprintClient",
14251426
],
14261427
},
14271428
{
@@ -1442,6 +1443,7 @@ const zhCnNavBar = {
14421443
"/reference/sdk-for-node/management/MFAManagementClient",
14431444
"/reference/sdk-for-node/management/PrincipalManagementClient",
14441445
"/reference/sdk-for-node/management/TenantManagementClient",
1446+
"/reference/sdk-for-node/management/BrowserFingerprintClient",
14451447
],
14461448
},
14471449
],

docs/reference/sdk-for-node/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ authenticationClient.qrcode.startScanning('DOM_ID', {
182182
- [多因素认证模块](./authentication/MfaAuthenticationClient.md)
183183
- [社会化登录模块](./authentication/SocialAuthenticationClient.md)
184184
- [企业身份源登录模块](./authentication/EnterpriseAuthenticationClient.md)
185+
- [管理浏览器指纹模块](./authentication/BrowserFingerprintClient.md)
185186

186187
## 使用管理模块
187188

@@ -255,6 +256,7 @@ const userpool = await managementClient.userpool.update({
255256
- [白名单管理模块](./management/WhitelistManagementClient.md)
256257
- [用户池设置管理模块](./management/UserpoolManagementClient.md)
257258
- [多租户管理模块](./management/TenantManagementClient.md)
259+
- [管理浏览器指纹模块](./management/BrowserFingerprintClient.md)
258260

259261
## 错误处理
260262

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# 浏览器指纹模块
2+
3+
<LastUpdated/>
4+
5+
> 此模块主要用来管理 浏览器指纹 相关操作,快速使用浏览器指纹相关数据接口以及功能。
6+
7+
使用方法:
8+
9+
```javascript
10+
import { AuthenticationClient } from 'authing-js-sdk';
11+
const authenticationClient = new AuthenticationClient({
12+
appId: "AUTHING_APP_ID",
13+
appHost: 'https://{YOUR_DOMAIN}.authing.cn',
14+
});
15+
16+
authenticationClient.browserFingerprint.getBrowserFingers; // 获取指纹信息 & 设备 id
17+
authenticationClient.browserFingerprint.createDevice; // 浏览器设备上报
18+
authenticationClient.browserFingerprint.myDevicesList; // 用户中心 - 列表
19+
authenticationClient.browserFingerprint.myDevicesUnbind; // 用户中心 - 移除设备
20+
authenticationClient.browserFingerprint.myDevicesLogout; // 用户中心 - 登出设备
21+
22+
```
23+
24+
25+
## 获取指纹信息 & 设备 id
26+
27+
#### 示例
28+
29+
```js
30+
import { AuthenticationClient } from "authing-js-sdk";
31+
32+
const authenticationClient = new AuthenticationClient({
33+
appId: "AUTHING_APP_ID",
34+
appHost: 'https://{YOUR_DOMAIN}.authing.cn',
35+
});
36+
37+
const { browserId, deviceFingers } = await authenticationClient.browserFingerprint.getBrowserFingers();
38+
39+
const {
40+
userAgentFingerprint, //浏览器用户代理指纹
41+
audioFingerprint, //音频设置和硬件特征指纹
42+
canvasFingerprint, //2D图像和动画绘制特征指纹
43+
screenResolutionFingerprint, //浏览器分辨率指纹
44+
webglFingerprint, //显卡及驱动程序指纹
45+
fontsFingerprint, //字体及输入设备特征指纹
46+
pluginsFingerprint, //浏览器预装插件指纹信息
47+
} = deviceFingers;
48+
49+
console.log(browserId); //浏览器设备id
50+
```
51+
52+
## 浏览器设备上报
53+
#### 示例
54+
55+
```js
56+
await authenticationClient.browserFingerprint.createDevice()
57+
```
58+
59+
#### 返回值
60+
61+
```json
62+
boolean : true / false
63+
```
64+
65+
66+
## 订阅设备事件
67+
68+
#### 示例
69+
70+
```js
71+
import { AuthenticationClient } from "authing-js-sdk";
72+
73+
const authenticationClient = new AuthenticationClient( {
74+
appId: "AUTHING_APP_ID",
75+
appHost: 'https://{YOUR_DOMAIN}.authing.cn',
76+
socketUri:'YOUR_SOCKET_URL',
77+
token:'YOUR_TOKEN',
78+
});
79+
80+
//获取设备id
81+
const { browserId } = await authenticationClient.browserFingerprint.getBrowserFingers();
82+
//事件监听
83+
authenticationClient. event.sub(
84+
'authing.device.force-logout',
85+
(msgDataStr: string) => {
86+
const msgData = JSON.parse(msgDataStr);
87+
const { appId: msgAppid, logoutType, deviceId } = msgData;
88+
//对比必须是当前 appid 和当前设备
89+
if (msgAppid === appId && deviceId === browserId) {
90+
switch (logoutType) {
91+
case 0:
92+
console.log('使其他设备登出')
93+
break;
94+
case 1:
95+
console.log('个人中心 - 设备解绑')
96+
break;
97+
case 2:
98+
console.log('用户列表 - 个人详情 - 挂起设备')
99+
break;
100+
case 3:
101+
console.log('设备管理 - 挂起设备')
102+
break;
103+
case 4:
104+
console.log('用户列表 - 个人详情 - 禁用设备')
105+
break;
106+
case 5:
107+
console.log('设备管理 - 禁用设备')
108+
break;
109+
case 6:
110+
console.log('用户列表 - 个人详情 - 移除设备(解绑)')
111+
break;
112+
case 7:
113+
console.log('设备管理 - 删除设备')
114+
break;
115+
default:
116+
break;
117+
}
118+
}
119+
},
120+
() => {}
121+
);
122+
```
123+
124+
## 用户中心 - 列表
125+
#### 示例
126+
127+
```js
128+
import { AuthenticationClient } from "authing-js-sdk";
129+
130+
const authenticationClient = new AuthenticationClient({
131+
appId: "AUTHING_APP_ID",
132+
appHost: 'https://{YOUR_DOMAIN}.authing.cn',
133+
});
134+
135+
const list = await authenticationClient.browserFingerprint.myDevicesList()
136+
```
137+
138+
#### 示例数据
139+
140+
```json
141+
[
142+
{
143+
"device": {
144+
"name": "chrome/114.0.0.0",
145+
"type": "Browser",
146+
"status": "activated",
147+
"os": "Mac OS",
148+
"version": "114.0.0.0",
149+
"mod": null,
150+
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
151+
"deviceId": "47a5d2ab86d90e6d2a8b7efcba939eec"
152+
},
153+
"lastLoginTime": "2023-07-06T02:25:08.879Z",
154+
"lastIp": "49.7.66.98",
155+
"online": true
156+
}
157+
]
158+
```
159+
160+
161+
## 用户中心 - 移除设备
162+
#### 参数
163+
164+
- `deviceUniqueId` \<string\> 当前用户的设备唯一标识
165+
166+
#### 示例
167+
168+
```js
169+
await authenticationClient.browserFingerprint.myDevicesUnbind('47a5d2ab86d90e6d2a8b7efcba939eec')
170+
```
171+
172+
#### 返回值
173+
174+
```json
175+
boolean : true / false
176+
```
177+
178+
## 用户中心 - 登出设备
179+
#### 参数
180+
181+
- `deviceUniqueId` \<string\> 当前用户的设备唯一标识
182+
183+
#### 示例
184+
185+
```js
186+
await authenticationClient.browserFingerprint.myDevicesLogout('47a5d2ab86d90e6d2a8b7efcba939eec')
187+
```
188+
189+
#### 返回值
190+
191+
```json
192+
boolean : true / false
193+
```

docs/reference/sdk-for-node/authentication/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ meta:
4444

4545
::: page-ref /reference/sdk-for-node/authentication/PrincipalAuthentication.md
4646
:::
47+
48+
如果你需要浏览器指纹,请使用:
49+
50+
::: page-ref /reference/sdk-for-node/authentication/BrowserFingerprintClient.md
51+
:::

0 commit comments

Comments
 (0)