@openpass/openpass-js-sdk
Advanced tools
Comparing version 2.1.4 to 2.1.5
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"repository": { | ||
@@ -39,3 +39,7 @@ "type": "git", | ||
"format-check": "prettier --check .", | ||
"pre-commit": "lint-staged" | ||
"pre-commit": "lint-staged", | ||
"e2e": "npx playwright test", | ||
"e2e:server": "ts-node ./tests/e2e/server/run-server.ts", | ||
"e2e:ui": "npx playwright test --ui", | ||
"e2e:codegen": "npx playwright codegen" | ||
}, | ||
@@ -54,2 +58,5 @@ "pre-commit": [ | ||
"devDependencies": { | ||
"@playwright/test": "^1.39.0", | ||
"@types/ejs": "^3.1.3", | ||
"@types/express": "^4.17.19", | ||
"@types/jest": "^27.4.1", | ||
@@ -60,3 +67,6 @@ "@types/promise.prototype.finally": "^2.0.4", | ||
"@typescript-eslint/parser": "^5.15.0", | ||
"cheerio": "^1.0.0-rc.12", | ||
"concurrently": "^7.2.2", | ||
"dotenv": "^16.3.1", | ||
"ejs": "^3.1.9", | ||
"eslint": "^8.11.0", | ||
@@ -69,2 +79,3 @@ "eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-tsdoc": "^0.2.14", | ||
"express": "^4.18.2", | ||
"jest": "^27.5.1", | ||
@@ -75,2 +86,3 @@ "jest-location-mock": "^1.0.9", | ||
"lint-staged": "^13.0.1", | ||
"mailslurp-client": "^15.17.2", | ||
"path-browserify": "^1.0.1", | ||
@@ -82,2 +94,3 @@ "pre-commit": "^1.2.2", | ||
"ts-loader": "^9.2.6", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.5.5", | ||
@@ -84,0 +97,0 @@ "url-parse": "^1.5.10", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ERROR_MESSAGE_POPUP_TIMEOUT = exports.ERROR_MESSAGE_POPUP_CLOSED = exports.ERROR_POPUP_REOPENED = exports.ERROR_POPUP_FAILED_TO_OPEN = exports.ERROR_INVALID_CLIENT_ID = exports.ERROR_INVALID_REDIRECT_URL = exports.ERROR_MESSAGE_INVALID_AUTH_CODE_RESPONSE = exports.ERROR_MESSAGE_TOKEN_REQUEST_FAILED = exports.ERROR_MESSAGE_NO_ACCESS_TOKEN = exports.ERROR_MESSAGE_DECODE_JWT = exports.ERROR_MESSAGE_INVALID_REDIRECT = exports.ERROR_MESSAGE_REDIRECT_URL_NOT_AVAILABLE = exports.ERROR_MESSAGE_INVALID_AUTH_SESSION = void 0; | ||
exports.ERROR_MESSAGE_POPUP_TIMEOUT = exports.ERROR_MESSAGE_POPUP_CLOSED = exports.ERROR_POPUP_CLOSED = exports.ERROR_INVALID_CLIENT_ID = exports.ERROR_INVALID_REDIRECT_URL = exports.ERROR_MESSAGE_INVALID_AUTH_CODE_RESPONSE = exports.ERROR_MESSAGE_TOKEN_REQUEST_FAILED = exports.ERROR_MESSAGE_NO_ACCESS_TOKEN = exports.ERROR_MESSAGE_DECODE_JWT = exports.ERROR_MESSAGE_INVALID_REDIRECT = exports.ERROR_MESSAGE_REDIRECT_URL_NOT_AVAILABLE = exports.ERROR_MESSAGE_INVALID_AUTH_SESSION = void 0; | ||
exports.ERROR_MESSAGE_INVALID_AUTH_SESSION = "Unable to authenticate, a login session may not have being started. Possibly a call to login is required"; | ||
@@ -13,6 +13,5 @@ exports.ERROR_MESSAGE_REDIRECT_URL_NOT_AVAILABLE = "Unable to complete login, a valid redirect url was not available"; | ||
exports.ERROR_INVALID_CLIENT_ID = "Error clientId is invalid. Please use a valid clientId"; | ||
exports.ERROR_POPUP_FAILED_TO_OPEN = "Popup window failed to open"; | ||
exports.ERROR_POPUP_REOPENED = "Popup window was reopened"; | ||
exports.ERROR_POPUP_CLOSED = "Popup window was closed"; | ||
exports.ERROR_MESSAGE_POPUP_CLOSED = "Popup closed, authentication response not available"; | ||
exports.ERROR_MESSAGE_POPUP_TIMEOUT = "No Response received from popup"; | ||
//# sourceMappingURL=messages.js.map |
@@ -39,9 +39,13 @@ "use strict"; | ||
constructor(OpenPassOptions, redirectApi, openPassClient) { | ||
this.OpenPassOptions = OpenPassOptions; | ||
this.popupWindows = new Map(); | ||
this.openPassOptions = OpenPassOptions; | ||
this.openPassClient = openPassClient; | ||
this.redirectApi = redirectApi; | ||
this.promises = []; | ||
} | ||
signInWithPopup(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// If an existing popup flow is in progress, close that and start a new one | ||
if (this.popupWindows.size > 0) { | ||
this.closeAllPoups(); | ||
} | ||
if (!options.redirectUrl) { | ||
@@ -53,6 +57,7 @@ // if redirectUrl hasn't been supplied, then use the current url | ||
} | ||
let popupWindow; | ||
const flowId = new Date().getTime().toString(); | ||
let popup; | ||
try { | ||
popupWindow = this.openPopup(); | ||
if (!popupWindow) { | ||
popup = this.openPopup(); | ||
if (!popup) { | ||
//fallback to full redirect | ||
@@ -63,6 +68,5 @@ yield this.redirectApi.signIn(options); | ||
} | ||
popupWindow.focus(); | ||
popup.focus(); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
catch (_a) { | ||
//fallback to full redirect | ||
@@ -73,9 +77,14 @@ yield this.redirectApi.signIn(options); | ||
} | ||
return this.doLogin(popupWindow, options); | ||
const authWindow = { | ||
flowId, | ||
window: popup, | ||
}; | ||
this.popupWindows.set(flowId, authWindow); | ||
return this.doLogin(authWindow, options); | ||
}); | ||
} | ||
doLogin(popupWindow, options) { | ||
doLogin(authWindow, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const popupCloseHandler = (e) => { | ||
this.closePopup(window); | ||
this.closePopup(authWindow.flowId); | ||
}; | ||
@@ -87,3 +96,3 @@ window.addEventListener("beforeunload", popupCloseHandler); | ||
clientState: options && options.clientState ? options.clientState : undefined, | ||
clientId: this.OpenPassOptions.clientId, | ||
clientId: this.openPassOptions.clientId, | ||
redirectUrl: options && options.redirectUrl ? options.redirectUrl : "", | ||
@@ -96,9 +105,9 @@ codeVerifier: verifier, | ||
}; | ||
const loginUri = (0, url_1.buildAuthorizeUrl)((0, config_1.getOpenPassApiBaseUrl)(this.OpenPassOptions.baseUrl), config_1.config.SSO_AUTHORIZE_PATH, authSession); | ||
popupWindow.location.replace(loginUri); | ||
return yield this.waitForPopupResponse(popupWindow, authSession); | ||
const loginUri = (0, url_1.buildAuthorizeUrl)((0, config_1.getOpenPassApiBaseUrl)(this.openPassOptions.baseUrl), config_1.config.SSO_AUTHORIZE_PATH, authSession); | ||
authWindow.window.location.replace(loginUri); | ||
return yield this.waitForPopupResponse(authWindow, authSession); | ||
} | ||
catch (e) { | ||
if (!(e instanceof errors_1.AuthCancelledError)) { | ||
this.closePopup(popupWindow); | ||
this.closePopup(authWindow.flowId); | ||
} | ||
@@ -112,5 +121,5 @@ throw e; | ||
} | ||
waitForPopupResponse(popupWindow, authSession) { | ||
waitForPopupResponse(authWindow, authSession) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const authCodeResponse = yield this.listenForPopupResponse(popupWindow); | ||
const authCodeResponse = yield this.listenForPopupResponse(authWindow); | ||
if (!this.isAuthCodeValid(authCodeResponse, authSession) || !authCodeResponse.code) { | ||
@@ -120,6 +129,6 @@ throw new errors_1.AuthError(authCodeResponse.error ? authCodeResponse.error : codes_1.ERROR_CODE_INVALID_AUTH_CODE, authCodeResponse.errorDescription ? authCodeResponse.errorDescription : messages_1.ERROR_MESSAGE_INVALID_AUTH_CODE_RESPONSE, authCodeResponse.errorUri ? authCodeResponse.errorUri : "", authSession.clientState); | ||
const openPassTokens = yield this.openPassClient.exchangeAuthCodeForTokens(authCodeResponse.code, authSession); | ||
return yield this.completeAuthentication(openPassTokens, authSession, popupWindow); | ||
return yield this.completeAuthentication(authWindow.flowId, openPassTokens, authSession); | ||
}); | ||
} | ||
completeAuthentication(tokens, authSession, popupWindow) { | ||
completeAuthentication(flowId, tokens, authSession) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -134,3 +143,3 @@ const { idToken, rawIdToken, rawAccessToken } = tokens; | ||
try { | ||
this.closePopup(popupWindow); | ||
this.closePopup(flowId); | ||
resolve({ | ||
@@ -144,3 +153,3 @@ clientState: authSession.clientState, | ||
catch (e) { | ||
this.closePopup(popupWindow); | ||
this.closePopup(flowId); | ||
reject(e); | ||
@@ -152,3 +161,3 @@ } | ||
} | ||
listenForPopupResponse(popupWindow) { | ||
listenForPopupResponse(authWindow) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -160,6 +169,6 @@ let closeTimeout; | ||
closeTimeout = setInterval(() => { | ||
if (popupWindow && popupWindow.closed) { | ||
if (authWindow.window && authWindow.window.closed) { | ||
clearInterval(closeTimeout); | ||
window.removeEventListener("message", messageHandler); | ||
this.closePopup(popupWindow); | ||
this.closePopup(authWindow.flowId); | ||
reject(new errors_1.SdkError(messages_1.ERROR_MESSAGE_POPUP_CLOSED)); | ||
@@ -170,3 +179,3 @@ } | ||
//Check that the message is from the authorization server | ||
if (!this.matchEventOrigin(event.origin, (0, config_1.getOpenPassApiBaseUrl)(this.OpenPassOptions.baseUrl)) || !event.data) { | ||
if (!this.matchEventOrigin(event.origin, (0, config_1.getOpenPassApiBaseUrl)(this.openPassOptions.baseUrl)) || !event.data) { | ||
return; | ||
@@ -189,6 +198,6 @@ } | ||
window.removeEventListener("message", messageHandler); | ||
reject(new errors_1.AuthCancelledError(messages_1.ERROR_POPUP_REOPENED)); | ||
reject(new errors_1.AuthCancelledError(messages_1.ERROR_POPUP_CLOSED)); | ||
}); | ||
}); | ||
this.promises.push(popupPromise); | ||
authWindow.listener = popupPromise; | ||
return popupPromise.finally(() => { | ||
@@ -219,9 +228,29 @@ clearInterval(closeTimeout); | ||
} | ||
closePopup(window) { | ||
this.promises = []; | ||
if (!window || window.closed) { | ||
return; | ||
closeAllPoups() { | ||
for (const key of this.popupWindows.keys()) { | ||
this.closePopup(key); | ||
} | ||
window.close(); | ||
} | ||
closePopup(flowId) { | ||
const popupWindowToClose = this.popupWindows.get(flowId); | ||
if (popupWindowToClose) { | ||
if (popupWindowToClose.window && !popupWindowToClose.window.closed) { | ||
try { | ||
popupWindowToClose.window.close(); | ||
} | ||
catch (_a) { | ||
// Ignore errors | ||
} | ||
} | ||
if (popupWindowToClose.listener) { | ||
try { | ||
popupWindowToClose.listener.abort(); | ||
} | ||
catch (_b) { | ||
// Ignore errors | ||
} | ||
} | ||
} | ||
this.popupWindows.delete(flowId); | ||
} | ||
matchEventOrigin(eventOrigin, origin) { | ||
@@ -236,8 +265,4 @@ if (eventOrigin === origin) { | ||
} | ||
cleanUpIfNecessary() { | ||
this.promises.forEach((p) => p.abort()); | ||
this.promises = []; | ||
} | ||
} | ||
exports.default = PopupAuth; | ||
//# sourceMappingURL=popup.js.map |
@@ -34,3 +34,3 @@ "use strict"; | ||
API_DEFAULT_TIMEOUT_MS: 60 * 1000, | ||
POPUP_RESPONSE_TIMEOUT_MS: 30 * 1000, //the timeout to receive a response from the popup | ||
POPUP_RESPONSE_TIMEOUT_MS: 10 * 60 * 1000, //the timeout to receive a response from the popup | ||
}; | ||
@@ -37,0 +37,0 @@ const getOpenPassApiBaseUrl = (baseUrl) => { |
@@ -14,3 +14,5 @@ "use strict"; | ||
Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return errors_1.AuthError; } }); | ||
const signInButton_1 = require("./buttons/signInButton"); | ||
(0, promise_prototype_finally_1.shim)(); | ||
document.addEventListener("DOMContentLoaded", signInButton_1.renderSignInButton, { once: true }); | ||
//# sourceMappingURL=main.js.map |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"repository": { | ||
@@ -39,3 +39,7 @@ "type": "git", | ||
"format-check": "prettier --check .", | ||
"pre-commit": "lint-staged" | ||
"pre-commit": "lint-staged", | ||
"e2e": "npx playwright test", | ||
"e2e:server": "ts-node ./tests/e2e/server/run-server.ts", | ||
"e2e:ui": "npx playwright test --ui", | ||
"e2e:codegen": "npx playwright codegen" | ||
}, | ||
@@ -54,2 +58,5 @@ "pre-commit": [ | ||
"devDependencies": { | ||
"@playwright/test": "^1.39.0", | ||
"@types/ejs": "^3.1.3", | ||
"@types/express": "^4.17.19", | ||
"@types/jest": "^27.4.1", | ||
@@ -60,3 +67,6 @@ "@types/promise.prototype.finally": "^2.0.4", | ||
"@typescript-eslint/parser": "^5.15.0", | ||
"cheerio": "^1.0.0-rc.12", | ||
"concurrently": "^7.2.2", | ||
"dotenv": "^16.3.1", | ||
"ejs": "^3.1.9", | ||
"eslint": "^8.11.0", | ||
@@ -69,2 +79,3 @@ "eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-tsdoc": "^0.2.14", | ||
"express": "^4.18.2", | ||
"jest": "^27.5.1", | ||
@@ -75,2 +86,3 @@ "jest-location-mock": "^1.0.9", | ||
"lint-staged": "^13.0.1", | ||
"mailslurp-client": "^15.17.2", | ||
"path-browserify": "^1.0.1", | ||
@@ -82,2 +94,3 @@ "pre-commit": "^1.2.2", | ||
"ts-loader": "^9.2.6", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.5.5", | ||
@@ -84,0 +97,0 @@ "url-parse": "^1.5.10", |
@@ -10,6 +10,5 @@ export const ERROR_MESSAGE_INVALID_AUTH_SESSION = "Unable to authenticate, a login session may not have being started. Possibly a call to login is required"; | ||
export const ERROR_INVALID_CLIENT_ID = "Error clientId is invalid. Please use a valid clientId"; | ||
export const ERROR_POPUP_FAILED_TO_OPEN = "Popup window failed to open"; | ||
export const ERROR_POPUP_REOPENED = "Popup window was reopened"; | ||
export const ERROR_POPUP_CLOSED = "Popup window was closed"; | ||
export const ERROR_MESSAGE_POPUP_CLOSED = "Popup closed, authentication response not available"; | ||
export const ERROR_MESSAGE_POPUP_TIMEOUT = "No Response received from popup"; | ||
//# sourceMappingURL=messages.js.map |
@@ -19,3 +19,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { AuthCancelledError, AuthError, SdkError } from "./error/errors"; | ||
import { ERROR_MESSAGE_INVALID_AUTH_CODE_RESPONSE, ERROR_MESSAGE_POPUP_CLOSED, ERROR_MESSAGE_POPUP_TIMEOUT, ERROR_POPUP_REOPENED, } from "./error/messages"; | ||
import { ERROR_MESSAGE_INVALID_AUTH_CODE_RESPONSE, ERROR_MESSAGE_POPUP_CLOSED, ERROR_MESSAGE_POPUP_TIMEOUT, ERROR_POPUP_CLOSED, } from "./error/messages"; | ||
import AbortablePromise from "./utils/abortablePromise"; | ||
@@ -35,9 +35,13 @@ const POPUP_HEIGHT = 586; | ||
constructor(OpenPassOptions, redirectApi, openPassClient) { | ||
this.OpenPassOptions = OpenPassOptions; | ||
this.popupWindows = new Map(); | ||
this.openPassOptions = OpenPassOptions; | ||
this.openPassClient = openPassClient; | ||
this.redirectApi = redirectApi; | ||
this.promises = []; | ||
} | ||
signInWithPopup(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// If an existing popup flow is in progress, close that and start a new one | ||
if (this.popupWindows.size > 0) { | ||
this.closeAllPoups(); | ||
} | ||
if (!options.redirectUrl) { | ||
@@ -49,6 +53,7 @@ // if redirectUrl hasn't been supplied, then use the current url | ||
} | ||
let popupWindow; | ||
const flowId = new Date().getTime().toString(); | ||
let popup; | ||
try { | ||
popupWindow = this.openPopup(); | ||
if (!popupWindow) { | ||
popup = this.openPopup(); | ||
if (!popup) { | ||
//fallback to full redirect | ||
@@ -59,6 +64,5 @@ yield this.redirectApi.signIn(options); | ||
} | ||
popupWindow.focus(); | ||
popup.focus(); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
catch (_a) { | ||
//fallback to full redirect | ||
@@ -69,9 +73,14 @@ yield this.redirectApi.signIn(options); | ||
} | ||
return this.doLogin(popupWindow, options); | ||
const authWindow = { | ||
flowId, | ||
window: popup, | ||
}; | ||
this.popupWindows.set(flowId, authWindow); | ||
return this.doLogin(authWindow, options); | ||
}); | ||
} | ||
doLogin(popupWindow, options) { | ||
doLogin(authWindow, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const popupCloseHandler = (e) => { | ||
this.closePopup(window); | ||
this.closePopup(authWindow.flowId); | ||
}; | ||
@@ -83,3 +92,3 @@ window.addEventListener("beforeunload", popupCloseHandler); | ||
clientState: options && options.clientState ? options.clientState : undefined, | ||
clientId: this.OpenPassOptions.clientId, | ||
clientId: this.openPassOptions.clientId, | ||
redirectUrl: options && options.redirectUrl ? options.redirectUrl : "", | ||
@@ -92,9 +101,9 @@ codeVerifier: verifier, | ||
}; | ||
const loginUri = buildAuthorizeUrl(getOpenPassApiBaseUrl(this.OpenPassOptions.baseUrl), config.SSO_AUTHORIZE_PATH, authSession); | ||
popupWindow.location.replace(loginUri); | ||
return yield this.waitForPopupResponse(popupWindow, authSession); | ||
const loginUri = buildAuthorizeUrl(getOpenPassApiBaseUrl(this.openPassOptions.baseUrl), config.SSO_AUTHORIZE_PATH, authSession); | ||
authWindow.window.location.replace(loginUri); | ||
return yield this.waitForPopupResponse(authWindow, authSession); | ||
} | ||
catch (e) { | ||
if (!(e instanceof AuthCancelledError)) { | ||
this.closePopup(popupWindow); | ||
this.closePopup(authWindow.flowId); | ||
} | ||
@@ -108,5 +117,5 @@ throw e; | ||
} | ||
waitForPopupResponse(popupWindow, authSession) { | ||
waitForPopupResponse(authWindow, authSession) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const authCodeResponse = yield this.listenForPopupResponse(popupWindow); | ||
const authCodeResponse = yield this.listenForPopupResponse(authWindow); | ||
if (!this.isAuthCodeValid(authCodeResponse, authSession) || !authCodeResponse.code) { | ||
@@ -116,6 +125,6 @@ throw new AuthError(authCodeResponse.error ? authCodeResponse.error : ERROR_CODE_INVALID_AUTH_CODE, authCodeResponse.errorDescription ? authCodeResponse.errorDescription : ERROR_MESSAGE_INVALID_AUTH_CODE_RESPONSE, authCodeResponse.errorUri ? authCodeResponse.errorUri : "", authSession.clientState); | ||
const openPassTokens = yield this.openPassClient.exchangeAuthCodeForTokens(authCodeResponse.code, authSession); | ||
return yield this.completeAuthentication(openPassTokens, authSession, popupWindow); | ||
return yield this.completeAuthentication(authWindow.flowId, openPassTokens, authSession); | ||
}); | ||
} | ||
completeAuthentication(tokens, authSession, popupWindow) { | ||
completeAuthentication(flowId, tokens, authSession) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -130,3 +139,3 @@ const { idToken, rawIdToken, rawAccessToken } = tokens; | ||
try { | ||
this.closePopup(popupWindow); | ||
this.closePopup(flowId); | ||
resolve({ | ||
@@ -140,3 +149,3 @@ clientState: authSession.clientState, | ||
catch (e) { | ||
this.closePopup(popupWindow); | ||
this.closePopup(flowId); | ||
reject(e); | ||
@@ -148,3 +157,3 @@ } | ||
} | ||
listenForPopupResponse(popupWindow) { | ||
listenForPopupResponse(authWindow) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -156,6 +165,6 @@ let closeTimeout; | ||
closeTimeout = setInterval(() => { | ||
if (popupWindow && popupWindow.closed) { | ||
if (authWindow.window && authWindow.window.closed) { | ||
clearInterval(closeTimeout); | ||
window.removeEventListener("message", messageHandler); | ||
this.closePopup(popupWindow); | ||
this.closePopup(authWindow.flowId); | ||
reject(new SdkError(ERROR_MESSAGE_POPUP_CLOSED)); | ||
@@ -166,3 +175,3 @@ } | ||
//Check that the message is from the authorization server | ||
if (!this.matchEventOrigin(event.origin, getOpenPassApiBaseUrl(this.OpenPassOptions.baseUrl)) || !event.data) { | ||
if (!this.matchEventOrigin(event.origin, getOpenPassApiBaseUrl(this.openPassOptions.baseUrl)) || !event.data) { | ||
return; | ||
@@ -185,6 +194,6 @@ } | ||
window.removeEventListener("message", messageHandler); | ||
reject(new AuthCancelledError(ERROR_POPUP_REOPENED)); | ||
reject(new AuthCancelledError(ERROR_POPUP_CLOSED)); | ||
}); | ||
}); | ||
this.promises.push(popupPromise); | ||
authWindow.listener = popupPromise; | ||
return popupPromise.finally(() => { | ||
@@ -215,9 +224,29 @@ clearInterval(closeTimeout); | ||
} | ||
closePopup(window) { | ||
this.promises = []; | ||
if (!window || window.closed) { | ||
return; | ||
closeAllPoups() { | ||
for (const key of this.popupWindows.keys()) { | ||
this.closePopup(key); | ||
} | ||
window.close(); | ||
} | ||
closePopup(flowId) { | ||
const popupWindowToClose = this.popupWindows.get(flowId); | ||
if (popupWindowToClose) { | ||
if (popupWindowToClose.window && !popupWindowToClose.window.closed) { | ||
try { | ||
popupWindowToClose.window.close(); | ||
} | ||
catch (_a) { | ||
// Ignore errors | ||
} | ||
} | ||
if (popupWindowToClose.listener) { | ||
try { | ||
popupWindowToClose.listener.abort(); | ||
} | ||
catch (_b) { | ||
// Ignore errors | ||
} | ||
} | ||
} | ||
this.popupWindows.delete(flowId); | ||
} | ||
matchEventOrigin(eventOrigin, origin) { | ||
@@ -232,7 +261,3 @@ if (eventOrigin === origin) { | ||
} | ||
cleanUpIfNecessary() { | ||
this.promises.forEach((p) => p.abort()); | ||
this.promises = []; | ||
} | ||
} | ||
//# sourceMappingURL=popup.js.map |
@@ -8,3 +8,3 @@ import * as consts from "./auth/constants"; | ||
API_DEFAULT_TIMEOUT_MS: 60 * 1000, | ||
POPUP_RESPONSE_TIMEOUT_MS: 30 * 1000, //the timeout to receive a response from the popup | ||
POPUP_RESPONSE_TIMEOUT_MS: 10 * 60 * 1000, //the timeout to receive a response from the popup | ||
}; | ||
@@ -11,0 +11,0 @@ export const getOpenPassApiBaseUrl = (baseUrl) => { |
@@ -5,4 +5,6 @@ import "abortcontroller-polyfill/dist/abortcontroller-polyfill-only"; | ||
import { SdkError, AuthError } from "./auth/error/errors"; | ||
import { renderSignInButton } from "./buttons/signInButton"; | ||
shim(); | ||
document.addEventListener("DOMContentLoaded", renderSignInButton, { once: true }); | ||
export { OpenPassClient, SdkError, AuthError }; | ||
//# sourceMappingURL=main.js.map |
@@ -10,5 +10,4 @@ export declare const ERROR_MESSAGE_INVALID_AUTH_SESSION = "Unable to authenticate, a login session may not have being started. Possibly a call to login is required"; | ||
export declare const ERROR_INVALID_CLIENT_ID = "Error clientId is invalid. Please use a valid clientId"; | ||
export declare const ERROR_POPUP_FAILED_TO_OPEN = "Popup window failed to open"; | ||
export declare const ERROR_POPUP_REOPENED = "Popup window was reopened"; | ||
export declare const ERROR_POPUP_CLOSED = "Popup window was closed"; | ||
export declare const ERROR_MESSAGE_POPUP_CLOSED = "Popup closed, authentication response not available"; | ||
export declare const ERROR_MESSAGE_POPUP_TIMEOUT = "No Response received from popup"; |
@@ -12,4 +12,4 @@ import { OpenPassApiClient } from "./apiClient/openPassApiClient"; | ||
private readonly openPassClient; | ||
private readonly OpenPassOptions; | ||
private promises; | ||
private readonly openPassOptions; | ||
private readonly popupWindows; | ||
constructor(OpenPassOptions: OpenPassOptions, redirectApi: RedirectAuth, openPassClient: OpenPassApiClient); | ||
@@ -19,9 +19,9 @@ signInWithPopup(options: SignInOptions): Promise<SignInResponse>; | ||
private waitForPopupResponse; | ||
protected completeAuthentication(tokens: OpenPassTokens, authSession: AuthSession, popupWindow: Window): Promise<SignInResponse>; | ||
protected completeAuthentication(flowId: string, tokens: OpenPassTokens, authSession: AuthSession): Promise<SignInResponse>; | ||
private listenForPopupResponse; | ||
private openPopup; | ||
private isAuthCodeValid; | ||
private closeAllPoups; | ||
private closePopup; | ||
private matchEventOrigin; | ||
private cleanUpIfNecessary; | ||
} |
import "abortcontroller-polyfill/dist/abortcontroller-polyfill-only"; | ||
import OpenPassClient from "./auth/openPassClient"; | ||
import { SignInOptions, OpenPassOptions, OpenPassClientAuth } from "auth/types"; | ||
import { SignInOptions, OpenPassOptions, OpenPassClientAuth } from "./auth/types"; | ||
import { SdkError, AuthError } from "./auth/error/errors"; | ||
export { OpenPassClient, OpenPassOptions, SignInOptions, OpenPassClientAuth, SdkError, AuthError }; |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "2.1.4", | ||
"version": "2.1.5", | ||
"repository": { | ||
@@ -39,3 +39,7 @@ "type": "git", | ||
"format-check": "prettier --check .", | ||
"pre-commit": "lint-staged" | ||
"pre-commit": "lint-staged", | ||
"e2e": "npx playwright test", | ||
"e2e:server": "ts-node ./tests/e2e/server/run-server.ts", | ||
"e2e:ui": "npx playwright test --ui", | ||
"e2e:codegen": "npx playwright codegen" | ||
}, | ||
@@ -54,2 +58,5 @@ "pre-commit": [ | ||
"devDependencies": { | ||
"@playwright/test": "^1.39.0", | ||
"@types/ejs": "^3.1.3", | ||
"@types/express": "^4.17.19", | ||
"@types/jest": "^27.4.1", | ||
@@ -60,3 +67,6 @@ "@types/promise.prototype.finally": "^2.0.4", | ||
"@typescript-eslint/parser": "^5.15.0", | ||
"cheerio": "^1.0.0-rc.12", | ||
"concurrently": "^7.2.2", | ||
"dotenv": "^16.3.1", | ||
"ejs": "^3.1.9", | ||
"eslint": "^8.11.0", | ||
@@ -69,2 +79,3 @@ "eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-tsdoc": "^0.2.14", | ||
"express": "^4.18.2", | ||
"jest": "^27.5.1", | ||
@@ -75,2 +86,3 @@ "jest-location-mock": "^1.0.9", | ||
"lint-staged": "^13.0.1", | ||
"mailslurp-client": "^15.17.2", | ||
"path-browserify": "^1.0.1", | ||
@@ -82,2 +94,3 @@ "pre-commit": "^1.2.2", | ||
"ts-loader": "^9.2.6", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.5.5", | ||
@@ -84,0 +97,0 @@ "url-parse": "^1.5.10", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
630569
167
3434
37