From 8a00e9c0cd24ef4f6fd2dabbdb1bfe2863bf69fa Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 8 Feb 2017 14:28:56 -0500 Subject: [PATCH] assign token AFTER refresh :) --- oauth3.core.js | 2 +- oauth3.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/oauth3.core.js b/oauth3.core.js index 9a1b947..1e8c276 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -200,7 +200,7 @@ , getFreshness: function (meta, staletime, now) { staletime = staletime || (15 * 60); now = now || Date.now(); - var fresh = ((parseInt(meta.exp, 10) || 0) - (now / 1000)); + var fresh = ((parseInt(meta.exp, 10) || 0) - Math.round(now / 1000)); if (fresh >= staletime) { return 'fresh'; diff --git a/oauth3.js b/oauth3.js index b0e19e3..b5e42e9 100644 --- a/oauth3.js +++ b/oauth3.js @@ -141,6 +141,9 @@ function lintAndRequest(preq) { function goGetHer() { + preq.headers = preq.headers || {}; + preq.headers.Authorization = 'Bearer ' + (preq.session.access_token || preq.session.accessToken); + if (!oauth3._lintRequest) { return rawRequest(preq); } @@ -153,12 +156,8 @@ return goGetHer(); } - preq.headers = preq.headers || {}; - preq.headers.Authorization = 'Bearer ' + (preq.session.access_token || preq.session.accessToken); - console.warn('lintAndRequest checkSession', preq); return oauth3.hooks.checkSession(preq, opts).then(goGetHer); - } if (opts.rawCase) {