From aa448cea85057f8ffbdae9b506283700cfe0d45e Mon Sep 17 00:00:00 2001 From: Sergei Mikhailov Date: Fri, 7 Aug 2020 14:40:35 +0200 Subject: [PATCH 1/3] TBD-48 fix: initialize token pool store with configuration values upon first access in order to use a fresh set after a page has been reloaded --- src/core/tokenHandler.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/core/tokenHandler.js b/src/core/tokenHandler.js index 3115859..b2e1ca6 100644 --- a/src/core/tokenHandler.js +++ b/src/core/tokenHandler.js @@ -85,21 +85,25 @@ export default function tokenHandlerFactory(options) { // Some async checks before we go for the token: return tokenStore .expireOldTokens() - .then(() => tokenStore.getSize()) - .then(queueSize => { - if (queueSize > 0) { - // Token available, use it - return getFirstTokenValue(); - } else if (!validateTokensOpt) { + .then(() => { + if (!validateTokensOpt) { return this.getClientConfigTokens() .then(getFirstTokenValue); - }else if (!clientConfigFetched) { + } else if (!clientConfigFetched) { // Client Config allowed! (first and only time) return this.getClientConfigTokens() .then(getFirstTokenValue); } else { - // No more token options, refresh needed - return Promise.reject(new Error('No tokens available. Please refresh the page.')); + return tokenStore.getSize() + .then(queueSize => { + if (queueSize > 0) { + // Token available, use it + return getFirstTokenValue(); + } else { + // No more token options, refresh needed + return Promise.reject(new Error('No tokens available. Please refresh the page.')); + } + }); } }); }, From 2553913f93eb0ace0d10ace8a9877bde148386dd Mon Sep 17 00:00:00 2001 From: Sergei Mikhailov Date: Fri, 7 Aug 2020 14:54:09 +0200 Subject: [PATCH 2/3] TBD-48 chore(version): bump a fix one --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index fdf76d2..08c1b3a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-core-sdk", - "version": "1.6.1", + "version": "1.6.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3e62f3f..fbc78f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-core-sdk", - "version": "1.6.1", + "version": "1.6.2", "displayName": "TAO Core SDK", "description": "Core libraries of TAO", "homepage": "https://github.com/oat-sa/tao-core-sdk-fe#readme", From eafcdd3ee7ea81e935596564c354a79bdb97f440 Mon Sep 17 00:00:00 2001 From: Sergei Mikhailov Date: Fri, 7 Aug 2020 15:01:02 +0200 Subject: [PATCH 3/3] TBD-48 fix: decrease a priority of `!validateTokensOpt` condition when retrieving a CSRF token --- src/core/tokenHandler.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/tokenHandler.js b/src/core/tokenHandler.js index b2e1ca6..1d81750 100644 --- a/src/core/tokenHandler.js +++ b/src/core/tokenHandler.js @@ -86,10 +86,7 @@ export default function tokenHandlerFactory(options) { return tokenStore .expireOldTokens() .then(() => { - if (!validateTokensOpt) { - return this.getClientConfigTokens() - .then(getFirstTokenValue); - } else if (!clientConfigFetched) { + if (!clientConfigFetched) { // Client Config allowed! (first and only time) return this.getClientConfigTokens() .then(getFirstTokenValue); @@ -99,6 +96,9 @@ export default function tokenHandlerFactory(options) { if (queueSize > 0) { // Token available, use it return getFirstTokenValue(); + } else if (!validateTokensOpt) { + return this.getClientConfigTokens() + .then(getFirstTokenValue); } else { // No more token options, refresh needed return Promise.reject(new Error('No tokens available. Please refresh the page.'));