2022-09-20 13:12:57 +02:00

73 lines
2.0 KiB
Plaintext

<h1>An application is requesting access</h1>
<p>
Your WebID is <strong id="webId"></strong>
</p>
<p>
Do you trust this application
to read and write data on your behalf?
</p>
<dl id="client"></dl>
<form method="post" id="mainForm">
<p class="error" id="error"></p>
<fieldset>
<ol>
<li class="checkbox">
<label><input type="checkbox" name="remember" value="yes" checked>Remember this client</label>
</li>
</ol>
</fieldset>
<p class="actions">
<button id="authorize" type="submit" autofocus>Authorize</button>
<button id="cancel" type="button">Cancel</button>
<button id="switch" type="button" class="alternate">Use a different WebID</button>
</p>
</form>
<script>
// Wire up elements
const elements = getElements();
elements.cancel.addEventListener('click', logOut);
elements.switch.addEventListener('click', logOut);
addPostListener('mainForm', 'error', '', () => {
throw new Error('Expected a location field in the response.');
});
// Retrieve and display client information
(async() => {
const res = await fetch('', { headers: { accept: 'application/json' } });
const { webId, client } = await res.json();
showWebId(webId);
showClientInfo('Name', client.client_name);
showClientInfo('ID', client.client_id);
})();
// Updates the user's WebID in the UI
function showWebId(webId) {
elements.webId.innerText = webId;
}
// Adds client info to the UI
function showClientInfo(label, value) {
if (value) {
const dt = document.createElement('dt');
const dd = document.createElement('dd')
dt.innerText = label;
dd.innerText = value;
elements.client.append(dt, dd);
}
}
// Logs the user out
async function logOut(event) {
const res = await fetch('', {
method: 'POST',
headers: { accept: 'application/json', 'content-type': 'application/json' },
body: JSON.stringify({ logOut: true }),
});
const body = await res.json();
location.href = body.location;
}
</script>