From 1233d59d6162a057ed009487ebd843c50e55eafa Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio@bekerle.com>
Date: Mon, 1 Feb 2021 12:50:54 +0100
Subject: [PATCH] Add and use auth object property

---
 packages/auth/src/auth-keycloak.js          | 19 ++++++++++++++-----
 packages/person-select/src/person-select.js |  4 +++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/packages/auth/src/auth-keycloak.js b/packages/auth/src/auth-keycloak.js
index b59dd2cf..d7d2c738 100644
--- a/packages/auth/src/auth-keycloak.js
+++ b/packages/auth/src/auth-keycloak.js
@@ -117,6 +117,7 @@ export class AuthKeycloak extends AdapterLitElement {
                 .then((person) => {
                     that.person = person;
                     window.DBPPerson = person;
+                    this.sendSetPropertyEvents();
                     this._setLoginStatus(this._loginStatus, true);
                 });
             }, {}, that.lang);
@@ -124,11 +125,19 @@ export class AuthKeycloak extends AdapterLitElement {
     }
 
     sendSetPropertyEvents() {
-        this.sendSetPropertyEvent('auth-subject', this.subject);
-        this.sendSetPropertyEvent('auth-token', this.token);
-        this.sendSetPropertyEvent('user-full-name', this.name);
-        this.sendSetPropertyEvent('person-id', this.personId);
-        this.sendSetPropertyEvent('person', this.person);
+        this.sendSetPropertyEvent('auth', {
+            'subject': this.subject,
+            'token': this.token,
+            'user-full-name': this.name,
+            'person-id': this.personId,
+            'person': this.person,
+        });
+
+        // this.sendSetPropertyEvent('auth-subject', this.subject);
+        // this.sendSetPropertyEvent('auth-token', this.token);
+        // this.sendSetPropertyEvent('user-full-name', this.name);
+        // this.sendSetPropertyEvent('person-id', this.personId);
+        // this.sendSetPropertyEvent('person', this.person);
     }
 
     _setLoginStatus(status, force) {
diff --git a/packages/person-select/src/person-select.js b/packages/person-select/src/person-select.js
index b662067a..8811f957 100644
--- a/packages/person-select/src/person-select.js
+++ b/packages/person-select/src/person-select.js
@@ -27,6 +27,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
 
     constructor() {
         super();
+        this.auth = {};
         this.lang = 'de';
         this.entryPointUrl = '';
         this.jsonld = null;
@@ -65,6 +66,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
             showReloadButton: { type: Boolean, attribute: 'show-reload-button' },
             reloadButtonTitle: { type: String, attribute: 'reload-button-title' },
             showBirthDate: { type: Boolean, attribute: 'show-birth-date' },
+            auth: { type: Object },
         };
     }
 
@@ -221,7 +223,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
             fetch(apiUrl, {
                 headers: {
                     'Content-Type': 'application/ld+json',
-                    'Authorization': 'Bearer ' + window.DBPAuthToken,
+                    'Authorization': 'Bearer ' + this.auth.token || window.DBPAuthToken,
                 },
             })
             .then(result => {
-- 
GitLab