From 94064ed3120d49a6790f69dcf2b1021ef2f45929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= <cpartiot@gmail.com> Date: Sat, 22 Jun 2019 10:18:39 +0200 Subject: [PATCH] bugfix: expose solid_auth access_tocken --- index.html | 9 +++------ sib-auth.js | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index c7c6305..7c02a94 100644 --- a/index.html +++ b/index.html @@ -67,20 +67,17 @@ async triggerLogout() { await this.logout(); } - - async getStatus() { - return this.getUser(); - } - + async update() { let user = await this.getUser(); + let accessToken = await this.getUserAccessToken(); if (!user) { result.innerHTML = `Vous n'êtes pas connecté !`; return; } user = await store.get(user); console.log(user); - result.innerHTML = `Bonjour ${user.username} !`; + result.innerHTML = `Bonjour ${user.username} !<br>access_token: ${accessToken}`; } empty(){} populate(){} diff --git a/sib-auth.js b/sib-auth.js index ea5c30c..2bdf6c4 100644 --- a/sib-auth.js +++ b/sib-auth.js @@ -50,6 +50,7 @@ class SIBAuth extends HTMLElement { install() { SIBBase.prototype.login = () => this.login(); SIBBase.prototype.logout = () => this.logout(); + SIBBase.prototype.getUserAccessToken = () => this.getUserAccessToken(); SIBBase.prototype.getUser = async () => { const id = await this.getUserWebId(); if (!id) return null; @@ -88,6 +89,7 @@ class SIBAuth extends HTMLElement { SIBBase.prototype.login = null; SIBBase.prototype.logout = null; SIBBase.prototype.getUser = null; + SIBBase.prototype.getUserAccessToken = null; this.bindUserObserver.disconnect(); } @@ -197,6 +199,24 @@ class SIBAuth extends HTMLElement { }); } + + /** @function + * @name getUserAccessToken + * Return AccessToken or undefined + * @return {User} + */ + // eslint-disable-next-line class-methods-use-this + getUserAccessToken() { + return new Promise((resolve) => { + auth.trackSession((session) => { + if (!session) { + return resolve(null); + } + return resolve(session.authorization && session.authorization.access_token); + }); + }); + } + /** @function * @name login * Try to login, if favorite provider is set, trigger login, if not, select provider -- GitLab