Skip to content

Commit

Permalink
popup oauth sfdc added to avoid iframe issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Midgley committed Dec 26, 2020
1 parent d8f0032 commit 023c44e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
26 changes: 21 additions & 5 deletions src/client/modules/platformevent/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default class Config extends LightningElement {
onsfdcclientsecretchange(e) {
this.config.sfdcclientsecret = e.detail.value;
}

toggleEdit() {
this.isEditing = !this.isEditing;
}
Expand All @@ -32,9 +31,27 @@ export default class Config extends LightningElement {
}
);
const jsonRes = await rawRes.json();
console.log(jsonRes);
if (rawRes.status < 300) {
window.location = jsonRes.redirect;
const popup = window.open(
jsonRes.redirect,
'sfdc_login',
'width=500,height=500'
);
// we are running a check every 3 seconds if the popup is
// complete since it was easier to implement than having a
// whole other screen to return the values
// eslint-disable-next-line @lwc/lwc/no-async-operation
const checkComplete = setInterval(() => {
if (
popup.location.href.includes(
'/api/platformeventactivity/oauth/response/'
)
) {
clearInterval(checkComplete);
this.isLoading = false;
this.isEditing = false;
}
}, 3000);
} else {
this.dispatchEvent(
new CustomEvent('error', {
Expand All @@ -45,14 +62,13 @@ export default class Config extends LightningElement {
}
})
);
this.isLoading = false;
}
this.isLoading = false;
}
async connectedCallback() {
this.isLoading = true;
const rawRes = await fetch('/api/platformeventactivity/sfdcstatus');
const jsonRes = await rawRes.json();
console.log(jsonRes);
if (rawRes.status < 300) {
if (jsonRes) {
this.config = {
Expand Down
2 changes: 1 addition & 1 deletion src/server/platformeventactivity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ router.get('/oauth/response/:mid', async (req, res) => {
try {
await sfdc.authorize(req.params.mid, req.query.code);
delete req.session.temp;
res.redirect('/platformeventapp');
res.status(200).send('Authorized, you can close this now!');
} catch (ex) {
res.status(500).json({ message: ex });
}
Expand Down
4 changes: 1 addition & 3 deletions src/server/sfdc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ exports.loginurl = (cred, hostname, mid, state) => {
mid
}
});
const authURLbase = connectionArray[mid].oauth2.getAuthorizationUrl({
return connectionArray[mid].oauth2.getAuthorizationUrl({
scope: 'api id web refresh_token offline_access',
state: state
});

return authURLbase + '&display=popup';
};

exports.status = async (mid) => {
Expand Down

0 comments on commit 023c44e

Please sign in to comment.