From ff0d9ffb95530878ea1b77831118d4f449cfe498 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio@bekerle.com> Date: Wed, 3 Feb 2021 08:30:16 +0100 Subject: [PATCH] Remove all window variable setting and add documentation for "auth" set-property event --- packages/auth/README.md | 11 +++++++++++ packages/auth/src/auth-keycloak.js | 25 ++++++------------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/auth/README.md b/packages/auth/README.md index 41364011..9ac827e5 100644 --- a/packages/auth/README.md +++ b/packages/auth/README.md @@ -36,6 +36,17 @@ npm i @dbp-toolkit/auth - `silent-check-sso-redirect-uri` (optional): URI or path to a separate page for checking the login session in an iframe, see https://www.keycloak.org/docs/latest/securing_apps/#_javascript_adapter - `scope` (optional): Space separated list of scopes to request. These scopes get added in addition to the default ones, assuming the scope is in the optional scopes list of the Keycloak client in use. +### Emitted attribute + +The component emits a `set-property` event for the attribute `auth`: + +- `auth.subject`: Keycloak username +- `auth.token`: Keycloak token to send with your requests +- `auth.user-full-name`: Full name of the user +- `auth.person-id`: Person identifier of the user +- `auth.person`: Person json object of the user (optional, enable by setting the `load-person` attribute) + + ## Login Button ### Usage diff --git a/packages/auth/src/auth-keycloak.js b/packages/auth/src/auth-keycloak.js index d7d2c738..cb8cedf9 100644 --- a/packages/auth/src/auth-keycloak.js +++ b/packages/auth/src/auth-keycloak.js @@ -10,12 +10,12 @@ 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 * - * Sets some global variables: - * window.DBPAuthSubject: Keycloak username - * window.DBPAuthToken: Keycloak token to send with your requests - * window.DBPUserFullName: Full name of the user - * window.DBPPersonId: Person identifier of the user - * window.DBPPerson: Person json object of the user (optional, enable by setting the `load-person` attribute) + * Emits a set-property event for the attribute "auth": + * auth.subject: Keycloak username + * auth.token: Keycloak token to send with your requests + * auth.user-full-name: Full name of the user + * auth.person-id: Person identifier of the user + * auth.person: Person json object of the user (optional, enable by setting the `load-person` attribute) */ export class AuthKeycloak extends AdapterLitElement { constructor() { @@ -70,12 +70,6 @@ export class AuthKeycloak extends AdapterLitElement { } this.personId = personId; - window.DBPAuthSubject = this.subject; - window.DBPAuthToken = this.token; - window.DBPUserFullName = this.name; - window.DBPPersonId = this.personId; - window.DBPPerson = this.person; - this.sendSetPropertyEvents(); this._setLoginStatus(LoginStatus.LOGGED_IN, tokenChanged || newPerson); } else { @@ -88,12 +82,6 @@ export class AuthKeycloak extends AdapterLitElement { this.personId = ""; this.person = null; - window.DBPAuthSubject = this.subject; - window.DBPAuthToken = this.token; - window.DBPUserFullName = this.name; - window.DBPPersonId = this.personId; - window.DBPPerson = this.person; - this.sendSetPropertyEvents(); this._setLoginStatus(LoginStatus.LOGGED_OUT); } @@ -116,7 +104,6 @@ export class AuthKeycloak extends AdapterLitElement { .then(response => response.json()) .then((person) => { that.person = person; - window.DBPPerson = person; this.sendSetPropertyEvents(); this._setLoginStatus(this._loginStatus, true); }); -- GitLab