Google Apps Script implementation of Salesforce Oauth using JSON Web Token.
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"
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.
-
Get Connected App in Salesforce and Generate Public and Private Keys by following this tutorial.
-
Push your code into Google Apps Script Project
clasp push
- Generate Private Key that GAS Supports
openssl pkcs8 -topk8 -inform pem -in private.pem -outform pem -nocrypt -out newPrivate.pem
- 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:
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASC
AmAwggJcAgEAAoGBALQXzM8zKoBAJbDo
mtQsi36RmQUwRpka7r5Sejwi1BQu3bhB
DKiQnvdkFt2789iQqeGvGoUgS3ifhrqp
nB+IBoczB3V4F4eIademGvdruktmpqt5
ixJUROScfLfBhsQfMyM5htgCaCyeGUTQ
Dk7Xedd0KTN1C5bB1YsBDB0JTD5AgMBA
AECgYAvp7Sch4oPIvpffsssfdyDM+Q==
-----END PRIVATE KEY-----
"-----BEGIN PRIVATE KEY-----\nMIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALQXzM8zKoBAJbDomtQsi36RmQUwRpka7r5Sejwi1BQu3bhBDKiQnvdkFt2789iQqeGvGoUgS3ifhrqp
nB+IBoczB3V4F4eIademGvdruktmpqt5ixJUROScfLfBhsQfMyM5htgCaCyeGUTQDk7Xedd0KTN1C5bB1YsBDB0JTD5AgMBA\nAECgYAvp7Sch4oPIvpffsssfdyDM+Q==-----END PRIVATE KEY-----"
- 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 |
👤 Jimmy Hikmatullah
- Website: https://jimmyganteng.com
- Github: @FazaTholomew
- LinkedIn: @faza-jimmy-hikmatullah-48bb54152
This README was generated with ❤️ by readme-md-generator