Merge branch 'master' of ssh://git.trj.tw:10022/keycloak-org/keycloak-demo

This commit is contained in:
Jay 2021-09-01 19:30:52 +08:00
commit b91ce62aa4
6 changed files with 36 additions and 59 deletions

View File

@ -2,10 +2,15 @@ const { env } = process;
module.exports = { module.exports = {
server: { server: {
<<<<<<< HEAD
url: env.SERVER_URL || "http://localhost:10230", url: env.SERVER_URL || "http://localhost:10230",
=======
url: env.SERVER_URL || 'http://localhost:10230',
>>>>>>> c96cdf0ebd17f805235c6fa9eecf2ea79ecca19b
port: parseInt(env.SERVER_PORT, 10) || 10230, port: parseInt(env.SERVER_PORT, 10) || 10230,
jwt_secret: env.SERVER_JWT_SECRET || "testsecret", jwt_secret: env.SERVER_JWT_SECRET || "testsecret",
jwt_expire: parseInt(env.SERVER_JWT_EXPIRE, 10) || 60 * 60 * 24 * 30, // 30 day jwt_expire: parseInt(env.SERVER_JWT_EXPIRE, 10) || 60 * 60 * 24 * 30, // 30 day
<<<<<<< HEAD
}, },
sso: { sso: {
authorized_endpoint: env.SSO_AUTHORIZED_ENDPOINT || "", authorized_endpoint: env.SSO_AUTHORIZED_ENDPOINT || "",
@ -13,5 +18,21 @@ module.exports = {
logout_endpoint: env.SSO_LOGOUT_ENDPOINT || "", logout_endpoint: env.SSO_LOGOUT_ENDPOINT || "",
client_id: env.SSO_CLIENT_ID || "", client_id: env.SSO_CLIENT_ID || "",
client_secret: env.SSO_CLIENT_SECRET || "", client_secret: env.SSO_CLIENT_SECRET || "",
=======
},
redis: {
host: env.REDIS_HOST || 'localhost',
port: parseInt(env.REDIS_PORT, 10) || 6379,
password: env.REDIS_PASSWORD || '',
prefix: env.REDIS_PREFIX || '',
db: parseInt(env.REDIS_DB, 10) || 0,
},
sso: {
authorized_endpoint: env.SSO_AUTHORIZED_ENDPOINT || '',
token_endpoint: env.SSO_TOKEN_ENDPOINT || '',
logout_endpoint: env.SSO_LOGOUT_ENDPOINT || '',
client_id: env.SSO_CLIENT_ID || '',
client_secret: env.SSO_CLIENT_SECRET || '',
>>>>>>> c96cdf0ebd17f805235c6fa9eecf2ea79ecca19b
}, },
}; };

View File

@ -2,7 +2,13 @@
const constants = { const constants = {
PAGE_SIZE: 20, PAGE_SIZE: 20,
OPENID_EXPIRE: 300, // 5min OPENID_EXPIRE: 300, // 5min
<<<<<<< HEAD
ALLOW_GROUP_ROLE: ["Ironman3"], ALLOW_GROUP_ROLE: ["Ironman3"],
=======
INTERNAL_REGULATION_CACHE_TTL: 1800, // 30min
REPORT_CACHE_TTL: 600, // 10 min
ALLOW_GROUP_ROLE: ['Ironman3'] // 允許的 Group 身份
>>>>>>> c96cdf0ebd17f805235c6fa9eecf2ea79ecca19b
}; };
module.exports = constants; module.exports = constants;

View File

@ -5,6 +5,10 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "node index.js", "start": "node index.js",
<<<<<<< HEAD
=======
"test": "mocha --timeout 5000 --exit test/ && jest --passWithNoTests --runInBand --coverage .",
>>>>>>> c96cdf0ebd17f805235c6fa9eecf2ea79ecca19b
"postinstall": "node -e \"var s='../',d='node_modules/src',fs=require('fs');fs.exists(d,function(e){e||fs.symlinkSync(s,d,'dir')});\"" "postinstall": "node -e \"var s='../',d='node_modules/src',fs=require('fs');fs.exists(d,function(e){e||fs.symlinkSync(s,d,'dir')});\""
}, },
"keywords": [], "keywords": [],

View File

@ -10,20 +10,3 @@ module.exports = {};
* @property {string} errorMessage api error message (除了prod以外的環境會有) * @property {string} errorMessage api error message (除了prod以外的環境會有)
*/ */
/**
* @typedef Pager
* @description 頁數資訊
* @property {number} page 目前頁數
* @property {number} count 總筆數
* @property {number} total 總頁數
*/
/**
* @typedef Account
* @description API回傳使用者資訊
* @property {string} id 使用者ID
* @property {string} phone 手機
* @property {string} display_name 顯示名稱
* @property {string} created_time 帳號建立時間
* @property {string} updated_time 帳號更新時間
*/

View File

@ -122,45 +122,3 @@ mod.selectObject = (obj, param) => {
return newObj; return newObj;
}; };
/**
* pad string to target length
* @param {any} v source input
* @param {number} len target length
* @param {number} direct pad direct (-1 left, 1 right)
* @param {string} padChar default '0'
* @return {string}
*/
mod.pad = (v, len = 0, direct = -1, padChar = '0') => {
if (v === null || v === undefined) return '';
if (typeof v !== 'string' && !v.toString) return '';
if (direct !== 1 && direct !== -1) return '';
if (typeof v !== 'string') v = v.toString();
if (typeof padChar !== 'string') padChar = '0';
len = mod.toNumber(len, 0, 0);
if (v.length < len) {
if (direct < 0) v = `${padChar}${v}`;
else v = `${v}${padChar}`;
return mod.pad(v, len, direct, padChar);
}
return v;
};
/**
* pad left
* @param {any} v
* @param {number} len
* @param {string} padChar
* @return {string}
*/
mod.padLeft = (v, len = 0, padChar = '0') => mod.pad(v, len, -1, padChar);
/**
* pad right
* @param {any} v
* @param {number} len
* @param {string} padChar
* @return {string}
*/
mod.padRight = (v, len = 0, padChar = '0') => mod.pad(v, len, 1, padChar);

View File

@ -135,7 +135,12 @@ mod.getToken = async (code, state) => {
// decode access token // decode access token
console.log("token ::: ", jwt.decode(accessToken)); console.log("token ::: ", jwt.decode(accessToken));
<<<<<<< HEAD
console.log("body ::: ", body); console.log("body ::: ", body);
=======
const decoded = jwt.decode(idToken);
if (!decoded || typeof decoded !== 'object') throw new Error('jwt decode fail');
>>>>>>> c96cdf0ebd17f805235c6fa9eecf2ea79ecca19b
// @ts-ignore // @ts-ignore
const { preferred_username: preferredUsername } = decoded; const { preferred_username: preferredUsername } = decoded;
if (!preferredUsername) throw new Error("id token field missing"); if (!preferredUsername) throw new Error("id token field missing");