Skip to content

Commit 34f53c6

Browse files
Merge pull request #965 from sven-codeculture/master
Add a windowRef option to initLoginFlowInPopup to prevent the window from beeing blocked by popup blockers
2 parents 5e00358 + 430e597 commit 34f53c6

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

projects/lib/src/oauth-service.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,12 @@ export class OAuthService extends AuthConfig implements OnDestroy {
11071107
public initImplicitFlowInPopup(options?: {
11081108
height?: number;
11091109
width?: number;
1110+
windowRef?: Window
11101111
}) {
11111112
return this.initLoginFlowInPopup(options);
11121113
}
11131114

1114-
public initLoginFlowInPopup(options?: { height?: number; width?: number }): Promise<boolean> {
1115+
public initLoginFlowInPopup(options?: { height?: number; width?: number; windowRef?: Window }) {
11151116
options = options || {};
11161117
return this.createLoginUrl(
11171118
null,
@@ -1127,11 +1128,21 @@ export class OAuthService extends AuthConfig implements OnDestroy {
11271128
* Error handling section
11281129
*/
11291130
const checkForPopupClosedInterval = 500;
1130-
let windowRef = window.open(
1131-
url,
1132-
'_blank',
1133-
this.calculatePopupFeatures(options)
1134-
);
1131+
1132+
let windowRef = null;
1133+
// If we got no window reference we open a window
1134+
// else we are using the window already opened
1135+
if(!options.windowRef) {
1136+
windowRef = window.open(
1137+
url,
1138+
'_blank',
1139+
this.calculatePopupFeatures(options)
1140+
);
1141+
} else if(options.windowRef && !options.windowRef.closed) {
1142+
windowRef = options.windowRef;
1143+
windowRef.location.href = url;
1144+
}
1145+
11351146
let checkForPopupClosedTimer: any;
11361147

11371148
const tryLogin = (hash: string) => {

0 commit comments

Comments
 (0)