bjchy-udg-sdk 1.0.2 → 1.0.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/README.md +6 -0
- package/package.json +1 -1
- package/src/index.js +6 -2
package/README.md
CHANGED
|
@@ -78,6 +78,12 @@ renderQrCode(client.buildScanQrContent(sessionId)) // 二维码内
|
|
|
78
78
|
const { userInfo } = await client.pollScanLogin(sessionId) // 确认后自动保存 token
|
|
79
79
|
// 小程序确认端:await client.approveScanLogin({ id, admininfo })(需先 login())
|
|
80
80
|
|
|
81
|
+
// ③b 跨租户借用登录:借用别的小程序(streetKey='hjl')的扫码流程登录到当前项目自己的 appid
|
|
82
|
+
// (小程序端代码完全不用改;目标项目需在管理后台配置 scanLoginTrustedStreetKeys 信任来源,
|
|
83
|
+
// 不配置 = 不限制;详见 docs/scan-login-cross-tenant.md)
|
|
84
|
+
renderQrCode(client.buildScanQrContent(sessionId, { streetKey: 'hjl' }))
|
|
85
|
+
await client.pollScanLogin(sessionId, { viaStreetKey: 'hjl' }) // token.appid 仍是当前项目自己的 appid
|
|
86
|
+
|
|
81
87
|
// ④ 外部体系已有 JWT(共用 JWT_SECRET,互通):init({ token }) 直入
|
|
82
88
|
```
|
|
83
89
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -158,7 +158,10 @@ class UdgClient {
|
|
|
158
158
|
/**
|
|
159
159
|
* 轮询扫码登录结果;确认后自动保存 token 并返回 { token, refreshToken, userInfo }。
|
|
160
160
|
* @param {string} sessionId createScanSession 返回的 id(即二维码中的 id)
|
|
161
|
-
* @param {object} opts { interval=2000, timeout=300000, onStatus(status) }
|
|
161
|
+
* @param {object} opts { interval=2000, timeout=300000, onStatus(status), viaStreetKey? }
|
|
162
|
+
* viaStreetKey:跨租户借用登录(见 docs/scan-login-cross-tenant.md)——本次扫码借用的来源
|
|
163
|
+
* streetKey(对应的小程序),不传 = 现状(登录来源即本 client 的 appid);跨租户时 token 归属
|
|
164
|
+
* 仍然是本 client 的 appid,来源租户只是负责扫码环节
|
|
162
165
|
*/
|
|
163
166
|
async pollScanLogin(sessionId, opts) {
|
|
164
167
|
await ensureAppid(this._ctx)
|
|
@@ -170,7 +173,8 @@ class UdgClient {
|
|
|
170
173
|
for (;;) {
|
|
171
174
|
const data = await post('/auth/scan/statuscheck', {
|
|
172
175
|
appid: this._ctx.appid,
|
|
173
|
-
id: sessionId
|
|
176
|
+
id: sessionId,
|
|
177
|
+
viaStreetKey: o.viaStreetKey
|
|
174
178
|
})
|
|
175
179
|
if (typeof o.onStatus === 'function') o.onStatus(data.status)
|
|
176
180
|
if (data.status === 'confirmed') {
|