Skip to content

Commit

Permalink
version issue fixed on SFDC
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Midgley committed Dec 27, 2020
1 parent 023c44e commit 565f882
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/client/modules/platformevent/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ export default class Config extends LightningElement {
'/api/platformeventactivity/oauth/response/'
)
) {
popup.close();
clearInterval(checkComplete);
this.isLoading = false;
this.isEditing = false;
}
}, 3000);
}, 1000);
} else {
this.dispatchEvent(
new CustomEvent('error', {
Expand Down
4 changes: 3 additions & 1 deletion src/server/platformeventactivity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ router.get('/oauth/response/:mid', async (req, res) => {
try {
await sfdc.authorize(req.params.mid, req.query.code);
delete req.session.temp;
res.status(200).send('Authorized, you can close this now!');
res.status(200).send(
'Finalizing Authorization. This window will close in a couple of seconds'
);
} catch (ex) {
res.status(500).json({ message: ex });
}
Expand Down
18 changes: 15 additions & 3 deletions src/server/sfdc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const connectionArray = {};

exports.getMetadata = async (mid) => {
const res = await connectionArray[mid].describeGlobal();

return Promise.all(
res.sobjects
.filter((obj) => obj.name.endsWith('__e'))
Expand All @@ -30,12 +29,20 @@ const init = async () => {
connectionArray[withoutPrefix] = new jsforce.Connection(
JSON.parse(conn)
);
// add refresh handler to save refresh token
connectionArray[withoutPrefix].on('refresh', (accessToken, res) => {
logger.info('on Refresh', accessToken, res);
saveCredentials(withoutPrefix, connectionArray[withoutPrefix]);
logger.info('refreshed and saved credentials');
// Refresh event will be fired when renewed access token
// to store it in your storage for next request
});
});
};

exports.loginurl = (cred, hostname, mid, state) => {
connectionArray[mid] = new jsforce.Connection({
version: '50',
version: '50.0',
loginUrl: cred.sfdcurl,
oauth2: {
loginUrl: cred.sfdcurl,
Expand Down Expand Up @@ -73,13 +80,15 @@ exports.authorize = async (mid, code) => {
try {
const userInfo = await connectionArray[mid].authorize(code);
logger.info('userInfo', userInfo);
connectionArray[mid].on('refresh', async (accessToken, res) => {
connectionArray[mid] = new jsforce.Connection(connectionArray[mid]);
connectionArray[mid].on('refresh', (accessToken, res) => {
logger.info('on Refresh', accessToken, res);
saveCredentials(mid, connectionArray[mid]);
logger.info('refreshed and saved credentials');
// Refresh event will be fired when renewed access token
// to store it in your storage for next request
});

await saveCredentials(mid, connectionArray[mid]);
// Now you can get the access token, refresh token, and instance URL information.
// Save them to establish connection next time.
Expand All @@ -95,14 +104,17 @@ exports.authorize = async (mid, code) => {

async function saveCredentials(mid, conf) {
logger.info('saving credentials to redis', mid, {
version: conf.version,
oauth2: conf.oauth2,
accessToken: conf.accessToken,
refreshToken: conf.refreshToken,
instanceUrl: conf.instanceUrl
});

const setCred = await redis.set(
mid,
JSON.stringify({
version: '50.0',
oauth2: conf.oauth2,
accessToken: conf.accessToken,
refreshToken: conf.refreshToken,
Expand Down

0 comments on commit 565f882

Please sign in to comment.