Git Product home page Git Product logo

salesforce-next-auth's Introduction

Salesforce Authentication in Next.js using NextAuth

๐Ÿ‘‹ Introduction

This project was created to demonstrate how to use NextAuth.js to Authenticate Salesforce as the provider of the authentication. There is no critical data that are being stored.

There is no database involved, it only uses the access_token and refresh_token provided by the Salesforce after the authentication, and by that, we can use the Refresh Rotation Strategy.

This project also uses the jsforce library to retrieve some data from Salesforce after the authentication is completed.

Tech Stack:

๐Ÿง‘โ€๐Ÿ”ง Pre-Work

Create Connected App in Salesforce

  1. Log in to Salesforce as an administrator.

  2. In the drop-down list of the account (in the upper-right corner), select Setup.

  3. In the left-hand pane, go to App Setup > Create >Apps.

  4. In the Connected Apps pane, click the New button.

  5. On the New Connected App page, fill the following required fields under Basic Information:

    • Connected App Name. For example, NextAuth Demo.
    • API name. For example, NextAuth Demo.
    • Contact Email.
  6. Go to API (Enable OAuth Settings), and select Enable OAuth Settings.

    • In the Callback URL field, enter http://localhost:3000/api/auth/callback/salesforce and https://YOUR_VERCEL_APP_URL/api/auth/callback/salesforce.

    • In the Selected OAuth Scopes field, for this demo I added all available scope. In your end you can only select Access and manage your data (api), and then click Add.

      Alt text

  7. Click the Save button to save the new Connected App.

  8. In the Connected Apps list, find the App that you just created, and then click Manage.

    • On the page that opens, click the Edit button.
    • Under OAuth policies, select All users may self-authorize in the Permitted Users list, and then click the Save button.
  9. Go back to the Connected Apps list, and click the App that you just created.

  10. Go to API (Enable OAuth Settings), and note down the Consumer Key and Consumer Secret, which will be used for the configuration of Environment Variables.

Environment Variables

For local installation, create .env.local in root folder of the project.

SALESFORCE_CLIENT_ID=YOUR_CLIENT_KEY
SALESFORCE_CLIENT_SECRET=YOUR_SECRET_KEY
SALESFORCE_URL_LOGIN=https://login.salesforce.com

NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=YOUR_NEXTAUTH_SECRET

To generate NextAuth Secret you can use this app: https://generate-secret.vercel.app/32

โšก๏ธ One-click Deployment to your own Vercel Account

Using the Vercel Deploy Button, you can quickly deploy this project into your own Vercel Account.

Deploy with Vercel

After clicking the Deploy button above, it will redirect to your Vercel Account, you'll see similar to the following screen shot bellow.

  1. Vercel will ask you to link your Github, Gitlab or Bitbucket. In this demo it uses Github, then populate the Repository Name and click Create. Alt text

  2. Next, it will proceed on setting up the Environment Variables needed to this project to run smoothly, then click Deploy Alt text

โšก๏ธ Local Machine Installation

git clone https://github.com/pelayochristian/salesforce-next-auth.git
cd salesforce-next-auth
npm install

Before firing up the project make sure you already set your Environment Variables.

npm run dev

Open http://localhost:3000 with your browser to see the result.

salesforce-next-auth's People

Contributors

pelayochristian avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

salesforce-next-auth's Issues

Custom Login Page

Is it possible to authenticate via custom login page with passing username and password?

csrfToken

error - SerializableError: Error serializing .csrfToken returned from getServerSideProps in "/signin".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.