Skip to content
Snippets Groups Projects
Commit 01d06876 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Get rid of the dbp-auth-init event

Replace with the event bus for now
parent 1e86c465
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,6 @@ npm i @dbp-toolkit/auth
### Events to listen to
- `dbp-auth-init`: Keycloak init event - happens once
- `dbp-auth-person-init`: Keycloak person init event - the person entity was loaded from the server
- `dbp-auth-keycloak-data-update`: Keycloak data was updated - happens for example every time after a token refresh
......
......@@ -10,7 +10,7 @@ import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element";
* Keycloak auth web component
* https://www.keycloak.org/docs/latest/securing_apps/index.html#_javascript_adapter
*
* Dispatches an event `dbp-auth-init` and sets some global variables:
* Sets some global variables:
* window.DBPAuthSubject: Keycloak username
* window.DBPAuthToken: Keycloak token to send with your requests
* window.DBPAuthTokenParsed: Keycloak token content
......@@ -44,7 +44,6 @@ export class AuthKeycloak extends AdapterLitElement {
this.idpHint = '';
// Create the events
this.initEvent = new CustomEvent("dbp-auth-init", { "detail": "KeyCloak init event", bubbles: true, composed: true });
this.personInitEvent = new CustomEvent("dbp-auth-person-init", { "detail": "KeyCloak person init event", bubbles: true, composed: true });
this.keycloakDataUpdateEvent = new CustomEvent("dbp-auth-keycloak-data-update", { "detail": "KeyCloak data was updated", bubbles: true, composed: true });
......@@ -112,10 +111,6 @@ export class AuthKeycloak extends AdapterLitElement {
const that = this;
if (newPerson) {
this.dispatchEvent(this.initEvent);
}
if (newPerson && this.loadPerson) {
JSONLD.initialize(this.entryPointUrl, (jsonld) => {
// find the correct api url for the current person
......
......@@ -3,6 +3,7 @@
import {send as notify} from './notification';
import * as utils from "./utils";
import {i18n} from "./i18n";
import {EventBus} from './';
let instances = {};
let successFunctions = {};
......@@ -51,18 +52,19 @@ export default class JSONLD {
initStarted[apiUrl] = true;
if (window.DBPAuthToken !== undefined) {
JSONLD.doInitialization(apiUrl);
} else {
// window.DBPAuthToken will be set by dbp-auth-init event
window.addEventListener("dbp-auth-init", () => JSONLD.doInitialization(apiUrl));
}
this._bus = new EventBus();
this._bus.subscribe('auth-update', (data) => {
if (data.token) {
this._bus.close();
JSONLD.doInitialization(apiUrl, data.token);
}
});
}
static doInitialization(apiUrl) {
static doInitialization(apiUrl, token) {
const xhr = new XMLHttpRequest();
xhr.open("GET", apiUrl, true);
xhr.setRequestHeader('Authorization', 'Bearer ' + window.DBPAuthToken);
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) {
......
......@@ -49,21 +49,6 @@ export class KnowledgeBaseWebPageElementView extends ScopedElementsMixin(LitElem
};
}
/*
connectedCallback() {
super.connectedCallback();
const that = this;
// JSONLD.initialize(this.entryPointUrl, function (jsonld) {
// const apiUrl = jsonld.getApiUrlForEntityName("KnowledgeBaseWebPageElement") + '/' +
// encodeURIComponent(commonUtils.base64EncodeUnicode(encodeURIComponent(that.value)));
// });
// disabled, load first on toggle to visible
window.addEventListener("dbp-auth-init", () => that.loadWebPageElement());
}
*/
/**
* Loads the data from the web page element
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment