Utility for authorizing user in a connected app, creating JWT to authenticate against it, and perform a sample callout.

Overview
Question: What is this for?

Answer: When configuring a Salesforce Connected app to use certificates to authenticate you will use JSON Web Tokens to authenticate. This application can take your certificate's key file and sign a request to create a JWT. That JWT can then be used to sign HTTP requests to your Salesforce connected app and interact with it. This application assumes you already have your connected app configured as outlined at https://salesforcecentral.com/accessing-salesforce-with-jwt-oauth-flow/

This application also allows you to authorize a user to use the given connected app. By default if your user has not logged in and you attempt to use the connected app you will recieve an error 

{"error":"invalid_grant","error_description":"user hasn't approved this consumer"}

which is very annoying. To resolve this you need to login as them once and approve the app. This tool can mostly automate that step for you by attempting to initiate the oAuth login flow which will then get you the access_token which can be used to authorize the app for this user.

Question: How to I use it?

Answer: This is a node.js application so you'll need node.js installed on your system. Then you'll need to fill out the values in your config/config.json file. Then you'll need the key file for the certificate you used in your connected app. It should look something like

-----BEGIN PRIVATE KEY-----
BUNCH OF STUFF HERE==
-----END PRIVATE KEY-----

After that you simply need to open a command shell and navigate to the directory the server.js file is in, then run 

node server.js

Or just run the start.bat file (for windows machines)

Question: The redirect part of the authorize a user isn't working. It's saying something about bad redirect?

Answer: That's not a question. But anyway, the fix is in your connected app add whatever you are using as your oauth_redirect_url in the config file. When the authorization is performed that callback is invoked but it has to be whitelisted in the app to be allowed. So just add that URL to the Callback URL configuration of your connected app.

Question: What is the config file?

Answer: The config file (config\config.json) is a JSON structured list of configuration parameters you can adjust as needed for your specific orginzation. If a config file is not found when the program is started an empty one will be created that you can then populate with your values.

Question: In the config file should I use the standard salesforce domains (test.salesforce.com/login.salesforce.com) for the loginURI and tokenURI or my custom domain?

loginURI = where to send login requests. It should be either "https://test.salesforce.com" or "https://login.salesforce.com"
tokenURI = where to token requests. It should be either "https://test.salesforce.com/services/oauth2/token" or "https://login.salesforce.com/services/oauth2/token"
authorizationURI = where to token requests. It should be either "https://test.salesforce.com/services/oauth2/authorize" or "https://login.salesforce.com/services/oauth2/authorize"
client_id = The Id of your connected app. Go to setup -> App Manager -> Your app -> View -> Consumer Key
client_secret = The secret key for your app. Go to setup -> App Manager -> Your app -> View -> Consumer Secret - > click to reveal
user = Salesforce username for the user you want to authenticate and get JWT for.
certificate_key_file = Key file for the certificate you provided to your connected app
oauth_redirect_url = some listener page that Salesforce can call that will read the access_token param. The default of https://oauthdebugger.com/debug should work fine.
oauth_scope = space seperated list of oAuth scope permissions as defined in your connected app.
custom_domain = your custom salesforce domain if you have one (this property will be automatically set in a later release)

Answer: Use the standard Salesforce domains; test.salesforce.com for sandboxes and login.salesforce.com for production and developer orgs.

Author: Dan Llewellyn ([email protected])
Credits: Based on the project by Bruce Tollefson at https://github.com/bruce-tollefson/SalesforceOauth and information from https://salesforcecentral.com/accessing-salesforce-with-jwt-oauth-flow/

You might also like...

Authenticate users into a web2 database to build a hybrid web2+web3 creator platform!

Creator Platform This project demonstrates how you can connect your web2 backend and integrate it with web3 using sign in with ethereum. Tools: React

Dec 16, 2022

The leaderboard website displays scores submitted by different players. It also allows you to submit your score. I created this project using ES6 concepts. I connected to the Leadboard API service

Leaderboard App The leaderboard website displays scores submitted by different players. It also allows you to submit your score I created this project

Dec 21, 2022

Talk to anyone connected to your network, be it LAN or your hotspot. Doesn't require internet.

Talk to anyone connected to your network, be it LAN or your hotspot. Doesn't require internet.

Apophis CLI to talk to anyone connected to your network, be it LAN or your hotspot. Doesn't require internet. Installation Make sure you have NodeJS (

Oct 16, 2022

JavaScript Express.js app serving static vanilla JS. This sample app is used in Microsoft Docs to demonstrate how to integrate Azure Storage, Azure Cosmos DB, and Azure Active Directory.

JavaScript on Azure Learn Path - Module 2 - Deploying a basic app to Azure This Learn module requires the following Azure resources to deploy correctl

Dec 31, 2022

A sample app (with TypeScript) to help developers bootstrap their Shopify app development.

⚠️ Please, refer to kanzitelli/shopify-app-template-typescript for the most up-to-date version. This repo was used for testing purposes. Shopify App N

Jun 10, 2022

An app to test out your typing speed, save your progress and view statistics against them.

An app to test out your typing speed, save your progress and view statistics against them.

Introduction An app to test out your typing speed, save your progress and view statistics against them. Demo Check out the quick demo here. Getting St

Sep 7, 2022

This project is a web application that enables users to add, edit and remove tasks they intend to perform. Built with JavaScript, HTML, and CSS.

TO DO List Unit testing using jest Create the to-do List project with webpack. Ultimately, the user should be able to add an item and delete the item

Jul 26, 2022

This is a web application that enables users to add, edit and remove tasks they intend to perform. Built with JavaScript, HTML, and CSS.

TODO LIST It list everything that you have to do, with the most important tasks at the top of the list, and the least important tasks at the bottom. B

Sep 16, 2022
Owner
null
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Generate a secured base32 one time password to authenticate your user! 🔐

Django SOTP ?? Generate a secured base32 one time password to authenticate your user! Case Study ?? Before I mention why you should use django-sotp in

アブラム (Abram) 36 Dec 22, 2022
A utility for creating toggleable items with JavaScript. Inspired by bootstrap's toggle utility. Implemented in vanillaJS in a functional style.

LUX TOGGLE Demo: https://jesschampion.github.io/lux-toggle/ A utility for creating toggleable dom elements with JavaScript. Inspired by bootstrap's to

Jess Champion 2 Oct 3, 2020
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
Omnichannel Live Chat Widget UI Components offers a re-usable component-based library to help create a custom chat widget that can be connected to the Dynamics 365 Customer Service experience.

Omnichannel Live Chat Widget UI Components @microsoft/omnichannel-chat-widget is a React-based UI component library which allows you to build your own

Microsoft 14 Dec 15, 2022
Authenticate your Replit Users without ReplAuth.

Replit Login An unofficial way to authenticate your Replit users Authenticate Replit users in your projects without ReplAuth. This uses the actual Rep

Ray 8 Aug 11, 2022
Get a verse(an aya) from the Quran during your coding session 💻 , stay connected with the words of Allah. 🕋

Ayat ?? Get a verse(an aya) from the Quran during your coding session ?? stay connected with the words of Allah. ?? ?? Release Notes 1.0.0 Get random

Hussam Adil 27 Jan 2, 2023