Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sfQuery(queryString, success, error){
let conn = new jsforce.Connection();
// Security Risk!
conn.login('username@example.com', 'salesforcepassword', function(err, res) {
if (err) {
error(err);
console.error(err);
}
conn.query('SELECT Id FROM User', function(err, res) {
if (err) {
error(err);
console.error(err);
}
success(res);
});
});
}
run(context) {
const username = context.flags.username;
const password = context.flags.password;
let instanceUrl = context.flags.instanceurl;
if (!instanceUrl) {
instanceUrl = 'https://login.salesforce.com';
}
const saveAsDefault = false;
const conn = new jsforce.Connection({
// you can change loginUrl to connect to sandbox or prerelease env.
loginUrl: instanceUrl
});
conn.login(username, password, (err, userInfo) => {
if (err) {
return console.error(err);
}
const orgSaveData = [];
orgSaveData.orgId = userInfo.organizationId;
orgSaveData.accessToken = conn.accessToken;
orgSaveData.instanceUrl = conn.instanceUrl;
orgSaveData.username = username;
orgSaveData.loginUrl = instanceUrl;
app.get( '/oauth2/callback', function( req, res ) {
// in testing, browsers would send a duplicate request after 5 seconds
// if this redirection did not respond in time.
// to avoid having a duplicate request we must tell the browser to wait longer
// https://github.com/expressjs/express/issues/2512
req.connection.setTimeout( 1000 * 60 * 10 ); // ten minutes
// initialize salesforce client for making the oauth authorization request
var sfClient = new jsforce.Connection({
oauth2 : sf_oauth2,
version : process.env.SALESFORCE_API_VERSION
});
// salesforce oauth authorize request to get access token
sfClient.authorize( req.query.code, function( err, userInfo ) {
if ( err ) {
handleError( err, res );
} else {
subscribeToEvents( sfClient, res );
}
public async run(): Promise {
const username = this.flags.username;
let password = this.flags.password;
let instanceUrl = this.flags.instanceurl;
if (!instanceUrl) {
instanceUrl = 'https://login.salesforce.com';
}
if (!password) {
password = await this.ux.prompt(`password for ${username}`, { type: 'mask' });
}
const conn = new jsforce.Connection({
// you can change loginUrl to connect to sandbox or prerelease env.
loginUrl: instanceUrl
});
await conn.login(username, password);
const accessTokenOptions = {
accessToken: conn.accessToken,
instanceUrl: conn.instanceUrl,
loginUrl: instanceUrl,
orgId: getString(conn, 'userInfo.organizationId')
};
const auth = await AuthInfo.create({ username, accessTokenOptions });
await auth.save();
var credentials = require('./salesforce-credentials.js');
var jsforce = require('jsforce');
var conn = new jsforce.Connection({});
conn.login(credentials.user, credentials.passwordtoken, function(err, userInfo) {
if (err) { return console.error(err); }
console.log("Bearer " + conn.accessToken);
console.log(conn.instanceUrl);
console.log("User ID: " + userInfo.id);
console.log("Org ID: " + userInfo.organizationId);
});
app.get( '/publish', function( req, res ) {
console.log( 'publishing new event...' );
var sfClient = new jsforce.Connection({
instanceUrl : req.query.instanceUrl,
accessToken : req.query.accessToken,
version : req.query.version
});
sfClient.sobject( 'Swag_Level__e' ).create({
'Level__c' : 'Low'
}).then( function( result ) {
console.log( result );
res.redirect( '/subscribe?accessToken=' + sfClient.accessToken + '&instanceUrl=' + sfClient.instanceUrl );
}).catch( function( err ) {
.then(orgInf => {
service.currentConnection = service.addConnection(orgInf, true);
if (!service.currentConnection) {
return Promise.reject('Error setting up connection');
}
vscode.window.forceCode.config = readConfigFile(orgInf.username);
const sfdxPath = path.join(
operatingSystem.getHomeDir(),
'.sfdx',
orgInf.username + '.json'
);
const refreshToken: string = fs.readJsonSync(sfdxPath).refreshToken;
service.currentConnection.connection = new jsforce.Connection({
oauth2: {
clientId:
service.currentConnection.orgInfo.clientId || 'SalesforceDevelopmentExperience',
},
instanceUrl: service.currentConnection.orgInfo.instanceUrl,
accessToken: service.currentConnection.orgInfo.accessToken,
refreshToken: refreshToken,
version:
vscode.window.forceCode &&
vscode.window.forceCode.config &&
vscode.window.forceCode.config.apiVersion
? vscode.window.forceCode.config.apiVersion
: vscode.workspace.getConfiguration('force')['defaultApiVersion'],
});
if (service.currentConnection.connection) {
var express = require('express');
var router = express.Router();
var jsforce = require('jsforce');
var conn = new jsforce.Connection({
serverUrl: 'https://ltng1-dev-ed.my.salesforce.com',
sessionId: '00Di0000000JEm3!AQ4AQEoB90cYo66ZD8DLTaegtPMrnt3LqoUHaKnRh1uP.mU8cAlJudaqx_jJhASRVx4pcPgCLwWOjRTu2fRrLIR6DgBYciDJ'
});
router.get('/posts', function(req, res, next) {
var q = req.query.query;
conn.query(q, function(err, result) {
if (err) {
return res.status(400).json(err);
}
res.json(result);
});
});
application.post("/", json(), (request, response, next) => {
const authorization = request.get("authorization");
let { connection } = options;
if (typeof authorization === "string") {
connection = new Connection({
accessToken: authorization.substr(7),
instanceUrl: options.instance,
});
}
if (connection == null) {
return next(new GraphQLError("Session expired or invalid"));
}
runtime(connection, request.body.query).then(
result => response.json(result),
error => next(error),
);
});
function createConnection(instance: string, session: Session): Connection {
const { oauth2, ...tokens } = session;
return new Connection({
...tokens,
instanceUrl: instance,
oauth2: new OAuth2(oauth2),
});
}