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
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! version: 1.4.0 */
|
|
2
|
+
"use strict";var e=require("crypto"),t=require("axios");var r,n={exports:{}},a={exports:{}};function o(){return r||(r=1,function(e){const t={eqp:"00000000-0000-0000-0000-000000000000",os:"",ba:"",bp:"",ver:"8.0.0",clientId:"",clientSecret:"",apiVersion:"",signVersion:"",signKey:"",passportapi:"",login:"",auth:"",enterpriseapi:"",debug:!1,debugApiUrl:"",app:null};function r(e,r){void 0!==t[e]&&(t[e]=r)}const n={getConfig:function(e){return e?t[e]:t},setConfig:async function(e,t){if("object"==typeof e)for(const t in e)r(t,e[t]);else e&&r(e,t)}};Object.keys(t).forEach(e=>{Object.defineProperty(n,e,{get:()=>t[e],enumerable:!0})}),e.exports=n}(a)),a.exports}var i,s,u,c,p={exports:{}},d={exports:{}},l={exports:{}};function f(){if(u)return s;let t;return u=1,i||(i=1,function(){const t=e;l.exports={hashHS256:function(e,r){return t.createHmac("sha256",r).update(e).digest("base64")},hashMD5:function(e){return t.createHash("md5").update(e).digest("hex").toUpperCase()}}}()),t=l.exports,s=t}function b(){return c||(c=1,function(e){const{hashHS256:t}=f(),r=o();function n(e){return"[object Object]"===Object.prototype.toString.call(e)?Object.keys(e).sort().reduce((t,r)=>(t[r]=n(e[r]),t),{}):"[object Array]"===Object.prototype.toString.call(e)?e.map(e=>n(e)):e}function a(e,r){const a=function(e){let t=[];return Object.entries(e).map(([e,r])=>{void 0===r||""===r||null===r||("[object Array]"===Object.prototype.toString.call(r)||"[object Object]"===Object.prototype.toString.call(r)?t.push(`${e}=${encodeURIComponent(JSON.stringify(r))}`):t.push(`${e}=${encodeURIComponent(r)}`))}),t.join("&")}(n(e)),o=t(a,r);return{...e,sign:o}}e.exports=function(e,t){const{eqp:n,os:o,ba:i,bp:s,ver:u,apiVersion:c,signVersion:p,clientId:d,clientSecret:l,data:f={}}=e||{};return a({eqp:n||r.eqp||"",os:1*o||1*r.os||1,ba:i||r.ba||"",bp:s||r.bp||"",ver:u||r.ver||"1.0.0",ts:Date.now(),apiVersion:c||r.apiVersion||"1.0.0",signVersion:p||r.signVersion||"V1",clientId:d||r.clientId||"",clientSecret:l||r.clientSecret||"",data:f},t=t||r.signKey)}}(d)),d.exports}var g,h,S,y={exports:{}},w={exports:{}},m={exports:{}},P={exports:{}};function x(){return g||(g=1,function(e){const t=o();e.exports={errorLogger:function(...e){console.error(...e)},debugLogger:function(...e){t.debug&&console.debug(...e)}}}(P)),P.exports}function O(){return h||(h=1,function(e){const r=t,n=o(),{debugLogger:a}=x(),i=r.create({withCredentials:!1,timeout:1e4});i.interceptors.request.use(e=>(e.baseURL||(e.baseURL=n.passportapi||""),n.debugApiUrl?.includes(e.url)&&a(e),e)),i.interceptors.response.use(e=>e);const s=r.create({timeout:1e4});s.interceptors.request.use(e=>(e.baseURL||(e.baseURL=n.auth||""),n.debugApiUrl?.includes(e.url)&&a(e),e)),s.interceptors.response.use(e=>e);const u=r.create({timeout:1e4});u.interceptors.request.use(e=>(e.baseURL||(e.baseURL=n.newapi2||""),n.debugApiUrl?.includes(e.url)&&a(e),e)),u.interceptors.response.use(e=>e);const c=r.create({timeout:1e4});c.interceptors.request.use(e=>(e.baseURL||(e.baseURL=n.enterpriseapi||""),n.debugApiUrl?.includes(e.url)&&a(e),e)),c.interceptors.response.use(e=>e),e.exports={passportapi:i,auth:s,newapi2:u,enterpriseapi:c}}(m)),m.exports}function v(){return S||(S=1,function(e){const t=b(),{passportapi:r}=O(),{errorLogger:n}=x();let a=null;e.exports={getPublicPem:async function(){if(a&&a.expiresAt>Date.now())return a.value;let e=t();try{const{data:t}=await r({url:"/api/v1/common/config/security",method:"POST",data:e});if(!1===t.isError)return a={value:`-----BEGIN PUBLIC KEY-----\n${t.data.rsaPubkey}\n-----END PUBLIC KEY-----`,expiresAt:Date.now()+288e5},a.value;throw new Error(t.error)}catch(e){n(e)}},clearPublicPemCache:function(){a=null},hasPublicPemCache:function(){return!!a}}}(w)),w.exports}var I,C,q,B,E={exports:{}};function A(){if(q)return C;let t;return q=1,I||(I=1,function(){const t=e;E.exports={encryptRSA:function(e,r){if(!r)throw new Error("publicPem is required");const n=Buffer.from(e,"utf8");return t.publicEncrypt({key:r,padding:t.constants.RSA_PKCS1_PADDING},n).toString("base64")},encryptAES:function(e){const r=t.randomBytes(16),n=r,a=t.createCipheriv("aes-128-cbc",n,r);let o=a.update(e,"utf8","base64");return o+=a.final("base64"),{iv:r.toString("hex"),encrypted:o}}}}()),t=E.exports,C=t}function T(){return B||(B=1,function(e){const{getPublicPem:t}=v(),{encryptRSA:r,encryptAES:n}=A();e.exports=async function(e){if(!e)throw new Error("data is required");const a=await t(),o=JSON.stringify(e),{encrypted:i,iv:s}=n(o);return{akaParams:i,secretKey:r(s,a)}}}(y)),y.exports}var U,k,j={exports:{}};function R(){return U||(U=1,function(e){const{hashMD5:t}=f(),r=o();e.exports={getReqSign:function(e,...n){"string"==typeof e&&(e={EQP:e||"",OS:n[0]||"",BA:n[1]||"",BP:n[2]||""});let{EQP:a,OS:o,BA:i,BP:s,Ver:u,ctx:c}=e||{};c&&(a||(a=c.uuid),o||(o=c.isMobi?2:1),i||(i=c.query.ba),s||(s=c.query.bp));const p={EQP:a||r.eqp||"",OS:o||1*r.os||1,BA:i||r.ba||"",BP:s||r.bp||"",Ver:u||r.ver||"1.0.0",TS:Date.now()},d=t(`EQP=${p.EQP}&OS=${p.OS}&BA=${p.BA}&BP=${p.BP}&Ver=${p.Ver}&TS=${p.TS}+bjxstat2019`).toUpperCase();return Object.assign(p,{Sign:d})},getReqSign2:function(e,...n){"string"==typeof e&&(e={EQP:e||"",OS:n[0]||"",BA:n[1]||"",BP:n[2]||"",XAppId:n[3]||""});let{EQP:a,OS:o,BA:i,BP:s,Ver:u,XAppId:c,ctx:p}=e||{};p&&(a||(a=p.uuid),o||(o=p.isMobi?2:1),i||(i=p.query.ba),s||(s=p.query.bp));const d={EQP:a||r.eqp||"",OS:o||1*r.os||1,BA:i||r.ba||"",BP:s||r.bp||"",Ver:u||r.ver||"1.0.0",TS:Date.now(),XAppId:c||r.clientId||""},l=t(`EQP=${d.EQP}&OS=${d.OS}&BA=${d.BA}&BP=${d.BP}&Ver=${d.Ver}&TS=${d.TS}&XAppId=${d.XAppId}+%SiGn2021!@#`).toUpperCase();return Object.assign(d,{Sign:l})}}}(j)),j.exports}function _(){return k||(k=1,function(e){const t=b(),r=T(),n=R();e.exports={reqSign:t,reqEncrypt:r,getReqBody:async function(e,n,a){let{eqp:o="",os:i="",ba:s="",bp:u="",ver:c="",apiVersion:p="",signVersion:d="",clientId:l="",clientSecret:f="",ctx:b}=a||{};b&&(o||(o=b.uuid),i||(o=b.isMobi?2:1),s||(s=b.query.ba),u||(u=b.query.bp));const g={eqp:o,os:i,ba:s,bp:u,ver:c,apiVersion:p,signVersion:d,clientId:l,clientSecret:f};return n&&e&&Object.keys(e).length>0?g.data=await r(e):g.data=e||{},t(g)},...n}}(p)),p.exports}var V,L={exports:{}};function $(){return V||(V=1,function(e){const{passportapi:t}=O(),{getReqBody:r}=_();e.exports={getToken:async function(e,n){return e.__isRefresh__?async function(e,n={}){return e.data=await r(null,!1,n),t({url:"/api/v1/token/refresh/web",method:"POST",...e})}(e,n):async function(e,n={}){return e.data=await r(null,!1,n),t({url:"/api/v1/token/web",method:"POST",...e})}(e,n)},loginSms:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/login/sms/web",method:"POST",...e})},loginPwd:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/login/pwd/web",method:"POST",...e})},registerSms:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/register/sms/web",method:"POST",...e})},logout:async function(e,n={}){return e.data=await r(null,!1,n),t({url:"/api/v1/logout/web",method:"POST",...e})},loginSmsQuick:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/login/sms/quick/web",method:"POST",...e})},userBusmold:async function(e,n={}){return e.data=await r(e.data,!1,n),t({url:"/api/v1/user/busmold/seekers/set",method:"POST",...e})},userExist:async function(e,n={}){return e.data=await r(e.data,!1,n),t({url:"/api/v1/user/exist/phone",method:"POST",...e})},pwdResetVerify:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/user/pwd/reset/verify",method:"POST",...e})},pwdReset:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/user/pwd/reset",method:"POST",...e})},wxpubCode:async function(e,n={}){return e.data=await r(e.data,!1,n),t({url:"/api/v1/wechat/wxpub/qrcode",method:"POST",...e})},wxpubScan:async function(e,n={}){return e.data=await r(e.data,!1,n),t({url:"/api/v1/wechat/wxpub/scan/login",method:"POST",...e})},wxpubBindLogin:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/wechat/wxpub/scan/bindlogin",method:"POST",...e})},wxpubH5Code:async function(e,n={}){return e.data=await r(e.data,!1,n),t({url:"/api/v1/wechat/wxpub/h5/getcode",method:"POST",...e})},wxpubH5BindLogin:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/wechat/wxpub/h5/bindlogin",method:"POST",...e})},webappCode:async function(e,n={}){return e.data=await r(e.data,!1,n),t({url:"/api/v1/wechat/webapp/code",method:"POST",...e})},webappBindLogin:async function(e,n={}){return e.data=await r(e.data,!0,n),t({url:"/api/v1/wechat/webapp/bindlogin",method:"POST",...e})}}}(L)),L.exports}var D,N,Q={exports:{}};function H(){return D||(D=1,function(e){const{auth:t,enterpriseapi:r}=O(),{getReqSign:n}=_();e.exports={getUserInfo:async function(e,a){const o=["BaseInfo","BaseInfoV1","ExtendInfo","userInfo"];return o.includes(e.__type__)||(e.__type__=o[0]),"userInfo"===e.__type__?async function(e,t={}){return e.data={...e.data,...n(t)},r({url:"/enterprise/user/userInfo",method:"POST",...e}).then(e=>{const{data:t}=e;return e.data={HttpStatusCode:t.code,Error:t.errMsg,IsError:!t.success,Data:t.data&&Object.keys(t.data).length?{HasCompany:t.data.hasCompanyState>0,Id:t.data.id||"",UId:t.data.userId||0,UserName:t.data.userName||"",NickName:t.data.nickName||"",Email:t.data.userEmail||"",EmailIsCheck:t.data.emailCheckState>0,RegionCode:t.data.regionCode||"",Phone:t.data.userPhone||"",PhoneIsCheck:t.data.phoneCheckState>0,HeadUrl:t.data.headUrl||"",BackImage:t.data.backImage||"",BriefIntro:t.data.briefIntro||"",Industry:t.data.industryId||0,Source:t.data.registerSource||0,ShowName:t.data.showName||"",HeadIsDef:t.data.headDefState>0,Nick:t.data.nick||"",NickShowName:t.data.nickShowName||"",RegDate:t.data.registerDate||""}:{}},e})}(e,a):async function(e,r={}){return e.data={...e.data,...n(r)},t({url:"/api/User/"+e.__type__,method:"POST",...e})}(e,a)}}}(Q)),Q.exports}exports.getDefaultExportFromCjs=function(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e},exports.requireConfig=o,exports.requireLogger=x,exports.requireRequest=function(){return N||(N=1,function(e){const{setConfig:t,getConfig:r}=o(),n=_(),a=$(),i=H(),{clearPublicPemCache:s,hasPublicPemCache:u}=v();e.exports=Object.assign({setConfig:t,getConfig:r,clearPublicPemCache:s,hasPublicPemCache:u},n,a,i)}(n)),n.exports};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! version: 1.4.0 */
|
|
2
|
+
"use strict";var e=require("./index-Doi37tmx.js"),o=require("passport");require("crypto"),require("axios");var t,r,n,s,i,a,c,h={exports:{}};function u(){if(s)return n;s=1;const{Strategy:i}=o,{setConfig:a,getConfig:c,getToken:h,getUserInfo:u}=function(){if(r)return t;r=1;const{setConfig:o,getConfig:n,getToken:s,getUserInfo:i}=e.requireRequest();return t={setConfig:o,getConfig:n,getToken:async function(e,o,{headers:t,ctx:r}){return s({__isRefresh__:o,headers:{Cookie:Object.entries(e).map(e=>e.join("=")).join("; "),...t}},{ctx:r}).then(({data:o})=>{if(!1===o.isError)return{bjx_token_flag:e["idsrv.session"],token_type:"",access_token:o.data.authToken,expires_at:o.data.expiresAt||Date.now()/1e3+14400|0}})},getUserInfo:async function(e,o,{headers:t,ctx:r}){const n={};return e.startsWith("Bearer ")?n.Authorization=e:n.AuthToken=e,i({__type__:o,headers:{...t,...n}},{ctx:r}).then(({data:e})=>{if(!1===e.IsError)return e.Data})}}}(),{errorLogger:j,debugLogger:d}=e.requireLogger();return n={BjxStrategy:class extends i{constructor(e={},o){super(),this.name="bjx",this.loadUserInfo=e.loadUserInfo||!1,this.userInfoDuration=this.normalizeDuration(e.loadUserInfo),this.userInfoType=e.userInfoType||"",this.handleHeadrToken=e.handleHeadrToken||!1,this.verify=o||((e,o)=>o(null,e)),a(e.authConfig),e.authConfig.debug&&d("配置项",c())}normalizeDuration(e){return"number"==typeof e&&e>0?60*e*1e3:18e5}authenticate(e,o){const t=e.cookies&&e.cookies.get("idsrv.session")&&e.cookies.get(".AspNetCore.Identity.Application"),r=e.headers&&(e.headers.authtoken||e.headers.authorization);if(!(t||this.handleHeadrToken&&r))return d("认证失败",t,"(",this.handleHeadrToken,r,")"),this.fail();this.handleHeadrToken&&r?this.executeCosplayAuthentication(e).then(e=>{this.success(e)}).catch(e=>{"__goto_next__"===e.message?this.pass():this.error(e)}):t?this.executeAuthentication(e).then(e=>this.verify(e,(e,o)=>{if(e)return this.error(e);this.success(o)})).catch(e=>{"__goto_next__"===e.message?this.pass():this.error(e)}):this.pass()}async executeCosplayAuthentication(e){let o="",t=!1;e.headers?.authtoken?o=e.headers.authtoken:e.headers?.authorization&&(o=e.headers.authorization.replace("Bearer ",""),t=!0);const r=e?.session?.passport?.user||{};if(r.token?.access_token===o)throw new Error("__goto_next__");r.info=null;const n=await this.getUserInfoWithRefresh((t?"Bearer ":"")+o,e,{});if(n)return d(`通过${t?"Authorization":"Authtoken"}头信息登录系统`),t?{token:{token_type:"Bearer",access_token:o,expires_at:Date.now()/1e3+2400|0},info:n}:{token:{bjx_token_flag:"This token from authtoken/authorization header",token_type:"",access_token:o,expires_at:Date.now()/1e3+2400|0},info:n};throw new Error("Invalid headers token")}async executeAuthentication(e){const o=this.extractHeaders(e),t={"idsrv.session":e.cookies.get("idsrv.session"),".AspNetCore.Identity.Application":e.cookies.get(".AspNetCore.Identity.Application")},r=await this.getTokenWithRefresh(t,e,o);if(!r)throw new Error("Get token failed");let n;if(this.loadUserInfo){const t=r.access_token;n=await this.getUserInfoWithRefresh(t,e,o)}return{token:r,info:n}}extractHeaders(e){return{"X-Forwarded-For":e.headers["x-forwarded-for"],"X-Forwarded-Host":e.headers["x-forwarded-host"],"User-Agent":e.headers["user-agent"],Referer:e.headers.referer}}async getTokenWithRefresh(e,o,t){const r=o?.session?.passport?.user||{},n=Date.now();if(r.token?.bjx_token_flag!==e["idsrv.session"]&&(r.token=void 0,r.info=void 0,d("令牌标识和cookie内的不一致")),r.token&&1e3*r.token.expires_at>n)throw new Error("__goto_next__");const s=!!r.token;s&&d("刷新令牌");const i=await h(e,s,{ctx:o.ctx,headers:t});return d("获取“新”令牌",e,s,i||"无"),i}async getUserInfoWithRefresh(e,o,t){const r=o?.session?.passport?.user||{},n=Date.now();if(r.info&&r.info.__expires_at__>n)throw new Error("__goto_next__");const s=await u(e,this.userInfoType,{ctx:o.ctx,headers:t});return s&&(s.__expires_at__=n+this.userInfoDuration),d("获取“新”用户信息",e,s||"无"),s}},createBjxAuthMiddleware:function(e){return async(o,t)=>{c("app")||a("app",o.app),await new Promise(t=>{e.authenticate("bjx",(e,r,n,s)=>{e?(j(e),o.logout()):r?o.login(r):o.logout(),t()})(o,()=>{t()})}),await t()}}}}function j(){if(a)return i;a=1;const o=e.requireConfig();function t(e){if(!e||0===Object.keys(e).length)return"";const o=[];for(const t in e)e[t]&&o.push(`${t}=${encodeURIComponent(e[t])}`);return o.join("&")}return i={getLoginCenterUrl:function(e,r=""){const{ctx:n,site:s="",returnUrl:i="",BA:a="",BP:c="",OS:h="",EQP:u="",...j}=e||{};if(!s&&!n)throw new Error("site is required");if(!i&&!n)throw new Error("returnUrl is required");const{clientId:d,login:b}=o,f=t({BA:a||n?.query?.ba||o.ba||"",BP:c||n?.query?.bp||o.bp||"",OS:h||o.os||1,EQP:u||o.eqp||""});let g;!n||s&&i||(g=function(e,o){let t=e.query.f||"";const r=e.origin,n=new RegExp("^"+r);if(/^\//.test(t))t=r+t;else if(t&&!n.test(t))t=r;else if(!t){const o=e.headers.referer;t=n.test(o)&&o!==e.href?o:r}const s={returnUrl:t};if(o){const e=t.replace(/^https?:\/\//,"").replace(/\/.*/,"");s.site=function(e){const o={hr:3e4,dljob:30100,hdjob:30101,fdjob:30102,sdjob:30103,hedjob:30104,gfjob:30105,zhnyfwjob:30106,shdjob:30107,tanjob:30108,qnjob:30109,dqjob:30200,cnjob:30201,spdjob:30202,zdhjob:30203,xxhjob:30204,hbjob:30300,scljob:30301,gfcljob:30302,dqzljob:30303,jchpjob:30304,hbfdjob:30305,hbgcjob:30306,hbsbjob:30307,hjxfjob:30308,jnjob:30309,gcjob:30400,dlgcjob:30401,jzjob:30402,szlqjob:30403,gdjob:30404,jdjob:30406,sjjob:30407,jljob:30408,gczjjob:30409,dcjob:30500,dcscjob:30501,dcyyjob:30502,dccljob:30503,dchsjob:30504,dcjsjob:30507,spdsbjob:30601,pdywjob:30602,pwpdgcjob:30603,znwdwjob:30604,zlpdwjob:30605,xndcjob:30606,dlscjob:30700,mhr:4e4,mdljob:40100,mhdjob:40101,mfdjob:40102,msdjob:40103,mhedjob:40104,mgfjob:40105,mzhnyfwjob:40106,mshdjob:40107,mtanjob:40108,mqnjob:40109,mdqjob:40200,mcnjob:40201,mspdjob:40202,mzdhjob:40203,mxxhjob:40204,mhbjob:40300,mscljob:40301,mgfcljob:40302,mdqzljob:40303,mjchpjob:40304,mhbfdjob:40305,mhbgcjob:40306,mhbsbjob:40307,mhjxfjob:40308,mjnjob:40309,mgcjob:40400,mdlgcjob:40401,mjzjob:40402,mszlqjob:40403,mgdjob:40404,mjdjob:40406,msjjob:40407,mjljob:40408,mgczjjob:40409,mdcjob:40500,mdcscjob:40501,mdcyyjob:40502,mdccljob:40503,mdchsjob:40504,mdcjsjob:40507,mspdsbjob:40601,mpdywjob:40602,mpwpdgcjob:40603,mznwdwjob:40604,mzlpdwjob:40605,mxndcjob:40606,mdlscjob:40700,yun:3099,yun:30991,yun:30992,yun:30993,yun:30994,yun:30995,yun:30996,sxh:3094,msxh:3093,xiaoyuan:3091,mxiaoyuan:4091,xxsxh:3090,mxxsxh:4090};for(const t in o){if(e.includes(t))return t+".bjx.com.cn";if(e.includes(o[t]))return t+".bjx.com.cn"}return"hr.bjx.com.cn"}(e)}return s}(n,!s));const l=t({site:s||g.site,clientId:d,pp:f,...j,returnUrl:i||g.returnUrl}),p=`/Account/Login?${l}`,m={login:`${b}${p}`,register:`${b}${`/Account/Register?${l}`}`,logout:`${b}${`/Account/Logout?${l}`}`,bind:`${b}${`/External/UserBind?${l}`}`,logout2:`${b}${`/Account/Logout?${l.replace("returnUrl=.+$","")+encodeURIComponent(p)}`}`,returnUrl:g.returnUrl};if(r){let e=[];if(Array.isArray(r)?e=r:"string"==typeof r&&(e=r.split(",").map(e=>e.trim())),!e.length)return m;const o={};return e.forEach(e=>{const t=m[e];t&&(o[e]=t)}),1===Object.keys(o).length?Object.values(o)[0]:Object.keys(o).length?o:m}return m}}}var d=(c||(c=1,function(o){const{setConfig:t,getConfig:r}=e.requireConfig(),n=u(),s=j();o.exports=Object.assign({setConfig:t,getConfig:r},n,s)}(h)),h.exports),b=e.getDefaultExportFromCjs(d);module.exports=b;
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bjx-auth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"exports": {
|
|
5
|
-
"
|
|
5
|
+
"./api": {
|
|
6
6
|
"require": "./dist/bjx-auth-api.umd.js",
|
|
7
7
|
"import": "./dist/bjx-auth-api.esm.js"
|
|
8
8
|
},
|
|
9
|
-
"./request": "./
|
|
10
|
-
"./strategy": "./
|
|
9
|
+
"./request": "./dist/request.cjs.js",
|
|
10
|
+
"./strategy": "./dist/strategy.cjs.js"
|
|
11
11
|
},
|
|
12
12
|
"unpkg": "./dist/bjx-auth-api.umd.js",
|
|
13
13
|
"jsdelivr": "./dist/bjx-auth-api.umd.js",
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
"src"
|
|
15
|
+
"dist"
|
|
17
16
|
],
|
|
18
17
|
"scripts": {
|
|
19
18
|
"version": "npm run build",
|
|
@@ -23,16 +22,19 @@
|
|
|
23
22
|
"license": "ISC",
|
|
24
23
|
"description": "",
|
|
25
24
|
"dependencies": {
|
|
25
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
26
26
|
"axios": "^1.11.0",
|
|
27
27
|
"crypto-js": "^4.2.0",
|
|
28
28
|
"jsencrypt": "^3.5.4",
|
|
29
29
|
"passport": "^0.4.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@babel/preset-env": "^7.28.3",
|
|
32
33
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
33
34
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
34
35
|
"@rollup/plugin-replace": "^6.0.2",
|
|
35
36
|
"@rollup/plugin-terser": "^0.4.4",
|
|
36
|
-
"rollup": "^4.49.0"
|
|
37
|
+
"rollup": "^4.49.0",
|
|
38
|
+
"rollup-plugin-delete": "^3.0.1"
|
|
37
39
|
}
|
|
38
40
|
}
|
package/readme.md
CHANGED
|
@@ -10,28 +10,28 @@ const {
|
|
|
10
10
|
createBjxAuthMiddleware,
|
|
11
11
|
} = require("bjx-auth/strategy");
|
|
12
12
|
const utils = require("./utils");
|
|
13
|
-
const isProd = process.env.NODE_ENV === "production";
|
|
14
13
|
|
|
15
14
|
passport.use(
|
|
16
15
|
"bjx",
|
|
17
16
|
new BjxStrategy(
|
|
18
17
|
{
|
|
19
|
-
loadUserInfo: true,
|
|
18
|
+
loadUserInfo: true,
|
|
20
19
|
userInfoType: "userinfo",
|
|
20
|
+
handleHeadrToken: false,
|
|
21
21
|
authConfig: {
|
|
22
|
-
ver:
|
|
23
|
-
clientId:
|
|
24
|
-
clientSecret:
|
|
25
|
-
apiVersion:
|
|
26
|
-
signVersion:
|
|
27
|
-
signKey:
|
|
22
|
+
ver: "",
|
|
23
|
+
clientId: "",
|
|
24
|
+
clientSecret: "",
|
|
25
|
+
apiVersion: "",
|
|
26
|
+
signVersion: "",
|
|
27
|
+
signKey: "",
|
|
28
28
|
|
|
29
|
-
passportapi:
|
|
30
|
-
login:
|
|
31
|
-
auth:
|
|
32
|
-
enterpriseapi:
|
|
29
|
+
passportapi: "",
|
|
30
|
+
login: "",
|
|
31
|
+
auth: "",
|
|
32
|
+
enterpriseapi: "",
|
|
33
33
|
|
|
34
|
-
debug:
|
|
34
|
+
// debug: false,
|
|
35
35
|
// debugApiUrl: [],
|
|
36
36
|
},
|
|
37
37
|
},
|
|
@@ -59,11 +59,6 @@ const app = new Koa()
|
|
|
59
59
|
|
|
60
60
|
app.use(passport.initialize())
|
|
61
61
|
app.use(passport.session())
|
|
62
|
-
app.use(createBjxAuthMiddleware(passport))
|
|
62
|
+
app.use(createBjxAuthMiddleware(passport))
|
|
63
63
|
//...
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
#### bjx-auth-api.umd.js 导出鉴权相关api
|
|
67
|
-
```bash
|
|
68
|
-
npm run build
|
|
69
64
|
```
|
package/src/config.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
const config = {
|
|
2
|
-
// sign/
|
|
3
|
-
eqp: '00000000-0000-0000-0000-000000000000',
|
|
4
|
-
os: '',
|
|
5
|
-
ba: '',
|
|
6
|
-
bp: '',
|
|
7
|
-
ver: '8.0.0',
|
|
8
|
-
clientId: process.env.CLIENT_ID || '',
|
|
9
|
-
clientSecret: process.env.CLIENT_SECRET || '',
|
|
10
|
-
apiVersion: process.env.API_VERSION || '',
|
|
11
|
-
signVersion: process.env.SIGN_VERSION || '',
|
|
12
|
-
signKey: process.env.SIGN_KEY || '',
|
|
13
|
-
|
|
14
|
-
// axios.js
|
|
15
|
-
passportapi: process.env.PASSPORTAPI || '',
|
|
16
|
-
login: process.env.LOGIN || '',
|
|
17
|
-
auth: process.env.AUTH || '',
|
|
18
|
-
enterpriseapi: process.env.ENTERPRISEAPI || '',
|
|
19
|
-
|
|
20
|
-
// logger.js
|
|
21
|
-
debug: false,
|
|
22
|
-
debugApiUrl: '',
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function setKey(key, val) {
|
|
26
|
-
if (config[key] !== undefined) {
|
|
27
|
-
config[key] = val
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function setConfig(key, val) {
|
|
31
|
-
if (typeof key === 'object') {
|
|
32
|
-
for (const k in key) {
|
|
33
|
-
setKey(k, key[k])
|
|
34
|
-
}
|
|
35
|
-
} else if (key) {
|
|
36
|
-
setKey(key, val)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function getConfig(key) {
|
|
40
|
-
if (key) {
|
|
41
|
-
return config[key]
|
|
42
|
-
}
|
|
43
|
-
return config
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const obj = {
|
|
47
|
-
getConfig,
|
|
48
|
-
setConfig,
|
|
49
|
-
}
|
|
50
|
-
Object.keys(config).forEach((key) => {
|
|
51
|
-
Object.defineProperty(obj, key, {
|
|
52
|
-
get() {
|
|
53
|
-
return config[key]
|
|
54
|
-
},
|
|
55
|
-
enumerable: true,
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
exports = module.exports = obj
|
package/src/logger.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const config = require('./config')
|
|
2
|
-
|
|
3
|
-
function errorLogger(...args) {
|
|
4
|
-
console.error(...args)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function debugLogger(...args) {
|
|
8
|
-
if (!config.debug) return
|
|
9
|
-
console.debug(...args)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
exports = module.exports = {
|
|
13
|
-
errorLogger,
|
|
14
|
-
debugLogger,
|
|
15
|
-
}
|
package/src/request/axios.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const axios = require('axios')
|
|
2
|
-
const conf = require('../config')
|
|
3
|
-
const { debugLogger } = require('../logger')
|
|
4
|
-
|
|
5
|
-
const passportapi = axios.create({
|
|
6
|
-
withCredentials: process.env.USE_ENV === 'web',
|
|
7
|
-
timeout: 10000,
|
|
8
|
-
})
|
|
9
|
-
passportapi.interceptors.request.use((config) => {
|
|
10
|
-
if (!config.baseURL) config.baseURL = conf.passportapi || ''
|
|
11
|
-
if (conf.debugApiUrl?.includes(config.url)) {
|
|
12
|
-
debugLogger(config)
|
|
13
|
-
}
|
|
14
|
-
return config
|
|
15
|
-
})
|
|
16
|
-
passportapi.interceptors.response.use((response) => {
|
|
17
|
-
return response
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const auth = axios.create({
|
|
21
|
-
timeout: 10000,
|
|
22
|
-
})
|
|
23
|
-
auth.interceptors.request.use((config) => {
|
|
24
|
-
if (!config.baseURL) config.baseURL = conf.auth || ''
|
|
25
|
-
if (conf.debugApiUrl?.includes(config.url)) {
|
|
26
|
-
debugLogger(config)
|
|
27
|
-
}
|
|
28
|
-
return config
|
|
29
|
-
})
|
|
30
|
-
auth.interceptors.response.use((response) => {
|
|
31
|
-
return response
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const newapi2 = axios.create({
|
|
35
|
-
timeout: 10000,
|
|
36
|
-
})
|
|
37
|
-
newapi2.interceptors.request.use((config) => {
|
|
38
|
-
if (!config.baseURL) config.baseURL = conf.newapi2 || ''
|
|
39
|
-
if (conf.debugApiUrl?.includes(config.url)) {
|
|
40
|
-
debugLogger(config)
|
|
41
|
-
}
|
|
42
|
-
return config
|
|
43
|
-
})
|
|
44
|
-
newapi2.interceptors.response.use((response) => {
|
|
45
|
-
return response
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const enterpriseapi = axios.create({
|
|
49
|
-
timeout: 10000,
|
|
50
|
-
})
|
|
51
|
-
enterpriseapi.interceptors.request.use((config) => {
|
|
52
|
-
if (!config.baseURL) config.baseURL = conf.enterpriseapi || ''
|
|
53
|
-
if (conf.debugApiUrl?.includes(config.url)) {
|
|
54
|
-
debugLogger(config)
|
|
55
|
-
}
|
|
56
|
-
return config
|
|
57
|
-
})
|
|
58
|
-
enterpriseapi.interceptors.response.use((response) => {
|
|
59
|
-
return response
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
exports = module.exports = {
|
|
63
|
-
passportapi,
|
|
64
|
-
auth,
|
|
65
|
-
newapi2,
|
|
66
|
-
enterpriseapi,
|
|
67
|
-
}
|
package/src/request/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const { setConfig, getConfig } = require('../config')
|
|
2
|
-
const sign = require('./sign')
|
|
3
|
-
const passportapi = require('./passportapi')
|
|
4
|
-
const userInfo = require('./userInfo')
|
|
5
|
-
const { clearPublicPemCache, hasPublicPemCache } = require('./sign/publicPem')
|
|
6
|
-
|
|
7
|
-
exports = module.exports = Object.assign(
|
|
8
|
-
{ setConfig, getConfig, clearPublicPemCache, hasPublicPemCache },
|
|
9
|
-
sign,
|
|
10
|
-
passportapi,
|
|
11
|
-
userInfo,
|
|
12
|
-
)
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
const { passportapi } = require('./axios')
|
|
2
|
-
const { getReqBody } = require('./sign')
|
|
3
|
-
|
|
4
|
-
//https://passportapi.bjx.com.cn/swagger/swagger-ui/index.html#/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* nodejs授权
|
|
8
|
-
*/
|
|
9
|
-
async function token(opts, signObj = {}) {
|
|
10
|
-
opts.data = await getReqBody(null, false, signObj)
|
|
11
|
-
return passportapi({
|
|
12
|
-
url: '/api/v1/token/web',
|
|
13
|
-
method: 'POST',
|
|
14
|
-
...opts,
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function tokenRefresh(opts, signObj = {}) {
|
|
19
|
-
opts.data = await getReqBody(null, false, signObj)
|
|
20
|
-
return passportapi({
|
|
21
|
-
url: '/api/v1/token/refresh/web',
|
|
22
|
-
method: 'POST',
|
|
23
|
-
...opts,
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function getToken(opts, signObj) {
|
|
28
|
-
if (opts.__isRefresh__) {
|
|
29
|
-
return tokenRefresh(opts, signObj)
|
|
30
|
-
} else {
|
|
31
|
-
return token(opts, signObj)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 其他接口
|
|
37
|
-
*/
|
|
38
|
-
// 短信登录
|
|
39
|
-
async function loginSms(opts, signObj = {}) {
|
|
40
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
41
|
-
return passportapi({
|
|
42
|
-
url: '/api/v1/login/sms/web',
|
|
43
|
-
method: 'POST',
|
|
44
|
-
...opts,
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 密码登录
|
|
49
|
-
async function loginPwd(opts, signObj = {}) {
|
|
50
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
51
|
-
return passportapi({
|
|
52
|
-
url: '/api/v1/login/pwd/web',
|
|
53
|
-
method: 'POST',
|
|
54
|
-
...opts,
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 短信注册
|
|
59
|
-
async function registerSms(opts, signObj = {}) {
|
|
60
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
61
|
-
return passportapi({
|
|
62
|
-
url: '/api/v1/register/sms/web',
|
|
63
|
-
method: 'POST',
|
|
64
|
-
...opts,
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 账户登出 (set-cookie + 返回clear_cache回调地址)
|
|
69
|
-
async function logout(opts, signObj = {}) {
|
|
70
|
-
opts.data = await getReqBody(null, false, signObj)
|
|
71
|
-
return passportapi({
|
|
72
|
-
url: '/api/v1/logout/web',
|
|
73
|
-
method: 'POST',
|
|
74
|
-
...opts,
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 快速登录/注册
|
|
79
|
-
async function loginSmsQuick(opts, signObj = {}) {
|
|
80
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
81
|
-
return passportapi({
|
|
82
|
-
url: '/api/v1/login/sms/quick/web',
|
|
83
|
-
method: 'POST',
|
|
84
|
-
...opts,
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// 设置用户身份
|
|
89
|
-
async function userBusmold(opts, signObj = {}) {
|
|
90
|
-
opts.data = await getReqBody(opts.data, false, signObj)
|
|
91
|
-
return passportapi({
|
|
92
|
-
url: '/api/v1/user/busmold/seekers/set',
|
|
93
|
-
method: 'POST',
|
|
94
|
-
...opts,
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// 根据手机号判断用户是否存在
|
|
99
|
-
async function userExist(opts, signObj = {}) {
|
|
100
|
-
opts.data = await getReqBody(opts.data, false, signObj)
|
|
101
|
-
return passportapi({
|
|
102
|
-
url: '/api/v1/user/exist/phone',
|
|
103
|
-
method: 'POST',
|
|
104
|
-
...opts,
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// 找回密码前验证码
|
|
109
|
-
async function pwdResetVerify(opts, signObj = {}) {
|
|
110
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
111
|
-
return passportapi({
|
|
112
|
-
url: '/api/v1/user/pwd/reset/verify',
|
|
113
|
-
method: 'POST',
|
|
114
|
-
...opts,
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 找回密码
|
|
119
|
-
async function pwdReset(opts, signObj = {}) {
|
|
120
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
121
|
-
return passportapi({
|
|
122
|
-
url: '/api/v1/user/pwd/reset',
|
|
123
|
-
method: 'POST',
|
|
124
|
-
...opts,
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 获取公众号二维码
|
|
129
|
-
async function wxpubCode(opts, signObj = {}) {
|
|
130
|
-
opts.data = await getReqBody(opts.data, false, signObj)
|
|
131
|
-
return passportapi({
|
|
132
|
-
url: '/api/v1/wechat/wxpub/qrcode',
|
|
133
|
-
method: 'POST',
|
|
134
|
-
...opts,
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// 公众号扫码登录
|
|
139
|
-
async function wxpubScan(opts, signObj = {}) {
|
|
140
|
-
opts.data = await getReqBody(opts.data, false, signObj)
|
|
141
|
-
return passportapi({
|
|
142
|
-
url: '/api/v1/wechat/wxpub/scan/login',
|
|
143
|
-
method: 'POST',
|
|
144
|
-
...opts,
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 公众号登录后绑定
|
|
149
|
-
async function wxpubBindLogin(opts, signObj = {}) {
|
|
150
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
151
|
-
return passportapi({
|
|
152
|
-
url: '/api/v1/wechat/wxpub/scan/bindlogin',
|
|
153
|
-
method: 'POST',
|
|
154
|
-
...opts,
|
|
155
|
-
})
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async function wxpubH5Code(opts, signObj = {}) {
|
|
159
|
-
opts.data = await getReqBody(opts.data, false, signObj)
|
|
160
|
-
return passportapi({
|
|
161
|
-
url: '/api/v1/wechat/wxpub/h5/getcode',
|
|
162
|
-
method: 'POST',
|
|
163
|
-
...opts,
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function wxpubH5BindLogin(opts, signObj = {}) {
|
|
168
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
169
|
-
return passportapi({
|
|
170
|
-
url: '/api/v1/wechat/wxpub/h5/bindlogin',
|
|
171
|
-
method: 'POST',
|
|
172
|
-
...opts,
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async function webappCode(opts, signObj = {}) {
|
|
177
|
-
opts.data = await getReqBody(opts.data, false, signObj)
|
|
178
|
-
return passportapi({
|
|
179
|
-
url: '/api/v1/wechat/webapp/code',
|
|
180
|
-
method: 'POST',
|
|
181
|
-
...opts,
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async function webappBindLogin(opts, signObj = {}) {
|
|
186
|
-
opts.data = await getReqBody(opts.data, true, signObj)
|
|
187
|
-
return passportapi({
|
|
188
|
-
url: '/api/v1/wechat/webapp/bindlogin',
|
|
189
|
-
method: 'POST',
|
|
190
|
-
...opts,
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
exports = module.exports = {
|
|
195
|
-
getToken,
|
|
196
|
-
loginSms,
|
|
197
|
-
loginPwd,
|
|
198
|
-
registerSms,
|
|
199
|
-
logout,
|
|
200
|
-
|
|
201
|
-
loginSmsQuick,
|
|
202
|
-
userBusmold,
|
|
203
|
-
userExist,
|
|
204
|
-
pwdResetVerify,
|
|
205
|
-
pwdReset,
|
|
206
|
-
|
|
207
|
-
wxpubCode,
|
|
208
|
-
wxpubScan,
|
|
209
|
-
wxpubBindLogin,
|
|
210
|
-
|
|
211
|
-
wxpubH5Code,
|
|
212
|
-
wxpubH5BindLogin,
|
|
213
|
-
|
|
214
|
-
webappCode,
|
|
215
|
-
webappBindLogin,
|
|
216
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const crypto = require('crypto')
|
|
2
|
-
|
|
3
|
-
function encryptRSA(str, publicPem) {
|
|
4
|
-
if (!publicPem) throw new Error('publicPem is required')
|
|
5
|
-
const dataBuffer = Buffer.from(str, 'utf8')
|
|
6
|
-
const encrypted = crypto.publicEncrypt(
|
|
7
|
-
{
|
|
8
|
-
key: publicPem,
|
|
9
|
-
padding: crypto.constants.RSA_PKCS1_PADDING,
|
|
10
|
-
},
|
|
11
|
-
dataBuffer,
|
|
12
|
-
)
|
|
13
|
-
return encrypted.toString('base64')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function encryptAES(str) {
|
|
17
|
-
const iv = crypto.randomBytes(16) // 密匙和IV一致
|
|
18
|
-
const key = iv
|
|
19
|
-
const cipher = crypto.createCipheriv('aes-128-cbc', key, iv)
|
|
20
|
-
let encrypted = cipher.update(str, 'utf8', 'base64')
|
|
21
|
-
encrypted += cipher.final('base64')
|
|
22
|
-
return {
|
|
23
|
-
iv: iv.toString('hex'),
|
|
24
|
-
encrypted,
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
exports = module.exports = {
|
|
29
|
-
encryptRSA,
|
|
30
|
-
encryptAES,
|
|
31
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const JSEncrypt = require('jsencrypt')
|
|
2
|
-
|
|
3
|
-
const AES = require('crypto-js/aes')
|
|
4
|
-
const WordArray = require('crypto-js/lib-typedarrays')
|
|
5
|
-
const Pkcs7 = require('crypto-js/pad-pkcs7')
|
|
6
|
-
const Hex = require('crypto-js/enc-hex')
|
|
7
|
-
|
|
8
|
-
function encryptRSA(str, publicPem) {
|
|
9
|
-
if (!publicPem) throw new Error('publicPem is required')
|
|
10
|
-
const encryptor = new JSEncrypt()
|
|
11
|
-
encryptor.setPublicKey(publicPem)
|
|
12
|
-
const encrypted = encryptor.encrypt(str)
|
|
13
|
-
return encrypted
|
|
14
|
-
}
|
|
15
|
-
function encryptAES(str) {
|
|
16
|
-
const iv = WordArray.random(16) // 密匙和IV一致
|
|
17
|
-
const key = iv
|
|
18
|
-
const encrypted = AES.encrypt(str, key, {
|
|
19
|
-
iv,
|
|
20
|
-
padding: Pkcs7,
|
|
21
|
-
})
|
|
22
|
-
return {
|
|
23
|
-
iv: iv.toString(Hex),
|
|
24
|
-
encrypted: encrypted.toString(),
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
exports = module.exports = {
|
|
29
|
-
encryptRSA,
|
|
30
|
-
encryptAES,
|
|
31
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const crypto = require('crypto')
|
|
2
|
-
|
|
3
|
-
function hashHS256(str, key) {
|
|
4
|
-
return crypto.createHmac('sha256', key).update(str).digest('base64')
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function hashMD5(str) {
|
|
8
|
-
return crypto.createHash('md5').update(str).digest('hex').toUpperCase()
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
exports = module.exports = {
|
|
12
|
-
hashHS256,
|
|
13
|
-
hashMD5,
|
|
14
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const HmacSHA256 = require('crypto-js/hmac-sha256')
|
|
2
|
-
const Base64 = require('crypto-js/enc-base64')
|
|
3
|
-
|
|
4
|
-
const MD5 = require('crypto-js/md5')
|
|
5
|
-
const Hex = require('crypto-js/enc-hex')
|
|
6
|
-
|
|
7
|
-
function hashHS256(str, key) {
|
|
8
|
-
return HmacSHA256(str, key).toString(Base64)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function hashMD5(str) {
|
|
12
|
-
return MD5(str).toString(Hex)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
exports = module.exports = {
|
|
16
|
-
hashHS256,
|
|
17
|
-
hashMD5,
|
|
18
|
-
}
|