Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
OAUTH2 and Apps Script
It's not that complicated
Authentication
and
Authorization
How to use Goa to simplify
OAuth2 user and service
account handling in Apps
Script.
devel...
In the developers console
1. Create the project
2. Select the APIS to use
3. See which scopes the APIS require using the A...
Developers
console How to set up an API project in
the Google Developers
consoleProject dashboard
…….
Developers console: 1. Create the project
Developers console: 2. Select the APIS to use
Developers console: 3. note scopes (API explorer)
Developers console: 4a. Get credentials (user)
(if using user Oauth2)
Developers console: 4b. Get credentials (service)
(if using Service account)
Apps Script How to set up Goa for OAuth2
and Service Accounts in the
Apps Script IDEThe Script IDE
In your script
1. Include the cGoa library (MZx5DzNPsYjVyZaR67xXJQai_d-phDA33)
2. Create a one off script to store credent...
Script IDE: 1. include cGoa library
MZx5DzNPsYjVyZaR67xXJQai_d-phDA33
Script IDE: 2a. create credentials script and run it
function oneOffScript() {
var options = {
packageName: 'goa-tutorial-...
function oneOffScript() {
var options = {
packageName: 'goa-tutorial-service',
fileId:'0B92xxxxxxjNDR28',
scopes : cGoa.Go...
function doGet(e) {
var goa = cGoa.GoaApp.createGoa ('goa-tutorial-user',
PropertiesService.getUserProperties()).execute (...
Script IDE: 3b. Copy redirect uri and origin to console
(if using user Oauth2)
Script IDE: 3c. Allow the consent process to complete
(if using user Oauth2)
function oneOffScript() {
….
}
function doGet() {
….
}
Script IDE: 4. delete one off script (and doGet)
scripts no longer ...
Apps Script How to consume Goa access
tokens in Apps Script projects
Using the token
Using Goa
1. Once Goa has been set up there is no need for any more interaction
2. Just fetch the access token and use it....
Using Goa: 1. Getting the token
var goa = cGoa.GoaApp.createGoa ('goa-tutorial-user',
PropertiesService.getUserProperties(...
Using Goa: 2. Using the token
var result = UrlFetchApp.fetch (apiUrl , {
header: {
authentication: 'Bearer ' + goa.getToke...
More Goa
The source code, examples
and additional features of Goa,
including how to set up for API
providers other than Go...
Upcoming SlideShare
Loading in …5
×

Goa tutorial

526 views

Published on

OAuth2 Goa library for Apps Script tutorial including how to use the Google Developer console dashboard. Handles Google and other providers as well as Service accounts.

Published in: Data & Analytics
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/fhx1X ◀ ◀ ◀ ◀
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Goa tutorial

  1. 1. OAUTH2 and Apps Script It's not that complicated
  2. 2. Authentication and Authorization How to use Goa to simplify OAuth2 user and service account handling in Apps Script. developers console script ide consuming tokens More information at Desktop Liberation Apps Script
  3. 3. In the developers console 1. Create the project 2. Select the APIS to use 3. See which scopes the APIS require using the API explorer 4. Get credentials a. Web client - take note of client ID and client secret b. Service Account - download the JSON data to Drive
  4. 4. Developers console How to set up an API project in the Google Developers consoleProject dashboard
  5. 5. ……. Developers console: 1. Create the project
  6. 6. Developers console: 2. Select the APIS to use
  7. 7. Developers console: 3. note scopes (API explorer)
  8. 8. Developers console: 4a. Get credentials (user) (if using user Oauth2)
  9. 9. Developers console: 4b. Get credentials (service) (if using Service account)
  10. 10. Apps Script How to set up Goa for OAuth2 and Service Accounts in the Apps Script IDEThe Script IDE
  11. 11. In your script 1. Include the cGoa library (MZx5DzNPsYjVyZaR67xXJQai_d-phDA33) 2. Create a one off script to store credentials and run it 3. If a user Oauth2 account (instead of a service account) a. Publish and run your App b. Copy the redirect URI to the developer console from the consent screen c. Allow the consent process to finish 4. Delete your one off script (or move it somewhere private)
  12. 12. Script IDE: 1. include cGoa library MZx5DzNPsYjVyZaR67xXJQai_d-phDA33
  13. 13. Script IDE: 2a. create credentials script and run it function oneOffScript() { var options = { packageName: 'goa-tutorial-user', clientId: 'xxx.apps.googleusercontent.com', clientSecret:'xxxx', scopes : cGoa.GoaApp.scopesGoogleExpand (['pubsub','cloud-platform']), service:'google' }; // store one off cGoa.GoaApp.setPackage (PropertiesService.getUserProperties(), options); } (if using user Oauth2)
  14. 14. function oneOffScript() { var options = { packageName: 'goa-tutorial-service', fileId:'0B92xxxxxxjNDR28', scopes : cGoa.GoaApp.scopesGoogleExpand (['pubsub','cloud-platform']), service:'google_service' }; cGoa.GoaApp.setPackage (PropertiesService.getScriptProperties(), cGoa.GoaApp.createServiceAccount (DriveApp , options)); } Script IDE: 2b. create credentials script and run it (if using Service account) the JSON key file id
  15. 15. function doGet(e) { var goa = cGoa.GoaApp.createGoa ('goa-tutorial-user', PropertiesService.getUserProperties()).execute (e); if (goa.needsConsent()) { return goa.getConsent(); } return HtmlService.createHtmlOutput (goa.hasToken() ? 'your token has been stored' : 'failed to get token') .setSandboxMode(HtmlService.SandboxMode.IFRAME); } Script IDE: 3a. Publish app and run it (if using user Oauth2)
  16. 16. Script IDE: 3b. Copy redirect uri and origin to console (if using user Oauth2)
  17. 17. Script IDE: 3c. Allow the consent process to complete (if using user Oauth2)
  18. 18. function oneOffScript() { …. } function doGet() { …. } Script IDE: 4. delete one off script (and doGet) scripts no longer needed
  19. 19. Apps Script How to consume Goa access tokens in Apps Script projects Using the token
  20. 20. Using Goa 1. Once Goa has been set up there is no need for any more interaction 2. Just fetch the access token and use it. It will be automatically refreshed
  21. 21. Using Goa: 1. Getting the token var goa = cGoa.GoaApp.createGoa ('goa-tutorial-user', PropertiesService.getUserProperties()).execute (); if (goa.hasToken()) { var token = goa.getToken(); } same for both service account and user OAuth2 Just change property store and credentials name
  22. 22. Using Goa: 2. Using the token var result = UrlFetchApp.fetch (apiUrl , { header: { authentication: 'Bearer ' + goa.getToken() } }); same for both service account and user OAuth2
  23. 23. More Goa The source code, examples and additional features of Goa, including how to set up for API providers other than Google can be found at Desktop Liberation Further capabilities

×