Commit 94064ed3 authored by Clément's avatar Clément

bugfix: expose solid_auth access_tocken

parent b679f44e
......@@ -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(){}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment