scorpiox-bot-plugin-claudecode-login
←ui.htmlhtml
399 lines · 16 KBHEADBlameDownload
1<!DOCTYPE html>
2<html lang="en"><head><meta charset="utf-8">
3<meta name="viewport" content="width=device-width,initial-scale=1">
4<title>claude</title>
5<!--TOKENS-->
6<style>
7*{box-sizing:border-box}
8html,body{margin:0;min-height:100%}
9body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;
10 line-height:1.5;-webkit-font-smoothing:antialiased}
11#app{max-width:840px;margin:0 auto;padding:16px 16px 40px}
12.hd{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:14px}
13.hd .grow{flex:1 1 auto;min-width:0}
14.hd h1{margin:0;font-size:18px;font-weight:650;letter-spacing:-.01em}
15.hd .sub{font-size:11.5px;color:var(--text-2);margin-top:2px;white-space:nowrap;
16 overflow:hidden;text-overflow:ellipsis}
17.pill{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;font-weight:650;
18 padding:4px 10px;border-radius:999px;background:var(--surface-2);color:var(--text-2);
19 border:1px solid var(--line);white-space:nowrap}
20.pill .dot{width:7px;height:7px;border-radius:50%;background:var(--gray);flex:0 0 auto}
21.pill.ok{color:var(--green);border-color:rgba(48,209,88,.35)}
22.pill.ok .dot{background:var(--green);box-shadow:0 0 0 3px rgba(48,209,88,.15)}
23.pill.warn{color:var(--orange);border-color:rgba(255,159,10,.35)}
24.pill.warn .dot{background:var(--orange)}
25.pill.off .dot{background:var(--gray)}
26.card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px;
27 padding:16px;margin-bottom:12px}
28.card h2{margin:0 0 4px;font-size:13px;font-weight:700;letter-spacing:.08em;
29 text-transform:uppercase;color:var(--text-2)}
30.card .lead{margin:0 0 12px;font-size:12.5px;color:var(--text-2)}
31.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
32.btn{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:7px 16px;
33 font-weight:600;font-size:13px;cursor:pointer;font-family:inherit;
34 transition:transform .12s var(--ease),opacity .12s}
35.btn:active{transform:scale(.98)}
36.btn:disabled{opacity:.5;cursor:default}
37.btn.ghost{background:var(--surface-2);color:var(--text);border:1px solid var(--line)}
38.btn.ghost:hover{background:var(--surface-hover);border-color:var(--line-2)}
39.btn.danger{background:transparent;color:var(--red);border:1px solid rgba(255,69,58,.35)}
40a.btn{display:inline-flex;align-items:center;gap:6px;text-decoration:none}
41.kv{display:grid;grid-template-columns:132px minmax(0,1fr);gap:6px 12px;font-size:13px}
42.kv .k{color:var(--text-2);font-size:12px}
43.kv .v{font-family:var(--mono);font-size:12px;word-break:break-all}
44.kv .v.plain{font-family:var(--font);font-size:13px}
45.step{display:none}
46.step.on{display:block}
47.hint{margin:10px 0 0;font-size:12px;color:var(--text-2)}
48.note{font-size:12.5px;margin-top:10px;display:none}
49.note.show{display:block}
50.note.err{color:var(--red)}
51.note.ok{color:var(--green)}
52.authurl{font-family:var(--mono);font-size:11.5px;color:var(--text-2);word-break:break-all;
53 background:var(--code-bg);border:1px solid var(--line);border-radius:10px;
54 padding:10px;margin-top:10px;max-height:120px;overflow:auto}
55textarea{width:100%;margin-top:10px;min-height:74px;resize:vertical;background:var(--input-bg);
56 color:var(--text);border:1px solid var(--line);border-radius:10px;padding:10px;
57 font-family:var(--mono);font-size:12px;outline:none}
58textarea:focus{border-color:var(--blue)}
59.count{font-size:34px;font-weight:700;letter-spacing:-.02em;line-height:1.1}
60.count small{font-size:13px;font-weight:600;color:var(--text-2);letter-spacing:0}
61.bar{height:6px;border-radius:999px;background:var(--surface-2);overflow:hidden;margin-top:10px}
62.bar .fill{display:block;height:100%;background:var(--green);border-radius:999px;
63 transition:width .3s var(--ease)}
64.bar.warn .fill{background:var(--orange)}
65.bar.err .fill{background:var(--red)}
66.spin{width:12px;height:12px;border-radius:50%;border:2px solid rgba(255,255,255,.35);
67 border-top-color:#fff;display:none;animation:sp .7s linear infinite}
68.btn.loading .spin{display:inline-block}
69@keyframes sp{to{transform:rotate(360deg)}}
70.acct{display:flex;align-items:center;gap:10px;padding:8px 0;border-top:1px solid var(--line);
71 font-size:13px;flex-wrap:wrap}
72.acct:first-of-type{border-top:0}
73.acct .nm{font-family:var(--mono);font-size:12px;flex:1 1 120px;min-width:0;
74 overflow:hidden;text-overflow:ellipsis}
75.acct .tag{font-size:11px;color:var(--text-2)}
76.acct .tag.ok{color:var(--green)}
77.acct .tag.warn{color:var(--orange)}
78.empty{padding:10px 0;color:var(--text-2);font-size:12.5px}
79.toast{position:fixed;left:50%;bottom:18px;transform:translate(-50%,14px);opacity:0;
80 pointer-events:none;background:var(--modal-bg);border:1px solid var(--line-2);
81 color:var(--text);border-radius:999px;padding:8px 16px;font-size:12.5px;
82 box-shadow:var(--shadow-lg);transition:opacity .18s var(--ease),transform .18s var(--ease);
83 z-index:9;max-width:calc(100vw - 32px)}
84.toast.show{opacity:1;transform:translate(-50%,0)}
85#themeToggle{background:var(--surface-2);border:1px solid var(--line);color:var(--text);
86 border-radius:980px;padding:5px 12px;font-size:12px;font-weight:600;cursor:pointer;
87 font-family:inherit}
88@media (max-width:520px){
89 #app{padding:12px 12px 32px}
90 .kv{grid-template-columns:1fr;gap:2px 0}
91 .kv .k{margin-top:8px}
92 .card{padding:13px;border-radius:12px}
93 .count{font-size:28px}
94}
95</style>
96</head>
97<body>
98<div id="app">
99 <div class="hd">
100 <div class="grow">
101 <h1>Claude Code</h1>
102 <div class="sub" id="sub">OAuth PKCE login on this node</div>
103 </div>
104 <span class="pill off" id="pill"><span class="dot"></span><span id="pillText">Checking</span></span>
105 <button id="themeToggle" class="embed-hide" type="button">Theme</button>
106 </div>
107
108 <div class="card">
109 <h2>Session</h2>
110 <p class="lead" id="sessionLead">Reading the local Claude Code credentials.</p>
111 <div class="count" id="count">-</div>
112 <div class="bar" id="bar"><span class="fill" id="fill" style="width:0%"></span></div>
113 <div class="kv" id="session" style="margin-top:14px"></div>
114 <div class="row" style="margin-top:14px">
115 <button class="btn ghost" id="btnRefresh" type="button"><span class="spin"></span>Refresh Token Now</button>
116 <button class="btn ghost" id="btnReload" type="button">Reload</button>
117 </div>
118 <div class="note" id="refreshNote"></div>
119 </div>
120
121 <div class="card">
122 <h2>OAuth login</h2>
123 <p class="lead">Sign in with Claude. Nothing leaves this node: the login CLI performs the
124 exchange and writes the credential file here.</p>
125
126 <div class="step on" id="step1">
127 <div class="row">
128 <button class="btn" id="btnStart" type="button">Start Claude Login</button>
129 <button class="btn ghost" id="btnRelogin" type="button">Re-login (replace)</button>
130 </div>
131 <p class="hint">This generates a PKCE challenge and an authorization link. No token is
132 created until you paste the code back.</p>
133 </div>
134
135 <div class="step" id="step2">
136 <div class="row">
137 <a class="btn" id="linkOpen" href="#" target="_blank" rel="noopener noreferrer">Open Claude.ai</a>
138 <button class="btn ghost" id="btnCopy" type="button">Copy link</button>
139 <button class="btn ghost" id="btnCancel" type="button">Cancel</button>
140 </div>
141 <div class="authurl" id="authUrl"></div>
142 <p class="hint" id="flowHint">After approving, Claude shows an authorization code. Paste the
143 whole redirect address or just the <span style="font-family:var(--mono)">code=</span> value below.</p>
144 <textarea id="codeInput" spellcheck="false" autocomplete="off"
145 placeholder="Paste the authorization code or the full redirect URL"></textarea>
146 <div class="row" style="margin-top:10px">
147 <button class="btn" id="btnFinish" type="button">Submit Code</button>
148 </div>
149 <div class="note" id="loginNote"></div>
150 </div>
151 </div>
152
153 <div class="card">
154 <h2>Named accounts</h2>
155 <p class="lead">Every account file in the local accounts directory.</p>
156 <div id="accounts"><div class="empty">No named accounts.</div></div>
157 </div>
158</div>
159
160<div class="toast" id="toast"></div>
161
162<script>
163var q=new URLSearchParams(location.search);
164var node=q.get('node')||'';
165var sid=q.get('id')||'';
166var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||
167 localStorage.getItem('bot_active_pwd')||'';
168
169/* Two call routes. Getting this wrong is the most common plugin bug:
170 * page served through the hub (bot.scorpiox.net/plugins?plugin=...&node=..)
171 * -> call the hub proxy back: /plugins?plugin=plugin_claudecode_login&action=..
172 * opened directly on the node
173 * -> the plugin itself is the route: /plugin_claudecode_login?action=..
174 * Calling /plugins?plugin= on the node returns the discovery list, not us. */
175var HUB=q.get('plugin')||'';
176function url(action,extra){
177 return (HUB?'/plugins?plugin='+encodeURIComponent(HUB):'/plugin_claudecode_login')+
178 '?action='+encodeURIComponent(action)+
179 (extra?('&'+extra):'')+
180 (node?'&node='+encodeURIComponent(node):'')+
181 (sid?'&id='+encodeURIComponent(sid):'')+
182 (pwd?'&pwd='+encodeURIComponent(pwd):'');
183}
184function hdr(){
185 var h={};
186 if(pwd)h['X-Bot-Password']=pwd;
187 return h;
188}
189function api(action,extra){
190 return fetch(url(action,extra),{headers:hdr()}).then(function(r){
191 return r.json().catch(function(){return {ok:false,error:'bad response'};});
192 });
193}
194
195var $=function(id){return document.getElementById(id);};
196function toast(msg){
197 var t=$('toast');t.textContent=msg;t.classList.add('show');
198 clearTimeout(t._t);t._t=setTimeout(function(){t.classList.remove('show');},2200);
199}
200function note(el,msg,kind){
201 el.textContent=msg||'';
202 el.className='note'+(msg?' show '+(kind||''):'');
203}
204function kv(el,rows){
205 el.innerHTML='';
206 rows.forEach(function(r){
207 var a=document.createElement('div');a.className='k';a.textContent=r[0];
208 var b=document.createElement('div');b.className='v'+(r[2]?' plain':'');
209 b.textContent=r[1];el.appendChild(a);el.appendChild(b);
210 });
211}
212function fmtExpiry(sec){
213 if(typeof sec!=='number')return '-';
214 if(sec<=0)return 'expired';
215 if(sec<90)return sec+'s';
216 if(sec<5400)return Math.round(sec/60)+' min';
217 if(sec<172800)return Math.round(sec/3600)+' h';
218 if(sec<63072000)return Math.round(sec/86400)+' d';
219 return Math.round(sec/31536000)+' yr';
220}
221function countdown(sec){
222 if(typeof sec!=='number'||sec<=0)return ['-',''];
223 var d=Math.floor(sec/86400),h=Math.floor((sec%86400)/3600),
224 m=Math.floor((sec%3600)/60),s=sec%60,u='second';
225 var v,d2;
226 if(d>0){v=d;u='day';d2=[h+'h',m+'m'].join(' ');}
227 else if(h>0){v=h;u='hour';d2=[m+'m'].join(' ');}
228 else if(m>0){v=m;u='minute';d2=[s+'s'].join(' ');}
229 else {v=s;d2='';}
230 return [v+' <small>'+(v===1?u:u+'s')+(d2?' &middot; '+d2:'')+'</small>',''];
231}
232function setPill(st){
233 var p=$('pill'),t=$('pillText');
234 if(st.logged_in&&st.expired){p.className='pill warn';t.textContent='Expired';}
235 else if(st.logged_in){p.className='pill ok';t.textContent='Logged In';}
236 else if(st.pending){p.className='pill warn';t.textContent='Signing in';}
237 else {p.className='pill off';t.textContent='Not Connected';}
238}
239/* Full token lifetime is 8 h for a Claude Code session; the bar is a share of
240 * the remaining time, so it is a coarse but honest "how much is left" read.
241 * A countdown of 0 with a refresh token present is the normal steady state. */
242var LIFETIME=8*3600;
243function render(st){
244 setPill(st);
245 $('sub').textContent=st.account?st.account:'OAuth PKCE login on this node';
246
247 if(st.logged_in){
248 $('sessionLead').textContent=st.expired
249 ? 'The session is present but its access token has expired. Use Refresh Token Now.'
250 : 'This node holds a Claude Code session.';
251 }else{
252 $('sessionLead').textContent='No Claude Code session on this node yet. Start a login below.';
253 }
254
255 var c=countdown(st.expires_in_sec);
256 $('count').innerHTML=st.logged_in?c[0]:'not connected';
257 var pct=0;
258 if(st.logged_in&&st.expires_in_sec>0){
259 pct=Math.max(2,Math.min(100,Math.round(st.expires_in_sec/LIFETIME*100)));
260 }
261 $('fill').style.width=pct+'%';
262 $('bar').className='bar'+(st.expired?' err':(pct<20?' warn':''));
263 if(!st.logged_in)$('bar').className='bar';
264
265 kv($('session'),[
266 ['Account', st.account||'-', true],
267 ['Logged in', st.logged_in?'yes':'no', true],
268 ['Refresh token', st.has_refresh?'stored':'none', true],
269 ['Token expires', st.logged_in?fmtExpiry(st.expires_in_sec):'-', true],
270 ['Subscription', st.subscription||'-', true],
271 ['Login pending', st.pending?'yes':'no', true],
272 ['Login CLI', st.cli_present?'found':'not found', true],
273 ['Profile', st.profile_exists?(st.profile||'claude_code'):'not created', true],
274 ['Credentials', st.credentials_path||'-']
275 ]);
276
277 var box=$('accounts');
278 box.innerHTML='';
279 var list=st.accounts||[];
280 if(!list.length){
281 var e=document.createElement('div');e.className='empty';
282 e.textContent='No named accounts.';box.appendChild(e);
283 }else{
284 list.forEach(function(a){
285 var row=document.createElement('div');row.className='acct';
286 var nm=document.createElement('div');nm.className='nm';nm.textContent=a.name;
287 var tg=document.createElement('div');
288 tg.className='tag '+(a.logged_in?(a.expired?'warn':'ok'):'');
289 tg.textContent=a.logged_in?(a.expired?'expired':'valid'):'no token';
290 row.appendChild(nm);row.appendChild(tg);box.appendChild(row);
291 });
292 }
293
294 if(st.pending){$('step1').classList.remove('on');$('step2').classList.add('on');}
295}
296function load(){
297 return api('status').then(function(d){
298 if(d&&d.ok)render(d);
299 else toast((d&&d.error)||'status failed');
300 }).catch(function(e){toast('Status failed: '+e.message);});
301}
302
303var authUrl='';
304function start(force){
305 var b=force?$('btnRelogin'):$('btnStart');
306 b.disabled=true;b.textContent='Starting...';
307 api('start',force?'force=1':'').then(function(d){
308 b.disabled=false;b.textContent=force?'Re-login (replace)':'Start Claude Login';
309 if(!d||!d.ok){toast((d&&(d.detail||d.error))||'start failed');return;}
310 authUrl=d.auth_url||'';
311 $('authUrl').textContent=authUrl;
312 $('linkOpen').setAttribute('href',authUrl);
313 if(d.hint)$('flowHint').textContent=d.hint;
314 $('step1').classList.remove('on');
315 $('step2').classList.add('on');
316 $('codeInput').focus();
317 }).catch(function(e){
318 b.disabled=false;b.textContent=force?'Re-login (replace)':'Start Claude Login';
319 toast('Start failed: '+e.message);
320 });
321}
322
323function finish(){
324 var raw=$('codeInput').value.trim();
325 if(!raw){note($('loginNote'),'Paste the code or the redirect address first.','err');return;}
326 var b=$('btnFinish');
327 b.disabled=true;b.textContent='Exchanging...';
328 note($('loginNote'),'Exchanging the code for a token.');
329 api('finish','code='+encodeURIComponent(raw)).then(function(d){
330 b.disabled=false;b.textContent='Submit Code';
331 if(!d||!d.ok){
332 note($('loginNote'),(d&&(d.detail||d.error))||'exchange failed','err');
333 return;
334 }
335 note($('loginNote'),'');
336 $('step2').classList.remove('on');
337 $('step1').classList.add('on');
338 $('codeInput').value='';
339 render(d);
340 toast('Signed in as '+(d.account||'Claude account'));
341 }).catch(function(e){
342 b.disabled=false;b.textContent='Submit Code';
343 note($('loginNote'),'Exchange failed: '+e.message,'err');
344 });
345}
346
347function cancel(){
348 api('cancel').then(function(){
349 $('step2').classList.remove('on');
350 $('step1').classList.add('on');
351 $('codeInput').value='';
352 note($('loginNote'),'');
353 toast('Pending login cancelled');
354 load();
355 }).catch(function(e){toast('Cancel failed: '+e.message);});
356}
357
358function refreshToken(){
359 var b=$('btnRefresh');
360 b.disabled=true;b.classList.add('loading');
361 b.lastChild.textContent=' Refreshing...';
362 note($('refreshNote'),'Asking Claude for a new access token...');
363 api('refresh').then(function(d){
364 b.disabled=false;b.classList.remove('loading');
365 b.lastChild.textContent='Refresh Token Now';
366 if(!d||!d.ok){
367 note($('refreshNote'),(d&&(d.detail||d.error))||'refresh failed','err');
368 return;
369 }
370 note($('refreshNote'),'Token refreshed. Expires in '+fmtExpiry(d.expires_in_sec)+'.','ok');
371 render(d);
372 }).catch(function(e){
373 b.disabled=false;b.classList.remove('loading');
374 b.lastChild.textContent='Refresh Token Now';
375 note($('refreshNote'),'Refresh failed: '+e.message,'err');
376 });
377}
378
379function copyLink(){
380 if(!authUrl)return;
381 var done=function(){toast('Link copied');};
382 if(navigator.clipboard&&navigator.clipboard.writeText){
383 navigator.clipboard.writeText(authUrl).then(done).catch(function(){toast('Copy failed');});
384 }else{toast('Copy not available');}
385}
386
387$('btnStart').onclick=function(){start(false);};
388$('btnRelogin').onclick=function(){start(true);};
389$('btnFinish').onclick=finish;
390$('btnCancel').onclick=cancel;
391$('btnRefresh').onclick=refreshToken;
392$('btnReload').onclick=load;
393$('btnCopy').onclick=copyLink;
394$('codeInput').addEventListener('keydown',function(e){
395 if(e.key==='Enter'&&(e.metaKey||e.ctrlKey)){e.preventDefault();finish();}
396});
397load();
398</script>
399</body></html>