w-web-sso 1.0.23 → 1.0.24
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/dist/w-web-sso.umd.js +1 -1
- package/docs/WWebSso.html +1 -1
- package/docs/WWebSso.mjs.html +1 -1
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/getUserByUserId.mjs +98 -0
package/dist/w-web-sso.umd.js
CHANGED
package/docs/WWebSso.html
CHANGED
|
@@ -387,7 +387,7 @@
|
|
|
387
387
|
<br class="clear">
|
|
388
388
|
|
|
389
389
|
<footer>
|
|
390
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Wed Jul 23 2025 15:
|
|
390
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Wed Jul 23 2025 15:40:40 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
391
391
|
</footer>
|
|
392
392
|
|
|
393
393
|
<script>prettyPrint();</script>
|
package/docs/WWebSso.mjs.html
CHANGED
|
@@ -1172,7 +1172,7 @@ export default WWebSso
|
|
|
1172
1172
|
<br class="clear">
|
|
1173
1173
|
|
|
1174
1174
|
<footer>
|
|
1175
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Wed Jul 23 2025 15:
|
|
1175
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Wed Jul 23 2025 15:40:40 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1176
1176
|
</footer>
|
|
1177
1177
|
|
|
1178
1178
|
<script>prettyPrint();</script>
|
package/docs/index.html
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
<br class="clear">
|
|
72
72
|
|
|
73
73
|
<footer>
|
|
74
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Wed Jul 23 2025 15:
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Wed Jul 23 2025 15:40:40 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
75
75
|
</footer>
|
|
76
76
|
|
|
77
77
|
<script>prettyPrint();</script>
|
package/package.json
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import get from 'lodash-es/get.js'
|
|
3
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
4
|
+
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
5
|
+
import isfun from 'wsemi/src/isfun.mjs'
|
|
6
|
+
import ispm from 'wsemi/src/ispm.mjs'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async function getUserByUserId(url, tokenSelf, userIdTar, opt = {}) {
|
|
10
|
+
//url: http://localhost:11007/api/getSsoUserInfor
|
|
11
|
+
let errTemp = null
|
|
12
|
+
|
|
13
|
+
//check
|
|
14
|
+
if (!isestr(url)) {
|
|
15
|
+
return Promise.reject('invalid url')
|
|
16
|
+
}
|
|
17
|
+
if (!isestr(tokenSelf)) {
|
|
18
|
+
return Promise.reject('invalid tokenSelf')
|
|
19
|
+
}
|
|
20
|
+
if (!isestr(userIdTar)) {
|
|
21
|
+
return Promise.reject('invalid userIdTar')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//funConvertUser
|
|
25
|
+
let funConvertUser = get(opt, 'funConvertUser')
|
|
26
|
+
|
|
27
|
+
//url
|
|
28
|
+
url = `${url}?token={sysToken}&key=userId&value={userId}`
|
|
29
|
+
url = url.replaceAll('{sysToken}', tokenSelf) //系統介接用ssoToken
|
|
30
|
+
url = url.replaceAll('{userId}', userIdTar)
|
|
31
|
+
// console.log('getUserByUserId: url', url)
|
|
32
|
+
|
|
33
|
+
//get
|
|
34
|
+
let res = await axios.get(url)
|
|
35
|
+
.catch((err) => {
|
|
36
|
+
errTemp = err.toString()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
//check
|
|
40
|
+
if (errTemp !== null) {
|
|
41
|
+
console.log('res', res)
|
|
42
|
+
console.log('errTemp', errTemp)
|
|
43
|
+
console.log(`can not get user by url[${url}]`)
|
|
44
|
+
return Promise.reject(`can not get user by url[${url}]`) //由SSO取得使用者資訊錯誤
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//data
|
|
48
|
+
let data = get(res, 'data')
|
|
49
|
+
|
|
50
|
+
//state
|
|
51
|
+
let state = get(data, 'state', '')
|
|
52
|
+
|
|
53
|
+
//msg
|
|
54
|
+
let msg = get(data, 'msg')
|
|
55
|
+
|
|
56
|
+
//check
|
|
57
|
+
if (state !== 'success') {
|
|
58
|
+
console.log('res', res)
|
|
59
|
+
console.log('data', data)
|
|
60
|
+
console.log('state', state)
|
|
61
|
+
console.log('errTemp', msg)
|
|
62
|
+
console.log(`can not get user data by url[${url}]`)
|
|
63
|
+
return Promise.reject(`can not get user data by url[${url}]`) //取得使用者資訊失敗
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//u
|
|
67
|
+
let u = msg
|
|
68
|
+
// console.log('getUserByUserId u(msg)', u)
|
|
69
|
+
|
|
70
|
+
//check
|
|
71
|
+
if (!iseobj(u)) {
|
|
72
|
+
console.log(`no user data by url[${url}]`)
|
|
73
|
+
return Promise.reject(`no user data by url[${url}]`)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//check
|
|
77
|
+
if (isfun(funConvertUser)) {
|
|
78
|
+
|
|
79
|
+
//funConvertUser
|
|
80
|
+
u = funConvertUser(u)
|
|
81
|
+
if (ispm(u)) {
|
|
82
|
+
u = await u
|
|
83
|
+
}
|
|
84
|
+
// console.log('getUserByUserId u(funConvertUser)', u)
|
|
85
|
+
|
|
86
|
+
//check
|
|
87
|
+
if (!iseobj(u)) {
|
|
88
|
+
console.log(`no user data after funConvertUser`)
|
|
89
|
+
return Promise.reject(`no user data after funConvertUser`)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return u
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
export default getUserByUserId
|