Google Service Account Sheets Demo
https://stackoverflow.com/questions/53965446/how-to-sign-a-jwt-with-a-private-key-pem-in-cryptojs
Side Load JSRSAssign to sign JWT tokens to be able to login into Google Sheets API
GETSide Load JSRSASign
Load the JS RSA Sign library
We can do this by calling a CDN of the library.
Then save it to an environment and calling eval
on it in the next script we want to use it in.
POSTGoogle Get Token
Here we just pass in the required information about the service account and scopes we want to touch. Then sign the payload and send it over for an access token.
//iss: email address of service account //scope A space-delimited list of the permissions that the application requests. //aud A descriptor of the intended target of the assertion. When making an access token request this value is always https://oauth2.googleapis.com/token. //exp The expiration time of the assertion, specified as seconds since 00:00:00 UTC, January 1, 1970. This value has a maximum of 1 hour after the issued time. //iat The time the assertion was issued, specified as seconds since 00:00:00 UTC, January 1, 1970.
https://developers.google.com/identity/protocols/OAuth2ServiceAccount#makingrequest
https://gist.github.com/dinvlad/425a072c8d23c1895e9d345b67909af0
POSTUpdate Sheet
Now we can just pass in the token as if we got it from a consent screen in the Auth tab!
Happy hacking!