Skip to content

Google Apps Script implementation of Salesforce Oauth using JSON Web Token.

License

Notifications You must be signed in to change notification settings

Fazatholomew/Salesforce-GAS-JWT

Repository files navigation

Welcome to Salesforce-GAS-JWT 👋

Version License: Apache--2.0

TypeScript

Google Apps Script implementation of Salesforce Oauth using JSON Web Token.

Install

  • (Option 1) Create New Google Apps Script Project

git clone https://github.com/Fazatholomew/Salesforce-GAS-JWT.git
cd Salesforce-GAS-JWT
npm i @google/clasp -g
clasp login
clasp create --title "Salesforce JWT Authentication"
  • (Option 2) Integrate with existing project

Copy the content of src/ folder and paste it in your project. Import the function from src/index.ts just like the example in Code.ts file.

Usage

  1. Get Connected App in Salesforce and Generate Public and Private Keys by following this tutorial.

  2. Push your code into Google Apps Script Project

clasp push
  1. Generate Private Key that GAS Supports
openssl pkcs8 -topk8 -inform pem -in private.pem -outform pem -nocrypt -out newPrivate.pem
  1. Turn the generated private key into single line string Open the newPrivate.pem with text editor. Remove all new line character. Except the one after BEGIN PRIVATE KEY and before END PRIVATE KEY. For example:

Before:

-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASC
AmAwggJcAgEAAoGBALQXzM8zKoBAJbDo
mtQsi36RmQUwRpka7r5Sejwi1BQu3bhB
DKiQnvdkFt2789iQqeGvGoUgS3ifhrqp
nB+IBoczB3V4F4eIademGvdruktmpqt5
ixJUROScfLfBhsQfMyM5htgCaCyeGUTQ
Dk7Xedd0KTN1C5bB1YsBDB0JTD5AgMBA
AECgYAvp7Sch4oPIvpffsssfdyDM+Q==
-----END PRIVATE KEY-----

After:

"-----BEGIN PRIVATE KEY-----\nMIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALQXzM8zKoBAJbDomtQsi36RmQUwRpka7r5Sejwi1BQu3bhBDKiQnvdkFt2789iQqeGvGoUgS3ifhrqp
nB+IBoczB3V4F4eIademGvdruktmpqt5ixJUROScfLfBhsQfMyM5htgCaCyeGUTQDk7Xedd0KTN1C5bB1YsBDB0JTD5AgMBA\nAECgYAvp7Sch4oPIvpffsssfdyDM+Q==-----END PRIVATE KEY-----"
  1. Save necessary credentials in Property Service in Google Apps Script As of May 29, 2021, in order to pre populate the Property Service and store our environment variables is by clicking Use Legacy Editor > File > Project Properties > Script Properties.
Property Value
aud login.salesforce.com
iss Client ID or Consumer Key from Connected App
key Private Key from previous step

Author

👤 Jimmy Hikmatullah


This README was generated with ❤️ by readme-md-generator

About

Google Apps Script implementation of Salesforce Oauth using JSON Web Token.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published