This repo has the sample code for connecting to Salesforce using OAuth Web Server flow from an LWC OSS App.
The basic version of the app is built using the Trailhead Project Build Your First Application with Lightning Web Components Open Source.
The Salesforce Data Model for the app is created using the first 3 units of the Trailhead Project Access Salesforce Data with Lightning Web Components Open Source.
The logout functionality is implemented in 2 different ways
- Logging out of the app, doesnt log you out of your active Salesforce session. The code for this is present in the
master
branch - Logging out of the app also logs you out of your active Salesforce session. The code for this is present in the
single-logout
branch.
-
Create a connected app in your Salesforce Org
- Add
http://localhost:3001/oauth2/callback
to the list of Callback URLs. - Add
api
to the list of Selected OAuth Scopes
- Add
-
Note the Consumer Key and Consumer Secret.
-
Clone this repository:
git clone https://github.com/adityanaag3/lwc-oss-oauth cd lwc-oss-oauth
-
Create a
.env
file at the root of the project, and add the following code:SALESFORCE_LOGIN_DOMAIN='https://login.salesforce.com' SALESFORCE_CLIENT_ID='YOUR_SALESFORCE_CONSUMER_KEY' SALESFORCE_CLIENT_SECRET='YOUR_SALESFORCE_CONSUMER_SECRET' SALESFORCE_CALLBACK_URL='http://localhost:3001/oauth2/callback' NODE_SESSION_SECRET_KEY='SOME_RANDOM_SECRET_KEY'
-
Run
npm install
. (Refer to package.json for the dependencies that'll be installed) -
Run
npm run watch
. This will start the project with a local development server.