Commit 4b3bcb04 authored by bianlongting's avatar bianlongting 💬

first

parents
Pipeline #139824 failed with stages
in 0 seconds
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
[*.md]
max_line_length = 0
trim_trailing_whitespace = false
[COMMIT_EDITMSG]
max_line_length = 0
node_modules
dist
.vscode
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
{
"bracketSpacing": false,
"singleQuote": true,
"jsxBracketSameLine": true,
"trailingComma": "es5",
"printWidth": 80,
"parser": "babel"
}
export interface ISsoConfig {
ssourl: string;
systemId: number;
systemName: string;
appSecret: string;
profiles: string;
}
export default class Sso {
private ssoConfig;
constructor(ssoConfig: ISsoConfig);
/**
* 获取登录凭证
* @param ssoStamp 时间戳
*/
getTicket(ssoStamp: string): Promise<unknown>;
/**
* 获取用户信息
* @param ticket 登录凭证
*/
getUserInfo(ticket: string): Promise<unknown>;
/**
* 获取管理员在指定系统下的权限
* @param id 员工Id
*/
getPowerIdsBySystemIdAndAdminId(id: string): Promise<unknown>;
/**
* 加载权限树
*/
loadPowerList(): Promise<unknown>;
/**
* 退出登录
* @param ticket 登录凭证
*/
logout(ticket: string): Promise<unknown>;
/**
* 获取sso当前域名
* @param ticket 登录凭证
*/
findSsoHomeUrl(ticket: string): Promise<unknown>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("./utils");
var Sso = /** @class */ (function () {
function Sso(ssoConfig) {
this.ssoConfig = ssoConfig;
}
/**
* 获取登录凭证
* @param ssoStamp 时间戳
*/
Sso.prototype.getTicket = function (ssoStamp) {
return __awaiter(this, void 0, void 0, function () {
var systemId, interfaceName;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
systemId = this.ssoConfig.systemId;
interfaceName = '/remoteSSOService/findTicketByStamp';
return [4 /*yield*/, utils_1.default.buildInterFaceUrl(interfaceName, systemId, ssoStamp)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* 获取用户信息
* @param ticket 登录凭证
*/
Sso.prototype.getUserInfo = function (ticket) {
return __awaiter(this, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
data = '/remoteSSOService/verifyTicketAndGetAdmin';
return [4 /*yield*/, utils_1.default.buildInterFaceUrl(data, ticket)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* 获取管理员在指定系统下的权限
* @param id 员工Id
*/
Sso.prototype.getPowerIdsBySystemIdAndAdminId = function (id) {
return __awaiter(this, void 0, void 0, function () {
var systemId, interfaceName;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
systemId = this.ssoConfig.systemId;
interfaceName = '/remotePermissionService/getPowerIdsBySystemIdAndAdminId';
return [4 /*yield*/, utils_1.default.buildInterFaceUrl(interfaceName, systemId, id)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* 加载权限树
*/
Sso.prototype.loadPowerList = function () {
return __awaiter(this, void 0, void 0, function () {
var systemId, interfaceName;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
systemId = this.ssoConfig.systemId;
interfaceName = '/remotePermissionService/loadPowerList';
return [4 /*yield*/, utils_1.default.buildInterFaceUrl(interfaceName, systemId)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* 退出登录
* @param ticket 登录凭证
*/
Sso.prototype.logout = function (ticket) {
return __awaiter(this, void 0, void 0, function () {
var interfaceName;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
interfaceName = '/remoteSSOService/outLogin';
return [4 /*yield*/, utils_1.default.buildInterFaceUrl(interfaceName, ticket)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* 获取sso当前域名
* @param ticket 登录凭证
*/
Sso.prototype.findSsoHomeUrl = function (ticket) {
return __awaiter(this, void 0, void 0, function () {
var interfaceName;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
interfaceName = 'remoteSSOService/findSsoHomeUrl';
return [4 /*yield*/, utils_1.default.buildInterFaceUrl(interfaceName, ticket)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
return Sso;
}());
exports.default = Sso;
//# sourceMappingURL=index.js.map
\ No newline at end of file
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA2B;AAS3B;IAEE,aAAY,SAAqB;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACU,uBAAS,GAAtB,UAAuB,QAAgB;;;;;;wBAC7B,QAAQ,GAAK,IAAI,CAAC,SAAS,SAAnB,CAAoB;wBAC9B,aAAa,GAAG,qCAAqC,CAAC;wBACrD,qBAAM,eAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAA;4BAAtE,sBAAO,SAA+D,EAAC;;;;KACxE;IACD;;;OAGG;IACU,yBAAW,GAAxB,UAAyB,MAAc;;;;;;wBAC/B,IAAI,GAAG,2CAA2C,CAAC;wBAClD,qBAAM,eAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,EAAA;4BAAjD,sBAAO,SAA0C,EAAC;;;;KACnD;IAED;;;OAGG;IACU,6CAA+B,GAA5C,UAA6C,EAAU;;;;;;wBAC7C,QAAQ,GAAK,IAAI,CAAC,SAAS,SAAnB,CAAoB;wBAC9B,aAAa,GACjB,0DAA0D,CAAC;wBACtD,qBAAM,eAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAA;4BAAhE,sBAAO,SAAyD,EAAC;;;;KAClE;IAED;;OAEG;IACU,2BAAa,GAA1B;;;;;;wBACU,QAAQ,GAAK,IAAI,CAAC,SAAS,SAAnB,CAAoB;wBAC9B,aAAa,GAAG,wCAAwC,CAAC;wBACxD,qBAAM,eAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAA;4BAA5D,sBAAO,SAAqD,EAAC;;;;KAC9D;IAED;;;OAGG;IACU,oBAAM,GAAnB,UAAoB,MAAc;;;;;;wBAC1B,aAAa,GAAG,4BAA4B,CAAC;wBAC5C,qBAAM,eAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,MAAM,CAAC,EAAA;4BAA1D,sBAAO,SAAmD,EAAC;;;;KAC5D;IAED;;;OAGG;IACG,4BAAc,GAApB,UAAqB,MAAc;;;;;;wBAC3B,aAAa,GAAG,iCAAiC,CAAC;wBAEjD,qBAAM,eAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,MAAM,CAAC,EAAA;4BAA1D,sBAAO,SAAmD,EAAC;;;;KAC5D;IACH,UAAC;AAAD,CAAC,AA9DD,IA8DC"}
\ No newline at end of file
declare var b64pad: string;
declare var chrsz: number;
declare var SECURITY: {
duiba_b64_sha: (input: any) => string;
duiba_md5: (string: any, key: any, raw: any) => string;
};
declare function safeAdd(x: any, y: any): number;
declare function bitRol(num: any, cnt: any): number;
declare function md5CMN(q: any, a: any, b: any, x: any, s: any, t: any): number;
declare function md5FF(a: any, b: any, c: any, d: any, x: any, s: any, t: any): number;
declare function md5GG(a: any, b: any, c: any, d: any, x: any, s: any, t: any): number;
declare function md5HH(a: any, b: any, c: any, d: any, x: any, s: any, t: any): number;
declare function md5II(a: any, b: any, c: any, d: any, x: any, s: any, t: any): number;
declare function binlMD5(x: any, len: any): number[];
declare function binl2rstr(input: any): string;
declare function rstr2binl(input: any): any[];
declare function rstrMd5(s: any): string;
declare function rstrHmacMd5(key: any, data: any): string;
declare function rstr2hex(input: any): string;
declare function str2rstrUtf8(input: any): string;
declare function rawMd5(s: any): string;
declare function hexMd5(s: any): string;
declare function rawHmacMd5(k: any, d: any): string;
declare function hexHmacMd5(k: any, d: any): string;
declare function coreSha1(x: any, len: any): number[];
declare function sha1Ft(t: any, b: any, c: any, d: any): number;
declare function sha1Kt(t: any): 1518500249 | 1859775393 | -1894007588 | -899497514;
declare function rol(num: any, cnt: any): number;
declare function str2binb(str: any): any[];
declare function binb2b64(binarray: any): string;
This diff is collapsed.
This diff is collapsed.
declare const util: {
init(opts: any): void;
/**
* 统一封装请求java接口
*/
buildInterFaceUrl(interfaceName: any, ...args: any[]): Promise<unknown>;
};
export default util;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var axios = require('axios');
var md5 = require('./md5');
var ssoConf = null;
var util = {
init: function (opts) {
ssoConf = opts;
},
/**
* 统一封装请求java接口
*/
buildInterFaceUrl: function (interfaceName) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
var params = {};
for (var i = 0; i < args.length; i++) {
if (typeof args[i] === 'string') {
args[i] = "\"" + args[i] + "\"";
}
params["_p" + i] = args[i];
}
var appSecret = ssoConf.appSecret;
var profiles = ssoConf.profiles;
var systemName = ssoConf.systemName;
// @ts-ignore
var timestamp = Date.parse(new Date());
var newString = appSecret + interfaceName + profiles + systemName + timestamp;
var sign = md5.SECURITY.duiba_md5(newString);
var headSignStr = JSON.stringify({
systemName: systemName,
interfaceName: interfaceName,
timestamp: timestamp,
profiles: profiles,
sign: sign,
});
var headSign = encodeURI(headSignStr);
var url = ssoConf.ssourl + interfaceName; // op
return new Promise(function (resolve, reject) {
axios({
headers: {
'X-SSO-MR': true,
'X-Rpc': true,
'X-SSO-SIGN': headSign,
},
method: 'get',
url: url,
params: params,
})
.then(function (data) {
resolve(data.data);
})
.catch(function (err) {
reject(err);
});
});
},
};
exports.default = util;
//# sourceMappingURL=utils.js.map
\ No newline at end of file
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAAA,IAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,IAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE7B,IAAI,OAAO,GAAG,IAAI,CAAC;AAEnB,IAAM,IAAI,GAAG;IACX,IAAI,YAAC,IAAI;QACP,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,iBAAiB,YAAC,aAAa;QAAE,cAAO;aAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;YAAP,6BAAO;;QACtC,IAAM,MAAM,GAAG,EAAE,CAAC;QAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACpC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;gBAC/B,IAAI,CAAC,CAAC,CAAC,GAAG,OAAI,IAAI,CAAC,CAAC,CAAC,OAAG,CAAC;aAC1B;YACD,MAAM,CAAC,OAAK,CAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;SAC5B;QAED,IAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,IAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,IAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,aAAa;QACb,IAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACzC,IAAM,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;QAChF,IAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC/C,IAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC;YACjC,UAAU,YAAA;YACV,aAAa,eAAA;YACb,SAAS,WAAA;YACT,QAAQ,UAAA;YACR,IAAI,MAAA;SACL,CAAC,CAAC;QACH,IAAM,QAAQ,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;QACxC,IAAM,GAAG,GAAG,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC,KAAK;QAEjD,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YACjC,KAAK,CAAC;gBACJ,OAAO,EAAE;oBACP,UAAU,EAAE,IAAI;oBAChB,OAAO,EAAE,IAAI;oBACb,YAAY,EAAE,QAAQ;iBACvB;gBACD,MAAM,EAAE,KAAK;gBACb,GAAG,KAAA;gBACH,MAAM,QAAA;aACP,CAAC;iBACC,IAAI,CAAC,UAAC,IAAI;gBACT,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC,CAAC;iBACD,KAAK,CAAC,UAAC,GAAG;gBACT,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAGF,kBAAe,IAAI,CAAA"}
\ No newline at end of file
{
"name": "sso-oauth2",
"version": "0.1.0",
"author": "HUHU",
"license": "MIT",
"main": "lib/index.js",
"repository": {
"type": "nodejs"
},
"scripts": {
"start": "npx tsc"
},
"dependencies": {
"@types/node": "^12.6.2",
"axios": "^0.19.0",
"typescript": "^3.5.3"
}
}
import util from './utils';
export interface ISsoConfig {
ssourl: string;
systemId: number;
systemName: string;
appSecret: string;
profiles: string;
}
export default class Sso {
private ssoConfig: ISsoConfig;
constructor(ssoConfig: ISsoConfig) {
this.ssoConfig = ssoConfig;
}
/**
* 获取登录凭证
* @param ssoStamp 时间戳
*/
public async getTicket(ssoStamp: string) {
const { systemId } = this.ssoConfig;
const interfaceName = '/remoteSSOService/findTicketByStamp';
return await util.buildInterFaceUrl(interfaceName, systemId, ssoStamp);
}
/**
* 获取用户信息
* @param ticket 登录凭证
*/
public async getUserInfo(ticket: string) {
const data = '/remoteSSOService/verifyTicketAndGetAdmin';
return await util.buildInterFaceUrl(data, ticket);
}
/**
* 获取管理员在指定系统下的权限
* @param id 员工Id
*/
public async getPowerIdsBySystemIdAndAdminId(id: string) {
const { systemId } = this.ssoConfig;
const interfaceName =
'/remotePermissionService/getPowerIdsBySystemIdAndAdminId';
return await util.buildInterFaceUrl(interfaceName, systemId, id);
}
/**
* 加载权限树
*/
public async loadPowerList() {
const { systemId } = this.ssoConfig;
const interfaceName = '/remotePermissionService/loadPowerList';
return await util.buildInterFaceUrl(interfaceName, systemId);
}
/**
* 退出登录
* @param ticket 登录凭证
*/
public async logout(ticket: string) {
const interfaceName = '/remoteSSOService/outLogin';
return await util.buildInterFaceUrl(interfaceName, ticket);
}
/**
* 获取sso当前域名
* @param ticket 登录凭证
*/
async findSsoHomeUrl(ticket: string) {
const interfaceName = 'remoteSSOService/findSsoHomeUrl';
return await util.buildInterFaceUrl(interfaceName, ticket);
}
}
// var hexcase = 0;
var b64pad = '';
var chrsz = 8;
var SECURITY = {
duiba_b64_sha: function(input) {
return binb2b64(coreSha1(str2binb(input), input.length * chrsz));
},
duiba_md5: function(string, key, raw) {
if (!key) {
if (!raw) {
return hexMd5(string);
} else {
return rawMd5(string);
}
}
if (!raw) {
return hexHmacMd5(key, string);
} else {
return rawHmacMd5(key, string);
}
// return hexHmacMd5(key, string);
}
};
function safeAdd(x, y) {
var lsw = (x & 65535) + (y & 65535);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 65535);
}
function bitRol(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt));
}
function md5CMN(q, a, b, x, s, t) {
return safeAdd(bitRol(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
}
function md5FF(a, b, c, d, x, s, t) {
return md5CMN((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5GG(a, b, c, d, x, s, t) {
return md5CMN((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5HH(a, b, c, d, x, s, t) {
return md5CMN(b ^ c ^ d, a, b, x, s, t);
}
function md5II(a, b, c, d, x, s, t) {
return md5CMN(c ^ (b | (~d)), a, b, x, s, t);
}
function binlMD5(x, len) {
x[len >> 5] |= 128 << ((len) % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
var i;
var olda;
var oldb;
var oldc;
var oldd;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
for (i = 0; i < x.length; i += 16) {
olda = a;
oldb = b;
oldc = c;
oldd = d;
a = md5FF(a, b, c, d, x[i], 7, -680876936);
d = md5FF(d, a, b, c, x[i + 1], 12, -389564586);
c = md5FF(c, d, a, b, x[i + 2], 17, 606105819);
b = md5FF(b, c, d, a, x[i + 3], 22, -1044525330);
a = md5FF(a, b, c, d, x[i + 4], 7, -176418897);
d = md5FF(d, a, b, c, x[i + 5], 12, 1200080426);
c = md5FF(c, d, a, b, x[i + 6], 17, -1473231341);
b = md5FF(b, c, d, a, x[i + 7], 22, -45705983);
a = md5FF(a, b, c, d, x[i + 8], 7, 1770035416);
d = md5FF(d, a, b, c, x[i + 9], 12, -1958414417);
c = md5FF(c, d, a, b, x[i + 10], 17, -42063);
b = md5FF(b, c, d, a, x[i + 11], 22, -1990404162);
a = md5FF(a, b, c, d, x[i + 12], 7, 1804603682);
d = md5FF(d, a, b, c, x[i + 13], 12, -40341101);
c = md5FF(c, d, a, b, x[i + 14], 17, -1502002290);
b = md5FF(b, c, d, a, x[i + 15], 22, 1236535329);
a = md5GG(a, b, c, d, x[i + 1], 5, -165796510);
d = md5GG(d, a, b, c, x[i + 6], 9, -1069501632);
c = md5GG(c, d, a, b, x[i + 11], 14, 643717713);
b = md5GG(b, c, d, a, x[i], 20, -373897302);
a = md5GG(a, b, c, d, x[i + 5], 5, -701558691);
d = md5GG(d, a, b, c, x[i + 10], 9, 38016083);
c = md5GG(c, d, a, b, x[i + 15], 14, -660478335);
b = md5GG(b, c, d, a, x[i + 4], 20, -405537848);
a = md5GG(a, b, c, d, x[i + 9], 5, 568446438);
d = md5GG(d, a, b, c, x[i + 14], 9, -1019803690);
c = md5GG(c, d, a, b, x[i + 3], 14, -187363961);
b = md5GG(b, c, d, a, x[i + 8], 20, 1163531501);
a = md5GG(a, b, c, d, x[i + 13], 5, -1444681467);
d = md5GG(d, a, b, c, x[i + 2], 9, -51403784);
c = md5GG(c, d, a, b, x[i + 7], 14, 1735328473);
b = md5GG(b, c, d, a, x[i + 12], 20, -1926607734);
a = md5HH(a, b, c, d, x[i + 5], 4, -378558);
d = md5HH(d, a, b, c, x[i + 8], 11, -2022574463);
c = md5HH(c, d, a, b, x[i + 11], 16, 1839030562);
b = md5HH(b, c, d, a, x[i + 14], 23, -35309556);
a = md5HH(a, b, c, d, x[i + 1], 4, -1530992060);
d = md5HH(d, a, b, c, x[i + 4], 11, 1272893353);
c = md5HH(c, d, a, b, x[i + 7], 16, -155497632);
b = md5HH(b, c, d, a, x[i + 10], 23, -1094730640);
a = md5HH(a, b, c, d, x[i + 13], 4, 681279174);
d = md5HH(d, a, b, c, x[i], 11, -358537222);
c = md5HH(c, d, a, b, x[i + 3], 16, -722521979);
b = md5HH(b, c, d, a, x[i + 6], 23, 76029189);
a = md5HH(a, b, c, d, x[i + 9], 4, -640364487);
d = md5HH(d, a, b, c, x[i + 12], 11, -421815835);
c = md5HH(c, d, a, b, x[i + 15], 16, 530742520);
b = md5HH(b, c, d, a, x[i + 2], 23, -995338651);
a = md5II(a, b, c, d, x[i], 6, -198630844);
d = md5II(d, a, b, c, x[i + 7], 10, 1126891415);
c = md5II(c, d, a, b, x[i + 14], 15, -1416354905);
b = md5II(b, c, d, a, x[i + 5], 21, -57434055);
a = md5II(a, b, c, d, x[i + 12], 6, 1700485571);
d = md5II(d, a, b, c, x[i + 3], 10, -1894986606);
c = md5II(c, d, a, b, x[i + 10], 15, -1051523);
b = md5II(b, c, d, a, x[i + 1], 21, -2054922799);
a = md5II(a, b, c, d, x[i + 8], 6, 1873313359);
d = md5II(d, a, b, c, x[i + 15], 10, -30611744);
c = md5II(c, d, a, b, x[i + 6], 15, -1560198380);
b = md5II(b, c, d, a, x[i + 13], 21, 1309151649);
a = md5II(a, b, c, d, x[i + 4], 6, -145523070);
d = md5II(d, a, b, c, x[i + 11], 10, -1120210379);
c = md5II(c, d, a, b, x[i + 2], 15, 718787259);
b = md5II(b, c, d, a, x[i + 9], 21, -343485551);
a = safeAdd(a, olda);
b = safeAdd(b, oldb);
c = safeAdd(c, oldc);
d = safeAdd(d, oldd);
}
return [a, b, c, d];
}
function binl2rstr(input) {
var i;
var output = '';
for (i = 0; i < input.length * 32; i += 8) {
output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 255);
}
return output;
}
function rstr2binl(input) {
var i;
var output = [];
output[(input.length >> 2) - 1] = undefined;
for (i = 0; i < output.length; i += 1) {
output[i] = 0;
}
for (i = 0; i < input.length * 8; i += 8) {
output[i >> 5] |= (input.charCodeAt(i / 8) & 255) << (i % 32);
}
return output;
}
function rstrMd5(s) {
return binl2rstr(binlMD5(rstr2binl(s), s.length * 8));
}
function rstrHmacMd5(key, data) {
var i;
var bkey = rstr2binl(key);
var ipad = [];
var opad = [];
var hash;
ipad[15] = opad[15] = undefined;
if (bkey.length > 16) {
bkey = binlMD5(bkey, key.length * 8);
}
for (i = 0; i < 16; i += 1) {
ipad[i] = bkey[i] ^ 909522486;
opad[i] = bkey[i] ^ 1549556828;
}
hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
return binl2rstr(binlMD5(opad.concat(hash), 512 + 128));
}
function rstr2hex(input) {
var hexTab = '0123456789abcdef';
var output = '';
var x;
var i;
for (i = 0; i < input.length; i += 1) {
x = input.charCodeAt(i);
output += hexTab.charAt((x >>> 4) & 15) + hexTab.charAt(x & 15);
}
return output;
}
function str2rstrUtf8(input) {
return unescape(encodeURIComponent(input));
}
function rawMd5(s) {
return rstrMd5(str2rstrUtf8(s));
}
function hexMd5(s) {
return rstr2hex(rawMd5(s));
}
function rawHmacMd5(k, d) {
return rstrHmacMd5(str2rstrUtf8(k), str2rstrUtf8(d));
}
function hexHmacMd5(k, d) {
return rstr2hex(rawHmacMd5(k, d));
}
function coreSha1(x, len) {
x[len >> 5] |= 128 << (24 - len % 32);
x[((len + 64 >> 9) << 4) + 15] = len;
var w = Array(80);
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
var e = -1009589776;
for (var i = 0; i < x.length; i += 16) {
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
var olde = e;
for (var j = 0; j < 80; j++) {
if (j < 16) {
w[j] = x[i + j];
} else {
w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
}
var t = safeAdd(safeAdd(rol(a, 5), sha1Ft(j, b, c, d)), safeAdd(safeAdd(e, w[j]), sha1Kt(j)));
e = d;
d = c;
c = rol(b, 30);
b = a;
a = t;
}
a = safeAdd(a, olda);
b = safeAdd(b, oldb);
c = safeAdd(c, oldc);
d = safeAdd(d, oldd);
e = safeAdd(e, olde);
}
return [a, b, c, d, e];
}
function sha1Ft(t, b, c, d) {
if (t < 20) {
return (b & c) | ((~b) & d);
}
if (t < 40) {
return b ^ c ^ d;
}
if (t < 60) {
return (b & c) | (b & d) | (c & d);
}
return b ^ c ^ d;
}
function sha1Kt(t) {
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : (t < 60) ? -1894007588 : -899497514;
}
function rol(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt));
}
function str2binb(str) {
var bin = [];
var mask = (1 << chrsz) - 1;
for (var i = 0; i < str.length * chrsz; i += chrsz) {
bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i % 32);
}
return bin;
}
/* function coreHmacSha1(key, data) {
var bkey = str2binb(key);
if (bkey.length > 16) {
bkey = coreSha1(bkey, key.length * chrsz);
};
var ipad = Array(16), opad = Array(16);
for (var i = 0; i < 16; i++) {
ipad[i] = bkey[i] ^ 909522486;
opad[i] = bkey[i] ^ 1549556828;
}
var hash = coreSha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
return coreSha1(opad.concat(hash), 512 + 160);
}
function binb2str(bin) {
var str = '';
var mask = (1 << chrsz) - 1;
for (var i = 0; i < bin.length * 32; i += chrsz) {
str += String.fromCharCode((bin[i >> 5] >>> (32 - chrsz - i % 32)) & mask);
}
return str;
}
function binb2hex(binarray) {
var hexTab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef';
var str = '';
for (var i = 0; i < binarray.length * 4; i++) {
str += hexTab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 15) + hexTab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 15);
}
return str;
} */
function binb2b64(binarray) {
var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var str = '';
for (var i = 0; i < binarray.length * 4; i += 3) {
var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 255) << 16) | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 255) << 8) | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 255);
for (var j = 0; j < 4; j++) {
if (i * 8 + j * 6 > binarray.length * 32) {
str += b64pad;
} else {
str += tab.charAt((triplet >> 6 * (3 - j)) & 63);
}
}
}
str = str + '=';
return str;
}
module.exports.SECURITY = SECURITY
//export default SECURITY;
\ No newline at end of file
const axios = require('axios');
const md5 = require('./md5');
let ssoConf = null;
const util = {
init(opts) {
ssoConf = opts;
},
/**
* 统一封装请求java接口
*/
buildInterFaceUrl(interfaceName, ...args) {
const params = {};
for (let i = 0; i < args.length; i++) {
if (typeof args[i] === 'string') {
args[i] = `"${args[i]}"`;
}
params[`_p${i}`] = args[i];
}
const appSecret = ssoConf.appSecret;
const profiles = ssoConf.profiles;
const systemName = ssoConf.systemName;
// @ts-ignore
const timestamp = Date.parse(new Date());
const newString = appSecret + interfaceName + profiles + systemName + timestamp;
const sign = md5.SECURITY.duiba_md5(newString);
const headSignStr = JSON.stringify({
systemName,
interfaceName,
timestamp,
profiles,
sign,
});
const headSign = encodeURI(headSignStr);
const url = ssoConf.ssourl + interfaceName; // op
return new Promise((resolve, reject) => {
axios({
headers: {
'X-SSO-MR': true,
'X-Rpc': true,
'X-SSO-SIGN': headSign,
},
method: 'get',
url,
params,
})
.then((data) => {
resolve(data.data);
})
.catch((err) => {
reject(err);
});
});
},
};
export default util
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"lib": ["es6", "dom"],
"types": ["node"],
"outDir": "./lib",
"sourceMap": true,
"module": "commonjs",
"watch": true,
"moduleResolution": "node",
"isolatedModules": false,
"experimentalDecorators": true,
"declaration": true,
"suppressImplicitAnyIndexErrors": true
},
"include": ["./src/**/*"]
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^12.6.2":
version "12.6.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.2.tgz#a5ccec6abb6060d5f20d256fb03ed743e9774999"
integrity sha512-gojym4tX0FWeV2gsW4Xmzo5wxGjXGm550oVUII7f7G5o4BV6c7DBdiG1RRQd+y1bvqRyYtPfMK85UM95vsapqQ==
axios@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
dependencies:
follow-redirects "1.5.10"
is-buffer "^2.0.2"
debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"
follow-redirects@1.5.10:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"
is-buffer@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725"
integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=
typescript@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment