Commit bc61a363 authored by Clément's avatar Clément

use ID Token

parent 8bcf6213
Pipeline #4499 passed with stage
in 52 seconds
......@@ -10,6 +10,10 @@
sib-test {
display: block;
}
pre{
white-space: normal;
word-wrap: break-word;
}
</style>
</head>
<body>
......@@ -70,14 +74,14 @@
async update() {
let user = await this.getUser();
let accessToken = await this.getUserAccessToken();
let idToken = await this.getUserIdToken();
if (!user) {
result.innerHTML = `Vous n'êtes pas connecté !`;
return;
}
user = await store.get(user);
console.log(user);
result.innerHTML = `Bonjour ${user.username} !<br>access_token: ${accessToken}`;
result.innerHTML = `Bonjour ${user.username} !<br>ID Token: <pre>${idToken}</pre>`;
}
empty(){}
populate(){}
......
......@@ -55,7 +55,7 @@ class SIBAuth extends HTMLElement {
if (!id) return null;
return { '@id': id };
};
SIBBase.prototype.getUserAccessToken = () => this.getUserAccessToken();
SIBBase.prototype.getUserIdToken = () => this.getUserIdToken();
}
/** @function
......@@ -67,7 +67,7 @@ class SIBAuth extends HTMLElement {
SIBBase.prototype.login = null;
SIBBase.prototype.logout = null;
SIBBase.prototype.getUser = null;
SIBBase.prototype.getUserAccessToken = null;
SIBBase.prototype.getUserIdToken = null;
}
/** @function
......@@ -131,7 +131,7 @@ class SIBAuth extends HTMLElement {
/** @function
* @name dispatchUserInfo
* @param {User} userWebId - User
* Try to replace data-src by userWebId iri on [bind-userWebId] elements
* Try to replace data-src by userWebId iri on [bind-user] elements
*/
// eslint-disable-next-line class-methods-use-this
async dispatchUserInfo() {
......@@ -146,7 +146,7 @@ class SIBAuth extends HTMLElement {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', processDOM);
} else {
await processDOM();
processDOM();
}
}
......@@ -169,18 +169,18 @@ class SIBAuth extends HTMLElement {
/** @function
* @name getUserAccessToken
* Return AccessToken or undefined
* @name getUserIdToken
* Return IdToken or undefined
* @return {User}
*/
// eslint-disable-next-line class-methods-use-this
getUserAccessToken() {
getUserIdToken() {
return new Promise((resolve) => {
auth.trackSession((session) => {
if (!session) {
return resolve(null);
}
return resolve(session.authorization && session.authorization.access_token);
return resolve(session.authorization && session.authorization.id_token);
});
});
}
......
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