mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Clarify application consent screen.
This commit is contained in:
parent
3beb049afc
commit
7987824068
@ -1,8 +1,12 @@
|
|||||||
<h1>Authorize</h1>
|
<h1>An application is requesting access</h1>
|
||||||
<p id="webId">Your WebID: </p>
|
<p>
|
||||||
<p>The following client wants to do authorized requests in your name:</p>
|
Your WebID is <strong id="webId"></strong>
|
||||||
<ul id="clientInfo">
|
</p>
|
||||||
</ul>
|
<p>
|
||||||
|
Do you trust this application
|
||||||
|
to read and write data on your behalf?
|
||||||
|
</p>
|
||||||
|
<dl id="client"></dl>
|
||||||
<form method="post" id="mainForm">
|
<form method="post" id="mainForm">
|
||||||
<p class="error" id="error"></p>
|
<p class="error" id="error"></p>
|
||||||
|
|
||||||
@ -15,52 +19,54 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<p class="actions">
|
<p class="actions">
|
||||||
<button autofocus type="submit" name="submit">Consent</button>
|
<button id="authorize" type="submit" autofocus>Authorize</button>
|
||||||
<button onclick="logOut(event)">Log in with a different account</button>
|
<button id="cancel" type="button">Cancel</button>
|
||||||
|
<button id="switch" type="button" class="alternate">Use a different WebID</button>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
async function logOut(e) {
|
// Wire up elements
|
||||||
e.preventDefault();
|
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('', {
|
const res = await fetch('', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { accept: 'application/json', 'content-type': 'application/json' },
|
headers: { accept: 'application/json', 'content-type': 'application/json' },
|
||||||
body: JSON.stringify({ logOut: true }),
|
body: JSON.stringify({ logOut: true }),
|
||||||
});
|
});
|
||||||
const json = await res.json();
|
const body = await res.json();
|
||||||
location.href = json.location;
|
location.href = body.location;
|
||||||
}
|
}
|
||||||
</script>
|
</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>
|
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Returns an object that maps IDs to the corresponding element.
|
||||||
|
*
|
||||||
|
* @param ...ids - IDs of the element (empty to retrieve all elements)
|
||||||
|
*/
|
||||||
|
function getElements(...ids) {
|
||||||
|
ids = ids.length ? ids : [...document.querySelectorAll("[id]")].map(e => e.id);
|
||||||
|
return Object.fromEntries(ids.map(id => [id, document.getElementById(id)]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acquires all data from the given form and POSTs it as JSON to the target URL.
|
* Acquires all data from the given form and POSTs it as JSON to the target URL.
|
||||||
* In case of failure this function will throw an error.
|
* In case of failure this function will throw an error.
|
||||||
|
@ -138,6 +138,20 @@ ul ul, ol ul {
|
|||||||
padding-left: 1em;
|
padding-left: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dl {
|
||||||
|
padding: 0 0 0 2em;
|
||||||
|
margin: .75em 0 0;
|
||||||
|
}
|
||||||
|
dl dt {
|
||||||
|
font-weight: bold;
|
||||||
|
float: left;
|
||||||
|
clear: left;
|
||||||
|
min-width: 4em;
|
||||||
|
}
|
||||||
|
dl dt:after {
|
||||||
|
content: ": ";
|
||||||
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
overflow-x: scroll;
|
overflow-x: scroll;
|
||||||
}
|
}
|
||||||
@ -207,12 +221,30 @@ button {
|
|||||||
border: 0px;
|
border: 0px;
|
||||||
background-color: var(--solid-purple);
|
background-color: var(--solid-purple);
|
||||||
color: white;
|
color: white;
|
||||||
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
}
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: var(--solid-blue);
|
background-color: var(--solid-blue);
|
||||||
}
|
}
|
||||||
|
button[type=submit] {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.alternate {
|
||||||
|
display: block;
|
||||||
|
padding: 0;
|
||||||
|
margin: .5em 0;
|
||||||
|
|
||||||
|
background: none;
|
||||||
|
color: var(--solid-purple);
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
button.alternate:hover {
|
||||||
|
color: var(--solid-blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus, button:focus {
|
||||||
|
outline: var(--solid-blue) solid 1.5px;
|
||||||
|
}
|
||||||
|
|
||||||
form p.actions {
|
form p.actions {
|
||||||
margin: .5em 0 1em 11em;
|
margin: .5em 0 1em 11em;
|
||||||
@ -222,6 +254,9 @@ form p.error {
|
|||||||
color: #ad0f0f;
|
color: #ad0f0f;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
form p.error:empty {
|
||||||
|
display :none;
|
||||||
|
}
|
||||||
|
|
||||||
form ul.actions {
|
form ul.actions {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user