From d542bb167dfd23aa19cfbc30cc3c3297a1aced1a Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio@bekerle.com> Date: Tue, 2 Feb 2021 14:27:34 +0100 Subject: [PATCH] Integrate provider for auth in dbp-auth-demo --- packages/auth/assets/index.html | 4 +++- packages/auth/src/dbp-auth-demo.js | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/auth/assets/index.html b/packages/auth/assets/index.html index 746cdf0f..8cd51cdc 100644 --- a/packages/auth/assets/index.html +++ b/packages/auth/assets/index.html @@ -7,7 +7,9 @@ <body> -<dbp-auth-demo lang="de" entry-point-url="http://127.0.0.1:8000"></dbp-auth-demo> +<dbp-provider auth> + <dbp-auth-demo lang="de" entry-point-url="http://127.0.0.1:8000" subscribe="auth:auth"></dbp-auth-demo> +</dbp-provider> </body> </html> diff --git a/packages/auth/src/dbp-auth-demo.js b/packages/auth/src/dbp-auth-demo.js index f31c31b8..b03017fe 100644 --- a/packages/auth/src/dbp-auth-demo.js +++ b/packages/auth/src/dbp-auth-demo.js @@ -6,12 +6,14 @@ import {LoginButton} from './login-button.js'; import * as commonUtils from '@dbp-toolkit/common/utils'; import {name as pkgName} from './../package.json'; import DBPLitElement from "@dbp-toolkit/common/dbp-lit-element"; +import {Provider} from '@dbp-toolkit/provider'; class AuthDemo extends ScopedElementsMixin(DBPLitElement) { constructor() { super(); this.lang = 'de'; this.entryPointUrl = ''; + this.auth = {}; } static get scopedElements() { @@ -26,6 +28,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { ...super.properties, lang: { type: String }, entryPointUrl: { type: String, attribute: 'entry-point-url' }, + auth: { type: Object }, }; } @@ -40,7 +43,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { } async _onUserInfoClick() { - if (!window.DBPAuthToken) { + if (!this.auth.token) { console.error("not logged in"); return; } @@ -51,7 +54,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { userInfoURL, { headers: { 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + window.DBPAuthToken + 'Authorization': 'Bearer ' + this.auth.token } } ); @@ -59,12 +62,12 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { } async _onShowToken() { - if (!window.DBPAuthToken) { + if (!this.auth.token) { console.error("not logged in"); return; } - console.log(window.DBPAuthToken); + console.log(this.auth.token); } render() { @@ -107,4 +110,5 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { } } +commonUtils.defineCustomElement('dbp-provider', Provider); commonUtils.defineCustomElement('dbp-auth-demo', AuthDemo); -- GitLab