2018年6月22日 星期五

The concept of using Google api using javascript.

There are 2 stand ways to call the google-apis,


  1. Use oauth client
  2. Use oauth server-to server applications


Concept.
For 1. The oauth flows are pretty standard for any oauth2 applications.
First you ask permission to the user that granted you to access the calendar.
Then there is a access_token and a refresh_token.
So that you can access user’s calendar via that access_token.

For 2. This is under the G-suite admin authority to manipulating G-suite users data
using a delegated account.
Create a service account and let that account has access to the data you want to manipulate.



The flow charts are
For 1.
Get token using oauth2  => Initialize an google-apis client with token and scopes =>
Use client to send the api

For 2.
Create Service Account Client in the google console =>
Create Security in G-suite app using G-suite admin account =>
JWT can make request to access G-suite users


There are 3  approach ways.


  1. Using googleapis in could-functions in node.js.


Implementation details.


For 2.

  1. To create a service account as a delegate.
  2. Use the credential to authorize the JWTclient.
  3. Add that service account to the calendar you want to manipulate.
  4. Manipulate calendar using AWT like google apis.


Reference of creating google calendar, setup gcp project.