lgsso-sdk 1.0.95 → 1.0.96
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 +43 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,29 +41,29 @@ const customSSO = createSSO();
|
|
|
41
41
|
```
|
|
42
42
|
lgsso.init({
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
accessCodeKey: 'accessCode', // accessCode 在 URL 中的参数名
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
tokenKey: 'scm\_token', // token 在存储中的键名
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
timeout: 5000, // 请求超时时间(毫秒)
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
headers: {}, // 自定义请求头
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
tokenApi: '/api/token', // 通过 accessCode 获取 token 的 API 地址(必填)
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
refreshCodeApi: '/api/refresh', // 刷新 accessCode 的 API 地址
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
logoutApi: '/api/logout', // 注销 API 地址
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
logOutUrl: '/login', // 登录页面 URL
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
storage: localStorage, // 存储方式(localStorage/sessionStorage)
|
|
61
61
|
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
.then(result => {
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
console.log('初始化结果:', result);
|
|
67
67
|
|
|
68
68
|
});
|
|
69
69
|
```
|
|
@@ -135,7 +135,7 @@ lgsso.logout()
|
|
|
135
135
|
|
|
136
136
|
.then(result => {
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
console.log('退出结果:', result);
|
|
139
139
|
|
|
140
140
|
});
|
|
141
141
|
```
|
|
@@ -163,7 +163,7 @@ lgsso.toUrl('https://example.com/target', '\_self')
|
|
|
163
163
|
|
|
164
164
|
.then(result => {
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
console.log('跳转准备结果:', result);
|
|
167
167
|
|
|
168
168
|
});
|
|
169
169
|
|
|
@@ -185,11 +185,11 @@ lgsso.getAccessCode()
|
|
|
185
185
|
|
|
186
186
|
.then(result => {
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
if (result.code === 0) {
|
|
189
189
|
|
|
190
|
-
|
|
190
|
+
console.log('新的accessCode:', result.data);
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
}
|
|
193
193
|
|
|
194
194
|
});
|
|
195
195
|
```
|
|
@@ -223,69 +223,69 @@ lgsso.getAccessCode()
|
|
|
223
223
|
|
|
224
224
|
lgsso.init({
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
tokenApi: '/api/getToken',
|
|
227
227
|
|
|
228
|
-
|
|
228
|
+
refreshCodeApi: '/api/refreshCode',
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
logoutApi: '/api/logout',
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
logOutUrl: '/login'
|
|
233
233
|
|
|
234
234
|
})
|
|
235
235
|
|
|
236
236
|
.then(initResult => {
|
|
237
237
|
|
|
238
|
-
|
|
238
|
+
console.log('初始化结果:', initResult);
|
|
239
239
|
|
|
240
|
-
|
|
240
|
+
|
|
241
241
|
|
|
242
|
-
|
|
242
|
+
// 获取token
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
const token = lgsso.getToken();
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
console.log('当前token:', token);
|
|
247
247
|
|
|
248
|
-
|
|
248
|
+
|
|
249
249
|
|
|
250
|
-
|
|
250
|
+
// 跳转到其他应用(当前页面)
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
document.getElementById('gotoCurrent').addEventListener('click', () => {
|
|
253
253
|
|
|
254
|
-
|
|
254
|
+
lgsso.toUrl('https://other-app.example.com', '\_self')
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
.catch(err => console.error('跳转失败:', err));
|
|
257
257
|
|
|
258
|
-
|
|
258
|
+
});
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
// 跳转到其他应用(新页面)
|
|
263
263
|
|
|
264
|
-
|
|
264
|
+
document.getElementById('gotoNew').addEventListener('click', () => {
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
lgsso.toUrl('https://other-app.example.com', '\_blank')
|
|
267
267
|
|
|
268
|
-
|
|
268
|
+
.catch(err => console.error('跳转失败:', err));
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
});
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
|
|
273
273
|
|
|
274
|
-
|
|
274
|
+
// 退出登录
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
document.getElementById('logoutBtn').addEventListener('click', () => {
|
|
277
277
|
|
|
278
|
-
|
|
278
|
+
lgsso.logout()
|
|
279
279
|
|
|
280
|
-
|
|
280
|
+
.catch(err => console.error('退出失败:', err));
|
|
281
281
|
|
|
282
|
-
|
|
282
|
+
});
|
|
283
283
|
|
|
284
284
|
})
|
|
285
285
|
|
|
286
286
|
.catch(err => {
|
|
287
287
|
|
|
288
|
-
|
|
288
|
+
console.error('初始化失败:', err);
|
|
289
289
|
|
|
290
290
|
});
|
|
291
291
|
```
|
|
@@ -304,4 +304,3 @@ lgsso.init({
|
|
|
304
304
|
|
|
305
305
|
5. 使用 `toUrl` 方法时,`target` 参数仅支持 `'_self'` 和 `'_blank'` 两个值,默认使用 `'_self'`
|
|
306
306
|
|
|
307
|
-
> (注:文档部分内容可能由 AI 生成)
|