'use strict'; const form = document.getElementById('login-form'); const button = document.getElementById('nsg-x1-logon-button'); const message = document.getElementById('message'); async function authenticate(path, body) { const response = await fetch(path, { method: 'POST', body, credentials: 'same-origin', redirect: 'error', headers: { Accept: 'application/vnd.citrix.authenticateresponse-1+xml' }, signal: AbortSignal.timeout(10000) }); if (!response.ok) throw new Error('Request failed'); const result = rdx.utils.authentication(await response.text()); form.elements.StateContext.value = result.state; // Only the local authentication endpoint can receive form credentials. if (result.postback === '/nf/auth/doAuthentication.do') form.action = result.postback; return result; } const ready = authenticate('/nf/auth/getAuthenticationRequirements.do', new URLSearchParams()) .catch(() => null); form.addEventListener('submit', async event => { event.preventDefault(); button.disabled = true; message.textContent = ''; try { await ready; const body = new URLSearchParams(new FormData(form)); body.set('nsg-x1-logon-button', 'Log On'); const result = await authenticate('/nf/auth/doAuthentication.do', body); message.textContent = result.errors.join(' ') || 'Anmeldung fehlgeschlagen. Überprüfen Sie Ihre Zugangsdaten.'; } catch { message.textContent = 'Die Anmeldung ist derzeit nicht möglich. Versuchen Sie es erneut.'; } finally { form.elements.passwd.value = ''; button.disabled = false; } });