bjx-auth 1.2.0 → 1.4.0
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/bjx-auth-api.esm.js +2 -2
- package/dist/bjx-auth-api.umd.js +2 -2
- package/dist/index-Doi37tmx.js +2 -0
- package/dist/request.cjs.js +2 -0
- package/dist/strategy.cjs.js +2 -0
- package/package.json +9 -7
- package/readme.md +14 -19
- package/src/config.js +0 -59
- package/src/logger.js +0 -15
- package/src/request/axios.js +0 -67
- package/src/request/index.js +0 -12
- package/src/request/passportapi.js +0 -216
- package/src/request/sign/encrypt/index.js +0 -7
- package/src/request/sign/encrypt/node.js +0 -31
- package/src/request/sign/encrypt/web.js +0 -31
- package/src/request/sign/hash/index.js +0 -7
- package/src/request/sign/hash/node.js +0 -14
- package/src/request/sign/hash/web.js +0 -18
- package/src/request/sign/index.js +0 -59
- package/src/request/sign/publicPem.js +0 -45
- package/src/request/sign/reqEncrypt.js +0 -16
- package/src/request/sign/reqSginOld.js +0 -89
- package/src/request/sign/reqSign.js +0 -80
- package/src/request/userInfo.js +0 -72
- package/src/strategy/handle.js +0 -66
- package/src/strategy/handleDemo.js +0 -49
- package/src/strategy/index.js +0 -9
- package/src/strategy/strategy.js +0 -261
- package/src/strategy/utils.js +0 -268
package/src/strategy/strategy.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
const { Strategy } = require('passport')
|
|
2
|
-
const { setConfig, getConfig, getToken, getUserInfo } = require('./handle')
|
|
3
|
-
const { errorLogger, debugLogger } = require('../logger')
|
|
4
|
-
|
|
5
|
-
class BjxStrategy extends Strategy {
|
|
6
|
-
constructor(options = {}, verify) {
|
|
7
|
-
super()
|
|
8
|
-
|
|
9
|
-
// 策略名称
|
|
10
|
-
this.name = 'bjx'
|
|
11
|
-
|
|
12
|
-
// 配置选项
|
|
13
|
-
this.loadUserInfo = options.loadUserInfo || false
|
|
14
|
-
this.userInfoDuration = this.normalizeDuration(options.loadUserInfo)
|
|
15
|
-
this.userInfoType = options.userInfoType || ''
|
|
16
|
-
this.handleHeadrToken = options.handleHeadrToken || false
|
|
17
|
-
this.verify = verify || ((user, done) => done(null, user))
|
|
18
|
-
|
|
19
|
-
// 设置配置缓存
|
|
20
|
-
setConfig(options.authConfig)
|
|
21
|
-
if (options.authConfig.debug) {
|
|
22
|
-
debugLogger('配置项', getConfig())
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
normalizeDuration(val) {
|
|
27
|
-
// loadUserInfo参数 单位为分钟 但是这里返回毫秒 减少比较时的计算
|
|
28
|
-
if (typeof val === 'number' && val > 0) {
|
|
29
|
-
return val * 60 * 1000
|
|
30
|
-
}
|
|
31
|
-
return 30 * 60 * 1000
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
authenticate(req, options) {
|
|
35
|
-
// 检查必要的cookie
|
|
36
|
-
const hasRequiredCookies =
|
|
37
|
-
req.cookies &&
|
|
38
|
-
req.cookies.get('idsrv.session') &&
|
|
39
|
-
req.cookies.get('.AspNetCore.Identity.Application')
|
|
40
|
-
|
|
41
|
-
// 检查必要的header
|
|
42
|
-
const hasRequiredHeaders =
|
|
43
|
-
req.headers && (req.headers.authtoken || req.headers.authorization)
|
|
44
|
-
|
|
45
|
-
// 假如不存在 则认证失败
|
|
46
|
-
if (!hasRequiredCookies && !(this.handleHeadrToken && hasRequiredHeaders)) {
|
|
47
|
-
return this.fail(new Error('Missing required cookies or headers'))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (this.handleHeadrToken && hasRequiredHeaders) {
|
|
51
|
-
this.executeCosplayAuthentication(req)
|
|
52
|
-
.then((user) => {
|
|
53
|
-
this.success(user)
|
|
54
|
-
})
|
|
55
|
-
.catch((err) => {
|
|
56
|
-
if (err.message === '__goto_next__') {
|
|
57
|
-
this.pass()
|
|
58
|
-
} else {
|
|
59
|
-
this.error(err)
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
} else if (hasRequiredCookies) {
|
|
63
|
-
// 否则 执行认证流程
|
|
64
|
-
this.executeAuthentication(req)
|
|
65
|
-
.then((user) =>
|
|
66
|
-
// 创建策略时 可传入回调函数 已追加认证逻辑
|
|
67
|
-
this.verify(user, (err, verifiedUser) => {
|
|
68
|
-
if (err) return this.error(err)
|
|
69
|
-
this.success(verifiedUser)
|
|
70
|
-
}),
|
|
71
|
-
)
|
|
72
|
-
.catch((err) => {
|
|
73
|
-
if (err.message === '__goto_next__') {
|
|
74
|
-
this.pass()
|
|
75
|
-
} else {
|
|
76
|
-
this.error(err)
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
} else {
|
|
80
|
-
this.pass()
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async executeCosplayAuthentication(req) {
|
|
85
|
-
// 以Bearer开始的 为Authorization头 否则为Authtoken头
|
|
86
|
-
let token = ''
|
|
87
|
-
let isAuthorization = false
|
|
88
|
-
if (req.headers?.authtoken) {
|
|
89
|
-
token = req.headers.authtoken
|
|
90
|
-
} else if (req.headers?.authorization) {
|
|
91
|
-
token = req.headers.authorization.replace('Bearer ', '')
|
|
92
|
-
isAuthorization = true
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const su = req?.session?.passport?.user || {}
|
|
96
|
-
if (su.token?.access_token === token) {
|
|
97
|
-
throw new Error('__goto_next__')
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 假如session里面没有不是该token说明换了 需要重新获取
|
|
101
|
-
su.info = null
|
|
102
|
-
const userInfo = await this.getUserInfoWithRefresh(
|
|
103
|
-
(isAuthorization ? 'Bearer ' : '') + token,
|
|
104
|
-
req,
|
|
105
|
-
{},
|
|
106
|
-
)
|
|
107
|
-
if (userInfo) {
|
|
108
|
-
debugLogger(
|
|
109
|
-
`通过${isAuthorization ? 'Authorization' : 'Authtoken'}头信息登录系统`,
|
|
110
|
-
)
|
|
111
|
-
if (isAuthorization) {
|
|
112
|
-
return {
|
|
113
|
-
token: {
|
|
114
|
-
token_type: 'Bearer',
|
|
115
|
-
access_token: token,
|
|
116
|
-
expires_at: (Date.now() / 1000 + 4 * 600) | 0,
|
|
117
|
-
},
|
|
118
|
-
info: userInfo,
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
return {
|
|
122
|
-
token: {
|
|
123
|
-
bjx_token_flag: 'This token from authtoken/authorization header',
|
|
124
|
-
token_type: '',
|
|
125
|
-
access_token: token,
|
|
126
|
-
expires_at: (Date.now() / 1000 + 4 * 600) | 0,
|
|
127
|
-
},
|
|
128
|
-
info: userInfo,
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
throw new Error('Invalid headers token')
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async executeAuthentication(req) {
|
|
137
|
-
// 获取请求头信息
|
|
138
|
-
const headers = this.extractHeaders(req)
|
|
139
|
-
|
|
140
|
-
// 获取cookie
|
|
141
|
-
const cookies = {
|
|
142
|
-
'idsrv.session': req.cookies.get('idsrv.session'),
|
|
143
|
-
'.AspNetCore.Identity.Application': req.cookies.get(
|
|
144
|
-
'.AspNetCore.Identity.Application',
|
|
145
|
-
),
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 获取令牌 不存在时直接抛出错误
|
|
149
|
-
const tokenData = await this.getTokenWithRefresh(cookies, req, headers)
|
|
150
|
-
if (!tokenData) throw new Error('Get token failed')
|
|
151
|
-
|
|
152
|
-
// 获取用户信息 假如配置中为false 则不获取
|
|
153
|
-
let userInfo
|
|
154
|
-
if (this.loadUserInfo) {
|
|
155
|
-
const token = tokenData.access_token
|
|
156
|
-
userInfo = await this.getUserInfoWithRefresh(token, req, headers)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
token: tokenData,
|
|
161
|
-
info: userInfo,
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
extractHeaders(req) {
|
|
166
|
-
return {
|
|
167
|
-
'X-Forwarded-For': req.headers['x-forwarded-for'],
|
|
168
|
-
'X-Forwarded-Host': req.headers['x-forwarded-host'],
|
|
169
|
-
'User-Agent': req.headers['user-agent'],
|
|
170
|
-
Referer: req.headers['referer'],
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
async getTokenWithRefresh(cookies, req, headers) {
|
|
175
|
-
const su = req?.session?.passport?.user || {}
|
|
176
|
-
const now = Date.now()
|
|
177
|
-
|
|
178
|
-
// 判断token的标识和cookie中的标识是否一致
|
|
179
|
-
if (su.token?.bjx_token_flag !== cookies['idsrv.session']) {
|
|
180
|
-
su.token = undefined
|
|
181
|
-
su.info = undefined
|
|
182
|
-
debugLogger('令牌标识和cookie内的不一致')
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// 检查passport中的令牌 是否需要刷新
|
|
186
|
-
if (su.token && su.token.expires_at * 1000 > now) {
|
|
187
|
-
throw new Error('__goto_next__')
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// 假如存在token 还到这一步 说明是刷新token
|
|
191
|
-
const isRefresh = !!su.token
|
|
192
|
-
if (isRefresh) {
|
|
193
|
-
debugLogger('更新令牌')
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// 获取新token
|
|
197
|
-
const newToken = await getToken(cookies, isRefresh, {
|
|
198
|
-
ctx: req.ctx,
|
|
199
|
-
headers,
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
debugLogger('获取“新”令牌', cookies, isRefresh, newToken || '无')
|
|
203
|
-
return newToken
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async getUserInfoWithRefresh(token, req, headers) {
|
|
207
|
-
const su = req?.session?.passport?.user || {}
|
|
208
|
-
const now = Date.now()
|
|
209
|
-
|
|
210
|
-
// 检查passport中的用户信息 是否需要刷新
|
|
211
|
-
if (su.info && su.info.__expires_at__ > now) {
|
|
212
|
-
throw new Error('__goto_next__')
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// 获取新用户信息
|
|
216
|
-
const newUserInfo = await getUserInfo(token, this.userInfoType, {
|
|
217
|
-
ctx: req.ctx,
|
|
218
|
-
headers,
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
// 设置用户信息的过期时间 这里用毫秒
|
|
222
|
-
if (newUserInfo) {
|
|
223
|
-
newUserInfo.__expires_at__ = now + this.userInfoDuration
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
debugLogger('获取“新”用户信息', token, newUserInfo || '无')
|
|
227
|
-
return newUserInfo
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Koa中间件
|
|
232
|
-
function createBjxAuthMiddleware(passport) {
|
|
233
|
-
return async (ctx, next) => {
|
|
234
|
-
await new Promise((resolve) => {
|
|
235
|
-
passport.authenticate('bjx', (err, user, info, status) => {
|
|
236
|
-
if (err) {
|
|
237
|
-
// this.error()
|
|
238
|
-
errorLogger(err)
|
|
239
|
-
ctx.logout()
|
|
240
|
-
} else if (user) {
|
|
241
|
-
// this.success()
|
|
242
|
-
ctx.login(user)
|
|
243
|
-
} else {
|
|
244
|
-
// this.fail()
|
|
245
|
-
ctx.logout()
|
|
246
|
-
}
|
|
247
|
-
resolve()
|
|
248
|
-
})(ctx, () => {
|
|
249
|
-
// this.pass()
|
|
250
|
-
resolve()
|
|
251
|
-
})
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
await next()
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
module.exports = {
|
|
259
|
-
BjxStrategy,
|
|
260
|
-
createBjxAuthMiddleware,
|
|
261
|
-
}
|
package/src/strategy/utils.js
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
const config = require('../config')
|
|
2
|
-
|
|
3
|
-
function objToQs(obj) {
|
|
4
|
-
if (!obj || Object.keys(obj).length === 0) return ''
|
|
5
|
-
const params = []
|
|
6
|
-
for (const key in obj) {
|
|
7
|
-
if (obj[key]) {
|
|
8
|
-
params.push(`${key}=${encodeURIComponent(obj[key])}`)
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return params.join('&')
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function hostToSite(host) {
|
|
15
|
-
const map = {
|
|
16
|
-
hr: 30000,
|
|
17
|
-
|
|
18
|
-
dljob: 30100,
|
|
19
|
-
hdjob: 30101,
|
|
20
|
-
fdjob: 30102,
|
|
21
|
-
sdjob: 30103,
|
|
22
|
-
hedjob: 30104,
|
|
23
|
-
gfjob: 30105,
|
|
24
|
-
zhnyfwjob: 30106,
|
|
25
|
-
shdjob: 30107,
|
|
26
|
-
tanjob: 30108,
|
|
27
|
-
qnjob: 30109,
|
|
28
|
-
|
|
29
|
-
dqjob: 30200,
|
|
30
|
-
cnjob: 30201,
|
|
31
|
-
spdjob: 30202,
|
|
32
|
-
zdhjob: 30203,
|
|
33
|
-
xxhjob: 30204,
|
|
34
|
-
|
|
35
|
-
hbjob: 30300,
|
|
36
|
-
scljob: 30301,
|
|
37
|
-
gfcljob: 30302,
|
|
38
|
-
dqzljob: 30303,
|
|
39
|
-
jchpjob: 30304,
|
|
40
|
-
hbfdjob: 30305,
|
|
41
|
-
hbgcjob: 30306,
|
|
42
|
-
hbsbjob: 30307,
|
|
43
|
-
hjxfjob: 30308,
|
|
44
|
-
jnjob: 30309,
|
|
45
|
-
|
|
46
|
-
gcjob: 30400,
|
|
47
|
-
dlgcjob: 30401,
|
|
48
|
-
jzjob: 30402,
|
|
49
|
-
szlqjob: 30403,
|
|
50
|
-
gdjob: 30404,
|
|
51
|
-
jdjob: 30406,
|
|
52
|
-
sjjob: 30407,
|
|
53
|
-
jljob: 30408,
|
|
54
|
-
gczjjob: 30409,
|
|
55
|
-
|
|
56
|
-
dcjob: 30500,
|
|
57
|
-
dcscjob: 30501,
|
|
58
|
-
dcyyjob: 30502,
|
|
59
|
-
dccljob: 30503,
|
|
60
|
-
dchsjob: 30504,
|
|
61
|
-
dcjsjob: 30507,
|
|
62
|
-
|
|
63
|
-
spdsbjob: 30601,
|
|
64
|
-
pdywjob: 30602,
|
|
65
|
-
pwpdgcjob: 30603,
|
|
66
|
-
znwdwjob: 30604,
|
|
67
|
-
zlpdwjob: 30605,
|
|
68
|
-
xndcjob: 30606,
|
|
69
|
-
|
|
70
|
-
dlscjob: 30700,
|
|
71
|
-
|
|
72
|
-
mhr: 40000,
|
|
73
|
-
|
|
74
|
-
mdljob: 40100,
|
|
75
|
-
mhdjob: 40101,
|
|
76
|
-
mfdjob: 40102,
|
|
77
|
-
msdjob: 40103,
|
|
78
|
-
mhedjob: 40104,
|
|
79
|
-
mgfjob: 40105,
|
|
80
|
-
mzhnyfwjob: 40106,
|
|
81
|
-
mshdjob: 40107,
|
|
82
|
-
mtanjob: 40108,
|
|
83
|
-
mqnjob: 40109,
|
|
84
|
-
|
|
85
|
-
mdqjob: 40200,
|
|
86
|
-
mcnjob: 40201,
|
|
87
|
-
mspdjob: 40202,
|
|
88
|
-
mzdhjob: 40203,
|
|
89
|
-
mxxhjob: 40204,
|
|
90
|
-
|
|
91
|
-
mhbjob: 40300,
|
|
92
|
-
mscljob: 40301,
|
|
93
|
-
mgfcljob: 40302,
|
|
94
|
-
mdqzljob: 40303,
|
|
95
|
-
mjchpjob: 40304,
|
|
96
|
-
mhbfdjob: 40305,
|
|
97
|
-
mhbgcjob: 40306,
|
|
98
|
-
mhbsbjob: 40307,
|
|
99
|
-
mhjxfjob: 40308,
|
|
100
|
-
mjnjob: 40309,
|
|
101
|
-
|
|
102
|
-
mgcjob: 40400,
|
|
103
|
-
mdlgcjob: 40401,
|
|
104
|
-
mjzjob: 40402,
|
|
105
|
-
mszlqjob: 40403,
|
|
106
|
-
mgdjob: 40404,
|
|
107
|
-
mjdjob: 40406,
|
|
108
|
-
msjjob: 40407,
|
|
109
|
-
mjljob: 40408,
|
|
110
|
-
mgczjjob: 40409,
|
|
111
|
-
|
|
112
|
-
mdcjob: 40500,
|
|
113
|
-
mdcscjob: 40501,
|
|
114
|
-
mdcyyjob: 40502,
|
|
115
|
-
mdccljob: 40503,
|
|
116
|
-
mdchsjob: 40504,
|
|
117
|
-
mdcjsjob: 40507,
|
|
118
|
-
|
|
119
|
-
mspdsbjob: 40601,
|
|
120
|
-
mpdywjob: 40602,
|
|
121
|
-
mpwpdgcjob: 40603,
|
|
122
|
-
mznwdwjob: 40604,
|
|
123
|
-
mzlpdwjob: 40605,
|
|
124
|
-
mxndcjob: 40606,
|
|
125
|
-
|
|
126
|
-
mdlscjob: 40700,
|
|
127
|
-
|
|
128
|
-
yun: 3099,
|
|
129
|
-
yun: 30991,
|
|
130
|
-
yun: 30992,
|
|
131
|
-
yun: 30993,
|
|
132
|
-
yun: 30994,
|
|
133
|
-
yun: 30995,
|
|
134
|
-
yun: 30996,
|
|
135
|
-
sxh: 3094,
|
|
136
|
-
msxh: 3093,
|
|
137
|
-
xiaoyuan: 3091,
|
|
138
|
-
mxiaoyuan: 4091,
|
|
139
|
-
xxsxh: 3090,
|
|
140
|
-
mxxsxh: 4090,
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
for (const k in map) {
|
|
144
|
-
if (host.includes(k)) return k + '.bjx.com.cn'
|
|
145
|
-
if (host.includes(map[k])) return k + '.bjx.com.cn'
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return 'hr.bjx.com.cn'
|
|
149
|
-
}
|
|
150
|
-
function handleCtx(ctx, needSite) {
|
|
151
|
-
let f = ctx.query.f || ''
|
|
152
|
-
const origin = ctx.origin
|
|
153
|
-
const originReg = new RegExp('^' + origin)
|
|
154
|
-
const rootReg = /^\//
|
|
155
|
-
if (rootReg.test(f)) {
|
|
156
|
-
f = origin + f
|
|
157
|
-
} else if (f && !originReg.test(f)) {
|
|
158
|
-
f = origin
|
|
159
|
-
} else if (!f) {
|
|
160
|
-
const referer = ctx.headers['referer']
|
|
161
|
-
if (originReg.test(referer) && referer !== ctx.href) {
|
|
162
|
-
f = referer
|
|
163
|
-
} else {
|
|
164
|
-
f = origin
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const obj = {
|
|
169
|
-
returnUrl: f,
|
|
170
|
-
}
|
|
171
|
-
if (needSite) {
|
|
172
|
-
const fHost = f.replace(/^https?:\/\//, '').replace(/\/.*/, '')
|
|
173
|
-
obj.site = hostToSite(fHost)
|
|
174
|
-
}
|
|
175
|
-
return obj
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function getLoginCenterUrl(opts, type = '') {
|
|
179
|
-
const {
|
|
180
|
-
ctx,
|
|
181
|
-
site = '',
|
|
182
|
-
returnUrl = '',
|
|
183
|
-
BA = '',
|
|
184
|
-
BP = '',
|
|
185
|
-
OS = '',
|
|
186
|
-
EQP = '',
|
|
187
|
-
...otherQueryParams
|
|
188
|
-
} = opts || {}
|
|
189
|
-
if (!site && !ctx) throw new Error('site is required')
|
|
190
|
-
if (!returnUrl && !ctx) throw new Error('returnUrl is required')
|
|
191
|
-
|
|
192
|
-
const { clientId, login: loginCenter } = config
|
|
193
|
-
|
|
194
|
-
const pp = objToQs({
|
|
195
|
-
BA: BA || ctx?.query?.ba || config.ba || '',
|
|
196
|
-
BP: BP || ctx?.query?.bp || config.bp || '',
|
|
197
|
-
OS: OS || config.os || 1,
|
|
198
|
-
EQP: EQP || config.eqp || '',
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
let sr
|
|
202
|
-
if (ctx && (!site || !returnUrl)) {
|
|
203
|
-
sr = handleCtx(ctx, !site)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const qs = {
|
|
207
|
-
site: site ? site : sr.site,
|
|
208
|
-
clientId,
|
|
209
|
-
pp,
|
|
210
|
-
...otherQueryParams,
|
|
211
|
-
returnUrl: returnUrl ? returnUrl : sr.returnUrl,
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const qsStr = objToQs(qs)
|
|
215
|
-
const login = `/Account/Login?${qsStr}`
|
|
216
|
-
const register = `/Account/Register?${qsStr}`
|
|
217
|
-
const logout = `/Account/Logout?${qsStr}`
|
|
218
|
-
const bind = `/External/UserBind?${qsStr}`
|
|
219
|
-
const logout2 = `/Account/Logout?${
|
|
220
|
-
qsStr.replace('returnUrl=.+$', '') + encodeURIComponent(login)
|
|
221
|
-
}`
|
|
222
|
-
const paths = {
|
|
223
|
-
login,
|
|
224
|
-
register,
|
|
225
|
-
logout,
|
|
226
|
-
bind,
|
|
227
|
-
logout2,
|
|
228
|
-
}
|
|
229
|
-
const urls = {
|
|
230
|
-
login: `${loginCenter}${paths.login}`,
|
|
231
|
-
register: `${loginCenter}${paths.register}`,
|
|
232
|
-
logout: `${loginCenter}${paths.logout}`,
|
|
233
|
-
bind: `${loginCenter}${paths.bind}`,
|
|
234
|
-
logout2: `${loginCenter}${paths.logout2}`,
|
|
235
|
-
returnUrl: sr.returnUrl,
|
|
236
|
-
}
|
|
237
|
-
if (!type) {
|
|
238
|
-
return urls
|
|
239
|
-
} else {
|
|
240
|
-
let typeArr = []
|
|
241
|
-
if (Array.isArray(type)) {
|
|
242
|
-
typeArr = type
|
|
243
|
-
} else if (typeof type === 'string') {
|
|
244
|
-
typeArr = type.split(',').map((v) => v.trim())
|
|
245
|
-
}
|
|
246
|
-
if (!typeArr.length) {
|
|
247
|
-
return urls
|
|
248
|
-
}
|
|
249
|
-
const obj = {}
|
|
250
|
-
typeArr.forEach((item) => {
|
|
251
|
-
const url = urls[item]
|
|
252
|
-
if (url) {
|
|
253
|
-
obj[item] = url
|
|
254
|
-
}
|
|
255
|
-
})
|
|
256
|
-
if (Object.keys(obj).length === 1) {
|
|
257
|
-
return Object.values(obj)[0]
|
|
258
|
-
} else if (Object.keys(obj).length) {
|
|
259
|
-
return obj
|
|
260
|
-
} else {
|
|
261
|
-
return urls
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
module.exports = {
|
|
267
|
-
getLoginCenterUrl,
|
|
268
|
-
}
|