How to use the jsforce.OAuth2 function in jsforce

To help you get started, we’ve selected a few jsforce examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / jsforce / jsforce-tests.ts View on Github external
console.log(`itemsLikeCreateResult['likedItem']: ${itemsLikeCreateResult as any['likedItem']}`);
}

(async () => {
    const query2: sf.QueryResult =
        await (salesforceConnection.query("SELECT Id, Name FROM User") as Promise>);
    console.log("Query Promise: total in database: " + query2.totalSize);
    console.log("Query Promise: total fetched : " + query2.records[0]);

    await testAnalytics(salesforceConnection);
    await testChatter(salesforceConnection);
    await testMetadata(salesforceConnection);
    await testExecuteAnonymous(salesforceConnection);
})();

const oauth2 = new sf.OAuth2({
    // you can change loginUrl to connect to sandbox or prerelease env.
    // loginUrl : 'https://test.salesforce.com',
    clientId: '',
    clientSecret: '',
    redirectUri: ''
});
oauth2.getAuthorizationUrl({ scope: 'api id web' });

const job = salesforceConnection.bulk.createJob("Account", "insert");
const batch = job.createBatch();
batch.execute(undefined);
batch.on("queue", (batchInfo) => { // fired when batch request is queued in server.
    console.log('batchInfo:', batchInfo);
    const batchId = batchInfo.id;
    const jobId = batchInfo.jobId;
});
github gbockus / jsForceInAction / server / services / SalesforceService.js View on Github external
function getOAuth2() {
    return new jsforce.OAuth2({
      // you can change loginUrl to connect to sandbox or prerelease env.
      // loginUrl : 'https://test.salesforce.com',
      clientId: config.app.key,
      clientSecret: config.app.secret,
      redirectUri: config.app.callbackURL
    });
  }
github douglascayers / sfdc-swag-level-platform-events-demo / app.js View on Github external
// ==============================================
// Load libraries
// ==============================================

var dotenv   = require('dotenv').config();          // necessary if running via 'node app.js' instead of 'heroku local'
var jsforce  = require('jsforce');                  // salesforce client
var express  = require('express');                  // nodejs de-facto web server
var exphbs   = require('express-handlebars');       // for html templating responses
var path     = require('path');                     // utility for parsing and formatting file paths

// ==============================================
// Salesforce OAuth Settings (reusable)
// ==============================================

var sf_oauth2 = new jsforce.OAuth2({
    loginUrl : process.env.OAUTH_SALESFORCE_LOGIN_URL,
    clientId : process.env.OAUTH_SALESFORCE_CLIENT_ID,
    clientSecret : process.env.OAUTH_SALESFORCE_CLIENT_SECRET,
    redirectUri : process.env.OAUTH_SALESFORCE_REDIRECT_URI
});

// ==============================================
// Configure web app to respond to requests
// ==============================================

var app = express();

app.engine( 'handlebars', exphbs( { defaultLayout: 'main' } ) );

app.set( 'view engine', 'handlebars' );
app.set( 'json spaces', 4 ); // pretty print json
github forcedotcom / OrgMonitor / lib / org.js View on Github external
constructor (options) {
    if (!options) throw new Error('Need options')
    let oauth2 = oauth2model
    oauth2.loginUrl = options.loginUrl || 'https://login.salesforce.com'
    Object.assign(this, options)

    this.connection = new jsforce.Connection({
      oauth2: new jsforce.OAuth2(oauth2),
      instanceUrl: options.instanceUrl,
      refreshToken: Crypto.decrypt(options.refreshToken)
    })

    this.connection.on('refresh', (accessToken, res) => {
      console.log(`[${this.orgId}] Refreshing Oauth2 token..`)
      this.connection.accessToken = accessToken
    })
  }
github forcedotcom / OrgMonitor / routes / index.js View on Github external
router.get('/add/:type', (req, res) => {
  let oauth2 = oauth2model
  let loginUrl = 'https://login.salesforce.com'
  if (req.params.type === 'sandbox') loginUrl = 'https://test.salesforce.com'
  oauth2.loginUrl = loginUrl
  res.redirect(new jsforce.OAuth2(oauth2).getAuthorizationUrl({ scope: 'api refresh_token' }))
})
github postlight / glide / src / oauth.ts View on Github external
function createConnection(instance: string, session: Session): Connection {
  const { oauth2, ...tokens } = session;

  return new Connection({
    ...tokens,
    instanceUrl: instance,
    oauth2: new OAuth2(oauth2),
  });
}
github xgeek-net / pipeline / src / class / SfdcApi.js View on Github external
getOAuthClient(orgType) {
    var loginUrl = (orgType == 'production') ? 'https://login.salesforce.com' : 'https://test.salesforce.com';
    var oauth2 = new jsforce.OAuth2({
      loginUrl : loginUrl,
      clientId : CLIENT.SFDC_CLIENT_ID,
      clientSecret : CLIENT.SFDC_CLIENT_SECRET,
      redirectUri : CLIENT.SFDC_CALLBACK_URL + '&orgType=' + orgType
    });
    return oauth2;
  }
  /**

jsforce

Salesforce API Library for JavaScript

MIT
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis