Skip to content

Commit

Permalink
fix integration
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongranick-okta committed Jan 11, 2022
1 parent 0f0d0d5 commit 40c819e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/OktaAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
FlowIdentifier,
GetWithRedirectAPI,
ParseFromUrlInterface,
GetWithRedirectFunction,
} from './types';
import {
transactionStatus,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 40c819e

Please sign in to comment.