@openpass/openpass-js-sdk
Advanced tools
Comparing version 4.2.3 to 4.3.0
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.2.3", | ||
"version": "4.3.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -26,2 +26,3 @@ "use strict"; | ||
constructor(openPassOptions, redirectAuth, popupAuth, apiClient) { | ||
this.currentLoginHint = null; | ||
this.openPassOptions = openPassOptions; | ||
@@ -79,2 +80,8 @@ this.popupAuth = popupAuth; | ||
try { | ||
// refocus popup if the login hints match and the popup is already open | ||
if (this.currentLoginHint === data.loginHint && this.popupAuth.refocusIfPopupExists()) { | ||
break; | ||
} | ||
// otherwise start a new flow | ||
this.currentLoginHint = data.loginHint; | ||
const popupResult = yield this.popupAuth.signInWithPopup(Object.assign(Object.assign({}, signInOptionsBase), { redirectUrl: inlineSignInOptions.redirectUrl, source: "SignInWithOpenPassInlineForm" })); | ||
@@ -81,0 +88,0 @@ if (popupSuccessCallback) { |
@@ -38,3 +38,2 @@ "use strict"; | ||
constructor(OpenPassOptions, redirectApi, openPassClient) { | ||
this.popupWindows = new Map(); | ||
this.openPassOptions = OpenPassOptions; | ||
@@ -44,9 +43,13 @@ this.openPassClient = openPassClient; | ||
} | ||
refocusIfPopupExists() { | ||
if (!this.popupWindow || this.popupWindow.window.closed) { | ||
return false; | ||
} | ||
this.popupWindow.window.focus(); | ||
return true; | ||
} | ||
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(); | ||
} | ||
const flowId = new Date().getTime().toString(); | ||
this.closePopupIfExists(this.popupWindow); | ||
let popup; | ||
@@ -73,7 +76,4 @@ let popupErrorMessage = null; | ||
} | ||
const authWindow = { | ||
flowId, | ||
window: popup, | ||
}; | ||
this.popupWindows.set(flowId, authWindow); | ||
const authWindow = { window: popup }; | ||
this.popupWindow = authWindow; | ||
return this.doLogin(authWindow, options); | ||
@@ -85,4 +85,4 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const popupCloseHandler = (e) => { | ||
this.closePopup(authWindow.flowId); | ||
const popupCloseHandler = () => { | ||
this.closePopupIfExists(authWindow); | ||
}; | ||
@@ -113,3 +113,3 @@ window.addEventListener("beforeunload", popupCloseHandler); | ||
if (!(e instanceof errors_1.AuthCancelledError)) { | ||
this.closePopup(authWindow.flowId); | ||
this.closePopupIfExists(authWindow); | ||
} | ||
@@ -130,6 +130,6 @@ throw e; | ||
const openPassTokens = yield this.openPassClient.exchangeAuthCodeForTokens(authCodeResponse.code, authSession); | ||
return yield this.completeAuthentication(authWindow.flowId, openPassTokens, authSession); | ||
return yield this.completeAuthentication(authWindow, openPassTokens, authSession); | ||
}); | ||
} | ||
completeAuthentication(flowId, tokens, authSession) { | ||
completeAuthentication(authWindow, tokens, authSession) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -144,3 +144,3 @@ const { idToken, rawIdToken, rawAccessToken, expiresIn, tokenType } = tokens; | ||
try { | ||
this.closePopup(flowId); | ||
this.closePopupIfExists(authWindow); | ||
resolve({ | ||
@@ -158,3 +158,3 @@ clientState: authSession.clientState, | ||
catch (e) { | ||
this.closePopup(flowId); | ||
this.closePopupIfExists(authWindow); | ||
reject(e); | ||
@@ -176,3 +176,3 @@ } | ||
window.removeEventListener("message", messageHandler); | ||
this.closePopup(authWindow.flowId); | ||
this.closePopupIfExists(authWindow); | ||
reject(new errors_1.SdkError("Popup closed, authentication response not available")); | ||
@@ -230,28 +230,27 @@ } | ||
} | ||
closeAllPoups() { | ||
for (const key of this.popupWindows.keys()) { | ||
this.closePopup(key); | ||
closePopupIfExists(popupWindowToClose) { | ||
if (!popupWindowToClose) { | ||
return; | ||
} | ||
} | ||
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.window && !popupWindowToClose.window.closed) { | ||
try { | ||
popupWindowToClose.window.close(); | ||
} | ||
if (popupWindowToClose.listener) { | ||
try { | ||
popupWindowToClose.listener.abort(); | ||
} | ||
catch (_b) { | ||
// Ignore errors | ||
} | ||
catch (e) { | ||
console.warn("Error closing the openpass popup window", e); | ||
} | ||
} | ||
this.popupWindows.delete(flowId); | ||
if (popupWindowToClose.listener) { | ||
try { | ||
popupWindowToClose.listener.abort(); | ||
popupWindowToClose.listener = undefined; | ||
} | ||
catch (e) { | ||
console.warn("Error aborting the openpass popup listener", e); | ||
} | ||
} | ||
// Only set the popup to null if the closed window was the current popup | ||
if (popupWindowToClose == this.popupWindow) { | ||
this.popupWindow = undefined; | ||
} | ||
} | ||
@@ -258,0 +257,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.2.3", | ||
"version": "4.3.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -24,2 +24,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
constructor(openPassOptions, redirectAuth, popupAuth, apiClient) { | ||
this.currentLoginHint = null; | ||
this.openPassOptions = openPassOptions; | ||
@@ -77,2 +78,8 @@ this.popupAuth = popupAuth; | ||
try { | ||
// refocus popup if the login hints match and the popup is already open | ||
if (this.currentLoginHint === data.loginHint && this.popupAuth.refocusIfPopupExists()) { | ||
break; | ||
} | ||
// otherwise start a new flow | ||
this.currentLoginHint = data.loginHint; | ||
const popupResult = yield this.popupAuth.signInWithPopup(Object.assign(Object.assign({}, signInOptionsBase), { redirectUrl: inlineSignInOptions.redirectUrl, source: "SignInWithOpenPassInlineForm" })); | ||
@@ -79,0 +86,0 @@ if (popupSuccessCallback) { |
@@ -33,3 +33,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
constructor(OpenPassOptions, redirectApi, openPassClient) { | ||
this.popupWindows = new Map(); | ||
this.openPassOptions = OpenPassOptions; | ||
@@ -39,9 +38,13 @@ this.openPassClient = openPassClient; | ||
} | ||
refocusIfPopupExists() { | ||
if (!this.popupWindow || this.popupWindow.window.closed) { | ||
return false; | ||
} | ||
this.popupWindow.window.focus(); | ||
return true; | ||
} | ||
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(); | ||
} | ||
const flowId = new Date().getTime().toString(); | ||
this.closePopupIfExists(this.popupWindow); | ||
let popup; | ||
@@ -68,7 +71,4 @@ let popupErrorMessage = null; | ||
} | ||
const authWindow = { | ||
flowId, | ||
window: popup, | ||
}; | ||
this.popupWindows.set(flowId, authWindow); | ||
const authWindow = { window: popup }; | ||
this.popupWindow = authWindow; | ||
return this.doLogin(authWindow, options); | ||
@@ -80,4 +80,4 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const popupCloseHandler = (e) => { | ||
this.closePopup(authWindow.flowId); | ||
const popupCloseHandler = () => { | ||
this.closePopupIfExists(authWindow); | ||
}; | ||
@@ -108,3 +108,3 @@ window.addEventListener("beforeunload", popupCloseHandler); | ||
if (!(e instanceof AuthCancelledError)) { | ||
this.closePopup(authWindow.flowId); | ||
this.closePopupIfExists(authWindow); | ||
} | ||
@@ -125,6 +125,6 @@ throw e; | ||
const openPassTokens = yield this.openPassClient.exchangeAuthCodeForTokens(authCodeResponse.code, authSession); | ||
return yield this.completeAuthentication(authWindow.flowId, openPassTokens, authSession); | ||
return yield this.completeAuthentication(authWindow, openPassTokens, authSession); | ||
}); | ||
} | ||
completeAuthentication(flowId, tokens, authSession) { | ||
completeAuthentication(authWindow, tokens, authSession) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -139,3 +139,3 @@ const { idToken, rawIdToken, rawAccessToken, expiresIn, tokenType } = tokens; | ||
try { | ||
this.closePopup(flowId); | ||
this.closePopupIfExists(authWindow); | ||
resolve({ | ||
@@ -153,3 +153,3 @@ clientState: authSession.clientState, | ||
catch (e) { | ||
this.closePopup(flowId); | ||
this.closePopupIfExists(authWindow); | ||
reject(e); | ||
@@ -171,3 +171,3 @@ } | ||
window.removeEventListener("message", messageHandler); | ||
this.closePopup(authWindow.flowId); | ||
this.closePopupIfExists(authWindow); | ||
reject(new SdkError("Popup closed, authentication response not available")); | ||
@@ -225,30 +225,29 @@ } | ||
} | ||
closeAllPoups() { | ||
for (const key of this.popupWindows.keys()) { | ||
this.closePopup(key); | ||
closePopupIfExists(popupWindowToClose) { | ||
if (!popupWindowToClose) { | ||
return; | ||
} | ||
} | ||
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.window && !popupWindowToClose.window.closed) { | ||
try { | ||
popupWindowToClose.window.close(); | ||
} | ||
if (popupWindowToClose.listener) { | ||
try { | ||
popupWindowToClose.listener.abort(); | ||
} | ||
catch (_b) { | ||
// Ignore errors | ||
} | ||
catch (e) { | ||
console.warn("Error closing the openpass popup window", e); | ||
} | ||
} | ||
this.popupWindows.delete(flowId); | ||
if (popupWindowToClose.listener) { | ||
try { | ||
popupWindowToClose.listener.abort(); | ||
popupWindowToClose.listener = undefined; | ||
} | ||
catch (e) { | ||
console.warn("Error aborting the openpass popup listener", e); | ||
} | ||
} | ||
// Only set the popup to null if the closed window was the current popup | ||
if (popupWindowToClose == this.popupWindow) { | ||
this.popupWindow = undefined; | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=popup.js.map |
@@ -13,2 +13,3 @@ import { OpenPassApiClient } from "./api/openPassApiClient"; | ||
private readonly apiClient; | ||
private currentLoginHint; | ||
/** | ||
@@ -15,0 +16,0 @@ * Initializes a new instance of the InlineSignInForm class. |
import { OpenPassApiClient } from "./api/openPassApiClient"; | ||
import RedirectAuth from "./redirect"; | ||
import AbortablePromise from "./utils/abortablePromise"; | ||
import { OpenPassOptions, OpenPassTokens, SignInResponse } from "../types"; | ||
import { AuthSession, InternalPopupSignInOptions } from "./internalTypes"; | ||
type AuthWindow = { | ||
window: Window; | ||
listener?: AbortablePromise<any>; | ||
}; | ||
/** | ||
@@ -14,13 +19,14 @@ * Class which handles the Popup authorization flow. | ||
private readonly openPassOptions; | ||
private readonly popupWindows; | ||
private popupWindow; | ||
constructor(OpenPassOptions: OpenPassOptions, redirectApi: RedirectAuth, openPassClient: OpenPassApiClient); | ||
refocusIfPopupExists(): boolean; | ||
signInWithPopup(options: InternalPopupSignInOptions): Promise<SignInResponse>; | ||
private doLogin; | ||
private waitForPopupResponse; | ||
protected completeAuthentication(flowId: string, tokens: OpenPassTokens, authSession: AuthSession): Promise<SignInResponse>; | ||
protected completeAuthentication(authWindow: AuthWindow, tokens: OpenPassTokens, authSession: AuthSession): Promise<SignInResponse>; | ||
private listenForPopupResponse; | ||
private openPopup; | ||
private isAuthCodeValid; | ||
private closeAllPoups; | ||
private closePopup; | ||
private closePopupIfExists; | ||
} | ||
export {}; |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.2.3", | ||
"version": "4.3.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
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
1283790
7491