v0.5.146: /iam_response_test, /iam_response_dev
This commit is contained in:
+57
-8
@@ -58,19 +58,38 @@ function createV2Router() {
|
||||
const mainAuth = require('../src/auth');
|
||||
const iamData = await mainAuth.fetchIamUser(token);
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send('<!DOCTYPE html>\n<html><head><meta charset="utf-8"><title>IAM Raw</title>'
|
||||
+ '<style>body{font-family:monospace;background:#111;color:#eee;padding:20px}'
|
||||
+ 'pre{background:#1a1a2e;padding:15px;border-radius:8px;overflow-x:auto;font-size:13px}'
|
||||
+ 'h2{color:#4fc3f7}a{color:#80cbc4}</style></head><body>'
|
||||
+ '<h2>Сырой ответ IAM</h2>'
|
||||
+ '<pre>' + JSON.stringify(iamData.raw, null, 2).replace(/</g, '<') + '</pre>'
|
||||
+ '<p><a href="/v2/iam">← Сессия</a> | <a href="/v2/app">CRUD</a></p>'
|
||||
+ '</body></html>');
|
||||
res.send(rawPage('IAM PROD', iamData.raw));
|
||||
} catch (e) {
|
||||
res.send('<h2>Ошибка IAM</h2><pre>' + e.message + '</pre>');
|
||||
}
|
||||
});
|
||||
|
||||
// ── GET /v2/iam_response_test — IAM test стенд ──────────────────────
|
||||
router.get('/iam_response_test', async (req, res) => {
|
||||
const token = req.session && req.session.token;
|
||||
if (!token) return res.send('<h2>Нет токена</h2><p><a href="/v2/login">Войти</a></p>');
|
||||
try {
|
||||
const raw = await iamFetch(token, 'https://auth-api-test.ngcloud.ru/api/v1/auth/user');
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send(rawPage('IAM TEST', raw));
|
||||
} catch (e) {
|
||||
res.send('<h2>Ошибка IAM Test</h2><pre>' + e.message + '</pre>');
|
||||
}
|
||||
});
|
||||
|
||||
// ── GET /v2/iam_response_dev — IAM dev стенд ────────────────────────
|
||||
router.get('/iam_response_dev', async (req, res) => {
|
||||
const token = req.session && req.session.token;
|
||||
if (!token) return res.send('<h2>Нет токена</h2><p><a href="/v2/login">Войти</a></p>');
|
||||
try {
|
||||
const raw = await iamFetch(token, 'https://auth-api-dev.ngcloud.ru/api/v1/auth/user');
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send(rawPage('IAM DEV', raw));
|
||||
} catch (e) {
|
||||
res.send('<h2>Ошибка IAM Dev</h2><pre>' + e.message + '</pre>');
|
||||
}
|
||||
});
|
||||
|
||||
// ── /v2/app — пользовательский CRUD (только с сессией) ──────────────
|
||||
router.use('/app', enhanceImpersonation, resolveContext, createUserRouter());
|
||||
|
||||
@@ -97,6 +116,36 @@ function createV2Router() {
|
||||
return router;
|
||||
}
|
||||
|
||||
// ── Хелпер: HTTP-запрос к IAM ────────────────────────────────────────────────
|
||||
async function iamFetch(token, url) {
|
||||
const https = require('https');
|
||||
const u = new URL(url);
|
||||
return new Promise((resolve, reject) => {
|
||||
https.get({
|
||||
hostname: u.hostname, port: 443, path: u.pathname,
|
||||
headers: { Authorization: 'Bearer ' + token, Accept: 'application/json' },
|
||||
}, res => {
|
||||
let data = '';
|
||||
res.on('data', c => data += c);
|
||||
res.on('end', () => {
|
||||
if (res.statusCode !== 200) return reject(new Error(res.statusCode + ': ' + data.slice(0, 200)));
|
||||
try { resolve(JSON.parse(data)); } catch (e) { reject(e); }
|
||||
});
|
||||
}).on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
function rawPage(title, data) {
|
||||
return '<!DOCTYPE html>\n<html><head><meta charset="utf-8"><title>' + title + '</title>'
|
||||
+ '<style>body{font-family:monospace;background:#111;color:#eee;padding:20px}'
|
||||
+ 'pre{background:#1a1a2e;padding:15px;border-radius:8px;overflow-x:auto;font-size:13px}'
|
||||
+ 'h2{color:#4fc3f7}a{color:#80cbc4}</style></head><body>'
|
||||
+ '<h2>Сырой ответ ' + title + '</h2>'
|
||||
+ '<pre>' + JSON.stringify(data, null, 2).replace(/</g, '<') + '</pre>'
|
||||
+ '<p><a href="/v2/iam">← Сессия</a> | <a href="/v2/app">CRUD</a></p>'
|
||||
+ '</body></html>';
|
||||
}
|
||||
|
||||
function debugPage(u, version) {
|
||||
return `<!DOCTYPE html>
|
||||
<html><head><meta charset="utf-8"><title>V2 — IAM</title>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
module.exports = {
|
||||
version: '0.5.145',
|
||||
version: '0.5.146',
|
||||
|
||||
// ── IAM ──────────────────────────────────────────────────────────────────
|
||||
iamUrl: process.env.V2_IAM_URL || 'https://auth-api.ngcloud.ru/api/v1/auth/user',
|
||||
|
||||
Reference in New Issue
Block a user