From 5d292687ceeeac4b09b14955cfe3c3a6b68eb87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Mon, 22 Jun 2026 23:20:18 +0400 Subject: [PATCH] =?UTF-8?q?v0.1.6:=20=D1=84=D0=B8=D0=BA=D1=81=20=D0=B4?= =?UTF-8?q?=D0=B5=D1=82=D0=B5=D0=BA=D1=86=D0=B8=D0=B8=20=D0=B8=D0=BC=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=BE=D0=BD=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=E2=80=94=20isImpersonated=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=20impersonatedCompanyId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _iam_test.js | 31 +++++++++++++++++++++++++++++++ _iam_token.txt | 1 + package.json | 2 +- v2/src/config/index.js | 2 +- v2/src/router/index.js | 4 ++-- 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 _iam_test.js create mode 100644 _iam_token.txt diff --git a/_iam_test.js b/_iam_test.js new file mode 100644 index 0000000..9d7c63d --- /dev/null +++ b/_iam_test.js @@ -0,0 +1,31 @@ +const fs = require('fs'); +const https = require('https'); +const TOKEN = fs.readFileSync(__dirname + '/token.txt', 'utf8').replace(/\s/g, ''); + +function fetchJson(url) { + return new Promise((resolve) => { + https.get(url, { + headers: { Authorization: 'Bearer ' + TOKEN, Accept: 'application/json' } + }, res => { + let data = ''; + res.on('data', c => data += c); + res.on('end', () => { + console.log('Status:', res.statusCode); + try { console.log(JSON.stringify(JSON.parse(data), null, 2)); } + catch(e) { console.log('RAW:', data.substring(0, 2000)); } + resolve(); + }); + }).on('error', e => { console.log('Error:', e.message); resolve(); }); + }); +} + +(async () => { + console.log('=== 1. auth-api /auth/user ==='); + await fetchJson('https://auth-api.ngcloud.ru/api/v1/auth/user'); + console.log(''); + console.log('=== 2. lk-api-gateway /iam/auth/user ==='); + await fetchJson('https://lk-api-gateway.ngcloud.ru/api/v1/iam/auth/user'); + console.log(''); + console.log('=== 3. auth-api /impersonation/status ==='); + await fetchJson('https://auth-api.ngcloud.ru/api/v1/impersonation/status'); +})(); diff --git a/_iam_token.txt b/_iam_token.txt new file mode 100644 index 0000000..ea65692 --- /dev/null +++ b/_iam_token.txt @@ -0,0 +1 @@ +eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoLWFwaSIsInN1YiI6IjAxOWQ3NmM1LTQyNGMtN2MyYy04OWI3LWUzZjA5OTQ5YTk4ZiIsImV4cCI6MTc4MjE5ODU2NywiaWF0IjoxNzgyMTU1MzY3LCJqdGkiOiI4Njk1N2I4OS1hYmYzLTRkM2UtYjc5Ni1jNjYzZjE2N2EwNDkiLCJhdXRoX3RpbWUiOjAsInR5cCI6IiIsImF6cCI6IiIsInNlc3Npb25fc3RhdGUiOiIiLCJhY3IiOiIiLCJhbGxvd2VkLW9yaWdpbnMiOm51bGwsInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6bnVsbH0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpudWxsfX0sInNjb3BlIjoiIiwic2lkIjoiIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJuYW1lIjoiIiwiQ2xpZW50SUQiOiJXWjAxMTEyIiwiY29tcGFueV9pZCI6IjhlYzcwYWMwLTU0NmQtNDJhNy04Y2ZmLTMzOWM4ZmI1MWEyMyIsImNvbXBhbnlfbmFtZSI6ItCe0J7QniDCq9Cd0KPQkdCV0KHCuyIsInRva2VuX3R5cGUiOiJhY2Nlc3MiLCJpZHBfdXNyX3VpZCI6IjAxOWQ3NmM1LTQyNGMtN2MyYy04OWI3LWUzZjA5OTQ5YTk4ZiIsImxvZ2luIjoibnRhemV0ZGlub3ZAbnViZXMucnUiLCJmaXJzdG5hbWUiOiLQndCw0LjQu9GMIiwibWlkZGxlbmFtZSI6ItCkIiwibGFzdG5hbWUiOiLQotCw0LfQtdGC0LTQuNC90L7QsiIsImdyb3VwcyI6bnVsbCwicHJlZmVycmVkX3VzZXJuYW1lIjoiIiwiZ2l2ZW5fbmFtZSI6IiIsImZhbWlseV9uYW1lIjoiIiwiZW1haWwiOiJudGF6ZXRkaW5vdkBudWJlcy5ydSJ9.MAkUzbgZYlJFc4aVqRlcxl6Zgv45e5mdJZq9UcCITiXVNtHFSqz9FtptNoeLy7XAYzvI3GMit7YNm_OUxYR_pZYY5W0hg4Gn68U0-nlGd3KaDMjX3QFuYJphQCLBYlkpiiuniju38MINcx6ccFXCW-_uEz7AC5UvQN8doQBr4YTGSNjvLaou13Vpqpz1b8XTaUp1S2gTHqcSJ-1-qxR8MgBguUNzPgZ384YTS7sZSJ3OXucgSrVHtaq5c7r-N7TzUuOqdAPND5bvOs47h17QftPhdVOI-pL8pqtnOTU3jsId01H8tI4u3lzDoet_cIK2cQVGu7J1zJlHOxwQOv8Xtw \ No newline at end of file diff --git a/package.json b/package.json index 2d2ae18..f522ad9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipwhitelist", - "version": "0.1.5", + "version": "0.1.6", "description": "IP WhiteList microservice for cloud provider", "main": "server.js", "scripts": { diff --git a/v2/src/config/index.js b/v2/src/config/index.js index e097ab7..5707233 100644 --- a/v2/src/config/index.js +++ b/v2/src/config/index.js @@ -8,7 +8,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ module.exports = { - version: '0.5.178', + version: '0.1.6', // ── IAM ────────────────────────────────────────────────────────────────── iamUrl: process.env.V2_IAM_URL || 'https://auth-api.ngcloud.ru/api/v1/auth/user', diff --git a/v2/src/router/index.js b/v2/src/router/index.js index 27f90a9..e65768b 100644 --- a/v2/src/router/index.js +++ b/v2/src/router/index.js @@ -53,7 +53,7 @@ async function checkImpersonation(token, req, u) { const imp = data.impersonation || {}; const newIsImp = !!(imp.is_impersonated); - const oldIsImp = !!(u.originalUserEmail && u.impersonatedCompanyId); + const oldIsImp = !!u.isImpersonated; // Статус не изменился — ничего не делаем if (newIsImp === oldIsImp) return; @@ -98,7 +98,7 @@ async function checkImpersonation(token, req, u) { } function applyContext(req, u) { - const isImpersonated = !!(u.originalUserEmail && u.impersonatedCompanyId); + const isImpersonated = !!(u.isImpersonated || u.originalUserEmail); req.email = u.email || ''; req.clientId = isImpersonated