Details in fire(authenticated) events

This commit is contained in:
Vincenzo Cestone 2022-12-14 10:28:04 +01:00
parent f4cf544f4f
commit 1dcba773d7
1 changed files with 18 additions and 6 deletions

View File

@ -32,7 +32,20 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement {
} }
fire(etype) { 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) document.dispatchEvent(evt)
} }
@ -109,9 +122,7 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement {
} }
}).then(token => { }).then(token => {
console.log("Authorized") console.log("Authorized. Token exp: " + this.expirationDate(this.parseJwt(token).exp))
console.log("Token exp: " + this.expirationDate(this.parseJwt(token).exp))
//console.log("Datetime: " + (new Date()))
//transform all queued requests to fetches //transform all queued requests to fetches
console.log("All pending requests to promises") console.log("All pending requests to promises")
let promises = this.#queue.map(r => { let promises = this.#queue.map(r => {
@ -123,7 +134,7 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement {
console.log("Resolving all fetches") console.log("Resolving all fetches")
return Promise.all(promises) 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) }, 300)
@ -153,7 +164,7 @@ window.customElements.define('d4s-boot-2', class extends HTMLElement {
// onGrant callback function. // onGrant callback function.
// If authorization was successful you'll receive an RPT // If authorization was successful you'll receive an RPT
// with the necessary permissions to access the resource server // with the necessary permissions to access the resource server
console.log(rpt) //console.log(rpt)
//console.log("rpt expires: " + expDt(parseJwt(rpt).exp)) //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(response => response.json())
.then(json => { .then(json => {
this.#config = json this.#config = json
console.log("Keycloak uma2 configuration loaded")
resolve(true) resolve(true)
}) })
.catch(err => reject("Failed to fetch uma2-configuration from server: " + err)) .catch(err => reject("Failed to fetch uma2-configuration from server: " + err))