jsforceinaction's People
jsforceinaction's Issues
Can not connect with jsForce
Hello.
I am currently writing a REST service that connect to Salesforce via jsForce with APEX REST requests.
To do so, I write code inspired by yours except that I am using a local cache service in place of a Redis server.
My routes:
// /callback
// Never reached by a request
const callback = function(request, result, next) {
const code = request.params.code;
sfService.processOAuthCode(code)
.then(result.redirect('/explorer', next))
.catch(result.redirect('error.html', next))
}
// /oauth2/auth
// Never reached by a request
const oauth2auth = function(request, result, next) {
result.redirect(sfService.getAuthorizationUrl(), next);
}
My sfService:
const getConnection = function() {
return cacheService.get('AuthorizationInfo')
.then(authInfo => {
const options = { version };
if(authInfo) {
options.instanceUrl = authInfo.instanceUrl;
options.accessToken = authInfo.accessToken;
options.oauth2 = {
clientId,
clientSecret,
redirectUri: `${protocol}://${host}:${port}/${callback}` // http://localhost:8000/callback at the moment
};
} else {
options.oauth2 = getOAuth2()
}
const connection = new Jsforce.Connection(options);
Bluebird.promisifyAll(Object.getPrototypeOf(connection))
return connection
})
.catch(error.logAndThrow('Error encountered in getConnection'));
}
const getAuthorizationUrl = function() {
return getOAuth2().getAuthorizationUrl({scope: 'api id web'});
}
const processOAuthCode = function(code) {
return cacheService.drop('AuthorizationInfo')
.then(() => getConnection())
.then(connection => [connection, connection.authorizeAsync(code)])
.spread((connection, userInfo) => {
return cacheService.set('AuthorizationInfo', {
accessToken: connection.accessToken,
instanceUrl: connection.instanceUrl,
userId: userInfo.id,
orgId: userInfo.organizationId
});
})
.catch(error.logAndThrow('Error encountered in processOAuthCode'));
}
When I am trying to fetch data using as callback of one of my route
getConnection()
.then(connection => {
return connection.requestGetAsync('/apexrest/pricebook?pricebookName=standard')
.catch(error.logAndThrow('Can not fetch data'))
})
I still have an error "resource" not found. If I print the connection content, I do not have any accessToken and it seems that my callbackUri http://localhost:8000/callback
has never been reached by a request from Salesforce.
Do you have an idea where I am doing wrong ?
Thank you in advance :)
test Issues
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.