diff --git a/boot/d4s-boot.js b/boot/d4s-boot.js index fa5f43f..602fafe 100644 --- a/boot/d4s-boot.js +++ b/boot/d4s-boot.js @@ -1,4 +1,12 @@ - +/** + * D4Science boot component that handles keykloak authz + * { + const audience = encodeURIComponent(this.#audience) + this.#authorization.entitlement(audience).then(function (rpt) { + fetch(endpoint, { + method: 'GET', + headers: { + 'Authorization': 'Bearer ' + rpt + } + }) + .then(response => response.blob()) + .then(blob => { + const objectURL = URL.createObjectURL(blob) + var tmplnk = document.createElement("a") + tmplnk.download = name + tmplnk.href = objectURL + document.body.appendChild(tmplnk) + tmplnk.click() + document.body.removeChild(tmplnk) + }) + }) + }).catch(function() { + onForbidden('Failed to refresh token') + }) + } + logout() { if (this.#keycloak) { if (!this.#redirectUrl) { diff --git a/social/d4s-social.js b/social/d4s-social.js index b28f093..fdc353a 100644 --- a/social/d4s-social.js +++ b/social/d4s-social.js @@ -1,42 +1,6 @@ - -window.customElements.define('d4s-social-search', class extends HTMLElement { - - constructor() { - super() - } - - connectedCallback() { - //console.log(typeof d4s) - //console.log(this) - //this.attachShadow({mode: "open"}) - //console.log(this.shadowRoot.querySelector("*[name=search]")) - //const shadowRoot = this.attachShadow({mode: 'open'}) - //console.log(shadowRoot.innerHTML) - console.log("d4s-social-search connectedCallback") - var d4s = document.querySelector('d4s-boot-2') - - /* - d4s.service( - 'https://api.dev.d4science.org/rest/2/full-text-search/search-by-query?query=d4science', - 'GET', null, - (resp) => { - document.getElementById('output').innerText = resp - }, - () => { alert('Forbidden') } - ) - - d4s.service( - 'https://api.dev.d4science.org/rest/2/posts/get-posts-user-quantity', - 'GET', null, - (resp) => { - document.getElementById('output').innerText = resp - }, - () => { alert('Forbidden') } - ) - */ - } -}) - +/** + * Prints VRE d4s-social-posts (limiting to @quantity number) + */ window.customElements.define('d4s-social-posts', class extends HTMLElement { #basepath = 'https://api.d4science.org/rest' @@ -121,4 +85,43 @@ window.customElements.define('d4s-social-posts', class extends HTMLElement { this.#quantity = quantity this.setAttribute("quantity", quantity) } -}) \ No newline at end of file +}) + + +window.customElements.define('d4s-social-search', class extends HTMLElement { + + constructor() { + super() + } + + connectedCallback() { + //console.log(typeof d4s) + //console.log(this) + //this.attachShadow({mode: "open"}) + //console.log(this.shadowRoot.querySelector("*[name=search]")) + //const shadowRoot = this.attachShadow({mode: 'open'}) + //console.log(shadowRoot.innerHTML) + console.log("d4s-social-search connectedCallback") + var d4s = document.querySelector('d4s-boot-2') + + /* + d4s.service( + 'https://api.dev.d4science.org/rest/2/full-text-search/search-by-query?query=d4science', + 'GET', null, + (resp) => { + document.getElementById('output').innerText = resp + }, + () => { alert('Forbidden') } + ) + + d4s.service( + 'https://api.dev.d4science.org/rest/2/posts/get-posts-user-quantity', + 'GET', null, + (resp) => { + document.getElementById('output').innerText = resp + }, + () => { alert('Forbidden') } + ) + */ + } +})