From 40c819e3ebdf344504b932918075cd289789997e Mon Sep 17 00:00:00 2001 From: Aaron Granick Date: Tue, 11 Jan 2022 00:21:04 -0800 Subject: [PATCH] fix integration --- lib/OktaAuth.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/OktaAuth.ts b/lib/OktaAuth.ts index 7abcd5f08d..5bae4b6ab5 100644 --- a/lib/OktaAuth.ts +++ b/lib/OktaAuth.ts @@ -47,6 +47,7 @@ import { FlowIdentifier, GetWithRedirectAPI, ParseFromUrlInterface, + GetWithRedirectFunction, } from './types'; import { transactionStatus, @@ -217,13 +218,21 @@ class OktaAuth implements SDKInterface, SigninAPI, SignoutAPI { }; this._tokenQueue = new PromiseQueue(); - const getWithRedirectApi: GetWithRedirectAPI = Object.assign(getWithRedirect.bind(null, this), { + const useQueue = (method) => { + return PromiseQueue.prototype.push.bind(this._tokenQueue, method, null); + }; + + // eslint-disable-next-line max-len + const getWithRedirectFn = useQueue(getWithRedirect.bind(null, this)) as GetWithRedirectFunction; + const getWithRedirectApi: GetWithRedirectAPI = Object.assign(getWithRedirectFn, { // This is exposed so we can set window.location in our tests _setLocation: function(url) { window.location = url; } }); - const parseFromUrlApi: ParseFromUrlInterface = Object.assign(parseFromUrl.bind(null, this), { + // eslint-disable-next-line max-len + const parseFromUrlFn = useQueue(parseFromUrl.bind(null, this)) as ParseFromUrlInterface; + const parseFromUrlApi: ParseFromUrlInterface = Object.assign(parseFromUrlFn, { // This is exposed so we can mock getting window.history in our tests _getHistory: function() { return window.history; @@ -256,7 +265,14 @@ class OktaAuth implements SDKInterface, SigninAPI, SignoutAPI { isLoginRedirect: isLoginRedirect.bind(null, this) }; // Wrap all async token API methods using MethodQueue to avoid issues with concurrency - const syncMethods = ['decode', 'isLoginRedirect']; + const syncMethods = [ + // sync methods + 'decode', + 'isLoginRedirect', + // already bound + 'getWithRedirect', + 'parseFromUrl' + ]; Object.keys(this.token).forEach(key => { if (syncMethods.indexOf(key) >= 0) { // sync methods should not be wrapped return;