This application demonstrates OAuth 2.0 integration with Salesforce, supporting both global and China instances.
server
├── .env
├── app.js
├── bin
│ └── www
├── package-lock.json
├── package.json
├── public
│ ├── images
│ ├── javascripts
│ └── stylesheets
│ └── style.css
├── routes
│ └── auth.routes.js
├── utils
│ └── auth.service.js
└── views
├── error.pug
├── index.pug
└── layout.pug
client
├── .gitignore
├── README.md
├── eslint.config.js
├── index.html
├── package-lock.json
├── package.json
├── public
│ └── vite.svg
├── src
│ ├── App.css
│ ├── App.jsx
│ ├── assets
│ │ ├── react.svg
│ │ ├── sf.png
│ │ └── sfoa.png
│ ├── components
│ │ ├── EnvironmentSelector.jsx
│ │ └── Layout.jsx
│ ├── config
│ │ └── environments.js
│ ├── context
│ │ └── AuthContext.jsx
│ ├── index.css
│ ├── main.jsx
│ └── pages
│ ├── Dashboard.jsx
│ └── HomePage.jsx
└── vite.config.js
- Node.js 20.x
- npm 10.x
- Redis
Refer here for specific instructions on installing Redis locally.
- Fork this repository
- Clone your forked repository locally
Repeat this step for both Salesforce, and Salesforce on Alibaba Cloud instances
- Log in to your Salesforce org
- Go to Setup > Apps > App Manager
- Click "New Connected App" and select "Create External Client App"
- Fill in the basic information
- Enable OAuth Settings
- Set the callback URL to
https://your-app-name.herokuapp.com/auth/salesforce/callback
- Add the following OAuth scopes:
- Access and manage your data (api)
- Access your basic information (id, profile, email, address, phone)
- Perform requests at any time (refresh_token, offline_access)
- Save the application
- Copy your Consumer Key (Client ID) and Consumer Secret
```
SESSION_SECRET=your-random-secret-key
SF_CLIENT_ID=your-salesforce-client-id
SF_CLIENT_SECRET=your-salesforce-client-secret
SFOA_CLIENT_ID=your-salesforce-on-alibaba-cloud-client-id
SFOA_CLIENT_SECRET=your-salesforce-on-alibaba-cloud-client-secret
SF_CALLBACK_URL=https://your-app-name.herokuapp.com/auth/salesforce/callback
SF_LOGIN_URL=https://login.salesforce.com
SFOA_LOGIN_URL=https://login.sfcrmproducts.cn
REDIS_URL=your-redis-connection-string
NODE_ENV=production
```
To start both front and back end, from project root run
npm run dev
This will start:
- Backend server on http://localhost:3000
- Frontend dev server on http://localhost:5173
# Start just the backend
npm run dev:server
# Start just the frontend
npm run dev:client
MIT