italia / Satosa-Saml2Spid

SATOSA SAML-to-SAML proxy with Spid compliances
Apache License 2.0
42 stars 25 forks source link

Errors page single with localization (js version) #88

Open MdreW opened 1 year ago

MdreW commented 1 year ago

New proposal for errors page.

Use the same errors page for all errors and add more detail and localization with javascript.

For security reason the errors details can't be add from with a simple string, but must be decoded from the error's code.

With a javascript we read a json with all codes and his error details and add this in the error box.

Vantage:

example json:

en:
  '20':  ''Destination is not valid'
  '30': 'Issuer NameFormat is invalid'
it:
  '20': 'Destinazione di ritorno non valida'
  '30': 'issuer non valido'
MdreW commented 1 year ago

@peppelinux , I have written a simple demo for a errors page single with localization, is a really simple js. In this example I have added a single error (code 100) and I have added the ID 'error' at the page box.

errors.js

const localizations = {
  'it': {
    '100': 'Autenticazione fallita'
  },
  'en': {
    '100': 'Authentication fail'
  }
}

document.addEventListener("DOMContentLoaded", () => {
  let default_locale = 'it'
  let available_locales = ['it','en']
  let params = new URLSearchParams(window.location.search)
  let locale = available_locales.includes(params.get('locale')) ? params.get('locale') :  default_locale ;
  let element = document.getElementById('error') 
  if (localizations[locale][params.get('error')]) { 
    element.innerHTML = localizations[locale][params.get('error')] 
  }
});

Without options return the standard error page /static/error_page.html image

If I add the error option in the url and the error is present in the localization the page will be updated /static/error_page.html?error=100 image

Optionally I ca add also the locale option /static/error_page.html?locale=en&error=100 image

We can also detach the localization from the error.js, in a single locale json or with different json file for each locale. At this moment we have 24 different errors messages (SPID), I not know the wallet error prerequisite. Write more different files is cute but not mandatory.

What do you think about it?

peppelinux commented 10 months ago

@MdreW very interesting feature

I'd like to have it in 2.1.0 together with i18n in pyeudiw

if you can go ahead with a PR we'll get it in time, we won't change the templates in this version 2.0.0

MdreW commented 10 months ago

Ok, I will work for this :+1: