Browse Source

working on javascript compatibility for old browsers

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
sqlite
Stephan Richter 3 months ago
parent
commit
50e9574c27
  1. 73
      de.srsoftware.oidc.web/src/main/resources/en/scripts/authorization.js
  2. 2
      de.srsoftware.oidc.web/src/main/resources/en/scripts/logout.js

73
de.srsoftware.oidc.web/src/main/resources/en/scripts/authorization.js

@ -1,52 +1,66 @@
var params = new URLSearchParams(window.location.search) var params = new URLSearchParams(window.location.search)
var json = Object.fromEntries(params); var json = paramsToObject(params);
var scopes = {}; var scopes = {};
// Replacement for Object.toEntries(…)
function paramsToObject(entries) {
const result = {};
for(var key of entries) { // each 'entry' is a [key, value] tupple
result[key[0]] = key[1];
}
return result;
}
function showConfirmationDialog(name){ function showConfirmationDialog(name){
get('name').innerHTML = name; get('name').innerHTML = name;
show('content'); show('content');
} }
async function showScope(response,scope){ function showScope(response,scope){
if (response.ok){ if (response.ok){
var content = await response.text(); response.text().then(content => {
get('scopes').innerHTML += content; get('scopes').innerHTML += content
});
} else { } else {
get('scopes').innerHTML += '<li>'+scope+' (???)</li>'; get('scopes').innerHTML += '<li>'+scope+' (???)</li>';
} }
} }
async function handleResponse(response){ function handleResponse(response){
if (response.ok){ if (response.ok){
var json = await response.json(); response.json().then(json => {
if (json.rp) { if (json.rp) {
setText("rp",json.rp); setText("rp",json.rp);
setText("rp2",json.rp); setText("rp2",json.rp);
}
get('scopes').innerHTML = '';
if (json.unauthorized_scopes){
scopes = json.unauthorized_scopes;
for (var scope of json.unauthorized_scopes){
fetch(web+"scopes/"+scope+".html").then(response => showScope(response,scope))
} }
show("content"); get('scopes').innerHTML = '';
return; if (json.unauthorized_scopes){
} scopes = json.unauthorized_scopes;
if (json.scope){ for (var scope of json.unauthorized_scopes){
var url = params.get('redirect_uri') + '?' + new URLSearchParams(json).toString(); fetch(web+"scopes/"+scope+".html",{credentials:'include'}).then(response => showScope(response,scope))
redirect(url); }
return; show("content");
} return;
show('missing_scopes'); }
if (json.scope){
var query = Object.keys(json).map(key => `${key}=${encodeURIComponent(json[key])}`).join('&');
var url = params.get('redirect_uri') + '?' + query.toString();
redirect(url);
return;
}
show('missing_scopes');
});
} else { } else {
console.log("handleResponse(…) ← ",response); console.log("handleResponse(…) ← ",response);
if (response.status == 401){ if (response.status == 401){
login(); login();
return; return;
} }
var json = await response.json(); response.json().then(json => {
setText('error',"Error: <br/>"+json.error_description); setText('error',"Error: <br/>"+json.error_description);
show('error'); show('error');
});
if (json.error != "invalid_request_uri"){ if (json.error != "invalid_request_uri"){
var url = params.get('redirect_uri') + '?' + new URLSearchParams(json).toString(); var url = params.get('redirect_uri') + '?' + new URLSearchParams(json).toString();
console.log('redirecting to '+url); console.log('redirecting to '+url);
@ -70,8 +84,9 @@ function backendAutorization(){
body: JSON.stringify(json), body: JSON.stringify(json),
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} },
credentials:'include'
}).then(handleResponse); }).then(handleResponse);
} }
backendAutorization(); backendAutorization();

2
de.srsoftware.oidc.web/src/main/resources/en/scripts/logout.js

@ -2,4 +2,4 @@ function handleLogout(response){
if (response.ok) document.body.innerHTML += 'success'; if (response.ok) document.body.innerHTML += 'success';
redirect('index.html') redirect('index.html')
} }
fetch(user_controller+"/logout").then(handleLogout) fetch(user_controller+"/logout",{credentials:'include'}).then(handleLogout)

Loading…
Cancel
Save