bjx-auth 1.3.0 → 1.5.1

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.
@@ -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
- }