Add SSO and device management samples
This commit is contained in:
127
SDK_MODIFICATIONS.md
Normal file
127
SDK_MODIFICATIONS.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# FIDO2 UI SDK 修改说明
|
||||
|
||||
## 修改概述
|
||||
|
||||
根据需求,对UI SDK进行了以下修改:
|
||||
|
||||
1. **增加用户ID参数**:renderDeviceManager函数现在需要userId参数
|
||||
2. **删除登录功能**:移除了登录相关的UI和事件处理
|
||||
3. **简化设备管理**:设备操作现在直接使用传入的用户ID
|
||||
|
||||
## 主要修改
|
||||
|
||||
### 1. renderDeviceManager函数
|
||||
|
||||
**修改前:**
|
||||
```javascript
|
||||
Fido2UIManager.renderDeviceManager({
|
||||
container: '#device-container',
|
||||
mode: 'modal',
|
||||
serverUrl: SERVER_URL
|
||||
});
|
||||
```
|
||||
|
||||
**修改后:**
|
||||
```javascript
|
||||
Fido2UIManager.renderDeviceManager({
|
||||
userId: 'user@example.com', // 新增必需参数
|
||||
container: '#device-container',
|
||||
mode: 'modal',
|
||||
serverUrl: SERVER_URL
|
||||
});
|
||||
```
|
||||
|
||||
### 2. DeviceManager修改
|
||||
|
||||
- `addDevice()`: 使用`this.config.userId`代替从sessionStorage获取用户ID
|
||||
- `deleteDevice()`: 使用`this.config.userId`代替从sessionStorage获取用户ID
|
||||
- `checkSession()`: 简化为始终返回true(假设用户已登录)
|
||||
- `getUserId()`: 返回`this.config.userId`
|
||||
|
||||
### 3. 删除的功能
|
||||
|
||||
- 移除了登录按钮的UI渲染
|
||||
- 移除了login事件处理器
|
||||
- 移除了session检查逻辑
|
||||
- 移除了getSessionData方法
|
||||
|
||||
### 4. 错误处理
|
||||
|
||||
如果未提供userId参数,renderDeviceManager会抛出错误:
|
||||
```
|
||||
'userId is required for device management operations'
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 模式1:模态框模式
|
||||
|
||||
```javascript
|
||||
Fido2UIManager.renderDeviceManager({
|
||||
userId: 'user@example.com',
|
||||
container: '#device-container',
|
||||
mode: 'modal',
|
||||
serverUrl: 'https://your-server.com',
|
||||
language: 'en-US',
|
||||
callbacks: {
|
||||
onInit: function(manager) {
|
||||
console.log('Device manager initialized');
|
||||
},
|
||||
onDeviceAdded: function(device) {
|
||||
console.log('Device added:', device);
|
||||
},
|
||||
onDeviceDeleted: function(deviceId) {
|
||||
console.log('Device deleted:', deviceId);
|
||||
},
|
||||
onDeviceListLoaded: function(devices) {
|
||||
console.log('Devices loaded:', devices);
|
||||
},
|
||||
onError: function(error) {
|
||||
console.error('Error:', error);
|
||||
},
|
||||
onClose: function() {
|
||||
console.log('Device manager closed');
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### 模式2:独立页面模式
|
||||
|
||||
```javascript
|
||||
Fido2UIManager.renderDeviceManager({
|
||||
userId: 'user@example.com',
|
||||
mode: 'standalone',
|
||||
serverUrl: 'https://your-server.com',
|
||||
language: 'zh-CN',
|
||||
theme: {
|
||||
primaryColor: '#007bff',
|
||||
backgroundColor: '#f8f9fa'
|
||||
},
|
||||
features: {
|
||||
showAddButton: true,
|
||||
showDeleteButton: true,
|
||||
showUserInfo: true,
|
||||
showSessionStatus: true
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **userId参数是必需的**:不提供userId会导致错误
|
||||
2. **假设用户已登录**:不再进行登录状态检查
|
||||
3. **向后兼容**:此修改可能会影响现有集成,需要更新调用代码
|
||||
4. **删除的API**:renderLogin函数仍然存在,但如果不再需要可以移除
|
||||
|
||||
## 测试
|
||||
|
||||
可以使用test-device-manager.html文件测试修改后的功能。
|
||||
|
||||
## 依赖关系
|
||||
|
||||
确保在调用renderDeviceManager之前已经加载了:
|
||||
- jQuery
|
||||
- Bootstrap JS
|
||||
- dfido2-lib.js
|
||||
- fido2-ui-sdk.js
|
||||
Reference in New Issue
Block a user