Twilio Serverless Functions to demonstrate Tri-Legged Oauth callbacks/webhooks to Box and Google Sheets
Important: Twilio Functions are limited to ~20 executions / second, so this is purely for demonstration and/or relatively light use cases
This uses the Twilio CLI with the Twilio Serverless Plugin
-
Clone this repo
-
Setup Provider Profiles
- Setup Google OAuth 2 Profile and Sheets Access (see below)
- Setup Box in a similar but much easier way (see below))
-
Create .env file in root and provide keys for the following: SYNC_NAME="" BOX_CLIENT_ID="" BOX_CLIENT_SECRET="" GOOGLE_CLIENT_ID="" GOOGLE_CLIENT_SECRET=""
-
Update access.js in assets folder with Box and Google Client IDs (see Google instructions below) Note: You can ignore Box if you only care about Google
- Or, you can add your own Provider by glancing through the code and modifying
-
Update Provider object data
- If using Google, update the Spreadhseet ID in callback_google.js (could move this to ENV as well.)
- If using Box, update the File ID (its the # in the URL of any given Box document)
-
Deploy the Serverless Function using Twilio CLI
twilio serverless:deploy
Following initial deploy, if you want to overwrite an existing project
twilio serverless:deploy --override-existing-project
-
Once deployed, visit your Twilio Functions
-
Copy to URL to the index.html and paste into a fresh browser tab. You should see the Oauth Buttons
- Click on either
- If configured correctly (e.g. all the URLs and IDs were update from above steps), you should be redirected and and Authorize
- Google will throw a non-verified App error for development projects. You'll have to by pass this and accept.
- Once you complete Auth, you will be returned to Twilio and a page showing the temporate Auth Code should display
-
You should now be able to update a Phone Number Webhook by pointing to the appropriate Callback Function (callback_box or callback_google)
-
Alternatively, you can run this locally for testing. See Developing with the Serverless Toolkit
(Google changes their IAM console regularly, so keeping this relatively generic)
1. Visit Google IAM and create an OAuth 2.0 Client ID [Google IAM](https://console.developers.google.com/apis/credentials)
2. Provide a redirect URI * (Example: https://serverless-oauth-callback-8527-dev.twil.io/redirect_google) *
- You can get this URL the Twilio Function Editor [Twilio Functions](https://www.twilio.com/console/functions/overview/services)
3. Copy the Client ID from this page (and add it to *.env and access.js)
4. Copy the Client Secret from this page (and add it to *.env)
5. *Important* You have to enable the Google Sheets API [Google Library](https://console.developers.google.com/apis/library?project=twilio-8cf4c)
1. Visit [Box Developer Console](https://quickstark.app.box.com/developers/console)
2. Create a "New App"
3. Choose "Custom App"
4. Select "User Authentication (OAuth 2.0)" on the Authentication Method modal
5. Copy the Client ID (and add it to *.env and access.js)
6. Copy the Client Secret (and add it toe *.env)
7. Provide a valid Redirect URI * (Example: https://serverless-oauth-callback-8527-dev.twil.io/callback_box) *
8. Check the box to provide "Write all files and folders stored in Box"
9. Save your changes