Skip to content

Commit

Permalink
fix(arcgis-rest-auth): enable oAuth from within an IFrame
Browse files Browse the repository at this point in the history
Adds a new check for oauth handler on window.opener, and cleans up previous handler checks.

AFFECTS PACKAGES:
@esri/arcgis-rest-auth

ISSUES CLOSED: #711
  • Loading branch information
dbouwman committed Jul 1, 2020
1 parent abaaa16 commit e6538d5
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions packages/arcgis-rest-auth/src/UserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,31 +355,25 @@ export class UserSession implements IAuthenticationManager {

function completeSignIn(error: any, oauthInfo?: IFetchTokenResponse) {
try {
if (
popup &&
win.opener &&
win.opener.parent &&
win.opener.parent[`__ESRI_REST_AUTH_HANDLER_${clientId}`]
) {
const handlerFn =
win.opener.parent[`__ESRI_REST_AUTH_HANDLER_${clientId}`];
if (handlerFn) {
handlerFn(
error ? JSON.stringify(error) : undefined,
JSON.stringify(oauthInfo)
);
let handlerFn;
const handlerFnName = `__ESRI_REST_AUTH_HANDLER_${clientId}`;

if (popup) {
// Guard b/c IE does not support window.opener
if (win.opener) {
if (win.opener.parent && win.opener.parent[handlerFnName]) {
handlerFn = win.opener.parent[handlerFnName];
} else if (win.opener && win.opener[handlerFnName]) {
// support pop-out oauth from within an iframe
handlerFn = win.opener[handlerFnName];
}
} else {
// IE
if (win !== win.parent && win.parent && win.parent[handlerFnName]) {
handlerFn = win.parent[handlerFnName];
}
}
win.close();
return undefined;
}

if (
popup &&
win !== win.parent &&
win.parent &&
win.parent[`__ESRI_REST_AUTH_HANDLER_${clientId}`]
) {
const handlerFn = win.parent[`__ESRI_REST_AUTH_HANDLER_${clientId}`];
// if we have a handler fn, call it and close the window
if (handlerFn) {
handlerFn(
error ? JSON.stringify(error) : undefined,
Expand Down

0 comments on commit e6538d5

Please sign in to comment.