Skip to content

Commit

Permalink
fix: check event source
Browse files Browse the repository at this point in the history
  • Loading branch information
abuaboud committed Mar 29, 2023
1 parent df29643 commit 82325ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 9 additions & 11 deletions packages/frontend/src/app/modules/common/service/oauth2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,15 @@ export class Oauth2Service {
this.currentlyOpenPopUp = popup;
const codeObs$ = new Observable<any>((observer) => {
window.addEventListener('message', function handler(event) {
if (redirect_uri.startsWith(event.origin)) {
if (event.data != undefined) {
event.data.code = decodeURIComponent(event.data.code);
observer.next(event.data);
popup?.close();
observer.complete();
} else {
observer.error('No code returned');
popup?.close();
observer.complete();
}
if (
redirect_uri.startsWith(event.origin) &&
event.data['code'] &&
event.data['source'] === 'activepieces'
) {
event.data.code = decodeURIComponent(event.data.code);
observer.next(event.data);
popup?.close();
observer.complete();
window.removeEventListener('message', handler);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ export class RedirectUrlComponent implements OnInit {
.pipe(
tap((params) => {
if (window.opener && params['code'] != undefined) {
window.opener.postMessage(params, '*');
window.opener.postMessage(
{
code: params['code'],
source: 'activepieces',
},
'*'
);
}
})
)
.pipe(map((value) => void 0));
.pipe(map(() => void 0));
}
}

0 comments on commit 82325ec

Please sign in to comment.