jaxoncreed 3fea5c98f5
feat: Allow switching accounts
* feat: Allow logging out on the consent page

* feat: log in with a different account cleanup

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>
2022-08-03 08:19:22 +02:00

67 lines
1.9 KiB
Plaintext

<h1>Authorize</h1>
<p id="webId">Your WebID: </p>
<p>The following client wants to do authorized requests in your name:</p>
<ul id="clientInfo">
</ul>
<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 autofocus type="submit" name="submit">Consent</button>
<button onclick="logOut(event)">Log in with a different account</button>
</p>
</form>
<script>
async function logOut(e) {
e.preventDefault();
const res = await fetch('', {
method: 'POST',
headers: { accept: 'application/json', 'content-type': 'application/json' },
body: JSON.stringify({ logOut: true }),
});
const json = await res.json();
location.href = json.location;
}
</script>
<script>
function addWebId(webId) {
const p = document.getElementById('webId');
const strong = document.createElement('strong')
strong.appendChild(document.createTextNode(webId));
p.appendChild(strong);
}
const clientInfo = document.getElementById('clientInfo');
function addClientInfo(text, value) {
if (value) {
const li = document.createElement('li');
const strong = document.createElement('strong')
strong.appendChild(document.createTextNode(value));
li.appendChild(document.createTextNode(`${text}: `));
li.appendChild(strong);
clientInfo.appendChild(li);
}
}
// Update the client information
(async() => {
const res = await fetch('', { headers: { accept: 'application/json' } });
const { webId, client } = await res.json();
addWebId(webId);
addClientInfo('Name', client.client_name);
addClientInfo('ID', client.client_id);
})()
addPostListener('mainForm', 'error', '', () => { throw new Error('Expected a location field in the response.') });
</script>