Add user-bound external MCP server and OAuth access
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<!doctype html>
|
||||
<html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Подключение ИИ — Инфосмета</title>
|
||||
<style>
|
||||
body{font:16px/1.5 system-ui,sans-serif;background:#f5f7fa;color:#202735;margin:0;padding:24px}
|
||||
main{max-width:550px;margin:8vh auto;background:white;padding:32px;border-radius:16px;box-shadow:0 4px 32px #172c451a}
|
||||
h1{font-size:1.5rem}ul{padding-left:1.4rem}button{border:0;border-radius:8px;padding:12px 18px;font:inherit;cursor:pointer}
|
||||
#approve{background:#1868cf;color:white}#deny{background:#e9edf3;color:#202735}p.status{min-height:1.5em}
|
||||
</style></head><body><main>
|
||||
<h1>Подключить внешний ИИ</h1>
|
||||
<p id="client"></p><p>После разрешения приложение сможет действовать от вашего имени в указанных пределах.</p>
|
||||
<ul id="scopes"></ul>
|
||||
<p id="login" hidden>Войдите в Инфосмету в соседней вкладке, затем вернитесь сюда. <a href="/" target="_blank" rel="noopener">Открыть вход</a></p>
|
||||
<p class="status" id="status" role="status"></p>
|
||||
<button id="approve" type="button">Разрешить</button> <button id="deny" type="button">Отказать</button>
|
||||
</main><script>
|
||||
(async () => {
|
||||
const ticket = new URLSearchParams(location.search).get('ticket');
|
||||
const status = document.getElementById('status');
|
||||
if (!ticket) { status.textContent = 'Ссылка неполная.'; return; }
|
||||
const info = await fetch('/api/mcp/consent?ticket=' + encodeURIComponent(ticket), {cache:'no-store'});
|
||||
if (!info.ok) { status.textContent = 'Запрос устарел. Начните подключение заново.'; return; }
|
||||
const data = await info.json();
|
||||
document.getElementById('client').textContent = 'Приложение: ' + data.client_name;
|
||||
const list = document.getElementById('scopes');
|
||||
for (const scope of data.scopes) { const li=document.createElement('li'); li.textContent=scope; list.append(li); }
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) document.getElementById('login').hidden = false;
|
||||
async function decide(approved) {
|
||||
const bearer = localStorage.getItem('token');
|
||||
if (!bearer) { document.getElementById('login').hidden=false; status.textContent='Сначала войдите в Инфосмету.'; return; }
|
||||
status.textContent='Проверяем доступ…';
|
||||
const res=await fetch('/oauth/consent',{method:'POST',headers:{'Content-Type':'application/json','Authorization':'Bearer '+bearer},body:JSON.stringify({ticket,approved})});
|
||||
if (res.status===401) { document.getElementById('login').hidden=false; status.textContent='Вход истёк. Войдите снова.'; return; }
|
||||
if (!res.ok) { status.textContent='Не удалось завершить подключение. Повторите его из клиента.'; return; }
|
||||
location.assign((await res.json()).redirect);
|
||||
}
|
||||
document.getElementById('approve').onclick=()=>decide(true);
|
||||
document.getElementById('deny').onclick=()=>decide(false);
|
||||
})();
|
||||
</script></body></html>
|
||||
Reference in New Issue
Block a user