Skip to content
Snippets Groups Projects
Unverified Commit d542bb16 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Integrate provider for auth in dbp-auth-demo

parent 45e8c03d
No related branches found
No related tags found
No related merge requests found
Pipeline #16441 passed
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
<body> <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> </body>
</html> </html>
...@@ -6,12 +6,14 @@ import {LoginButton} from './login-button.js'; ...@@ -6,12 +6,14 @@ import {LoginButton} from './login-button.js';
import * as commonUtils from '@dbp-toolkit/common/utils'; import * as commonUtils from '@dbp-toolkit/common/utils';
import {name as pkgName} from './../package.json'; import {name as pkgName} from './../package.json';
import DBPLitElement from "@dbp-toolkit/common/dbp-lit-element"; import DBPLitElement from "@dbp-toolkit/common/dbp-lit-element";
import {Provider} from '@dbp-toolkit/provider';
class AuthDemo extends ScopedElementsMixin(DBPLitElement) { class AuthDemo extends ScopedElementsMixin(DBPLitElement) {
constructor() { constructor() {
super(); super();
this.lang = 'de'; this.lang = 'de';
this.entryPointUrl = ''; this.entryPointUrl = '';
this.auth = {};
} }
static get scopedElements() { static get scopedElements() {
...@@ -26,6 +28,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -26,6 +28,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) {
...super.properties, ...super.properties,
lang: { type: String }, lang: { type: String },
entryPointUrl: { type: String, attribute: 'entry-point-url' }, entryPointUrl: { type: String, attribute: 'entry-point-url' },
auth: { type: Object },
}; };
} }
...@@ -40,7 +43,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -40,7 +43,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) {
} }
async _onUserInfoClick() { async _onUserInfoClick() {
if (!window.DBPAuthToken) { if (!this.auth.token) {
console.error("not logged in"); console.error("not logged in");
return; return;
} }
...@@ -51,7 +54,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -51,7 +54,7 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) {
userInfoURL, { userInfoURL, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Bearer ' + window.DBPAuthToken 'Authorization': 'Bearer ' + this.auth.token
} }
} }
); );
...@@ -59,12 +62,12 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -59,12 +62,12 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) {
} }
async _onShowToken() { async _onShowToken() {
if (!window.DBPAuthToken) { if (!this.auth.token) {
console.error("not logged in"); console.error("not logged in");
return; return;
} }
console.log(window.DBPAuthToken); console.log(this.auth.token);
} }
render() { render() {
...@@ -107,4 +110,5 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -107,4 +110,5 @@ class AuthDemo extends ScopedElementsMixin(DBPLitElement) {
} }
} }
commonUtils.defineCustomElement('dbp-provider', Provider);
commonUtils.defineCustomElement('dbp-auth-demo', AuthDemo); commonUtils.defineCustomElement('dbp-auth-demo', AuthDemo);
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