From 1dcba773d71a1465a7baf5696ab0d96ac3db0fcb Mon Sep 17 00:00:00 2001 From: Vincenzo Cestone Date: Wed, 14 Dec 2022 10:28:04 +0100 Subject: [PATCH] Details in fire(authenticated) events --- boot/d4s-boot.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/boot/d4s-boot.js b/boot/d4s-boot.js index ba2cecb..600a518 100644 --- a/boot/d4s-boot.js +++ b/boot/d4s-boot.js @@ -32,7 +32,20 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement { } fire(etype) { - const evt = new CustomEvent(etype, { detail : ''}) + const tp = this.#keycloak.tokenParsed + var outtp = { + aud: tp.aud, + azp: tp.azp, + email: tp.email, + email_verified: tp.email_verified, + exp: tp.exp, + family_name: tp.family_name, + given_name: tp.given_name, + locale: tp.locale, + name: tp.name, + preferred_username: tp.preferred_username + } + const evt = new CustomEvent(etype, { detail : outtp }) document.dispatchEvent(evt) } @@ -109,9 +122,7 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement { } }).then(token => { - console.log("Authorized") - console.log("Token exp: " + this.expirationDate(this.parseJwt(token).exp)) - //console.log("Datetime: " + (new Date())) + console.log("Authorized. Token exp: " + this.expirationDate(this.parseJwt(token).exp)) //transform all queued requests to fetches console.log("All pending requests to promises") let promises = this.#queue.map(r => { @@ -123,7 +134,7 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement { console.log("Resolving all fetches") return Promise.all(promises) - }).catch(err => console.error("Unable to make calls: " + err)) + }).catch(err => console.error("Unable to make calls: " + err)) // Sometimes throws: Unable to make calls: TypeError: Cannot read properties of undefined (reading 'split') } } }, 300) @@ -153,7 +164,7 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement { // onGrant callback function. // If authorization was successful you'll receive an RPT // with the necessary permissions to access the resource server - console.log(rpt) + //console.log(rpt) //console.log("rpt expires: " + expDt(parseJwt(rpt).exp)) }) } @@ -191,6 +202,7 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement { .then(response => response.json()) .then(json => { this.#config = json + console.log("Keycloak uma2 configuration loaded") resolve(true) }) .catch(err => reject("Failed to fetch uma2-configuration from server: " + err))