diff --git a/packages/auth/assets/index.html b/packages/auth/assets/index.html index 746cdf0f3a3a4dded6b4bab54ffb8eebb70a47c7..8cd51cdcf907f86d34831ff41abd0683709a295d 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 f31c31b85c45e70f0695787900ba2980d4eca190..b03017fe71d57716a8e2a32f9e605fc04bfa06cc 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);