grahamearley / FirestoreGoogleAppsScript

A Google Apps Script library for accessing Google Cloud Firestore.
http://grahamearley.website/blog/2017/10/18/firestore-in-google-apps-script.html
MIT License
648 stars 109 forks source link

getting this Exception: Unexpected error while getting the method or property computeRsaSha256Signature on object Utilities. (line 39, file "Auth") #103

Closed vitata78 closed 4 years ago

vitata78 commented 4 years ago

Minimal code to reproduce the problem

const firestore = FirestoreApp.getFirestore(email, key, projectId);

Expected Behavior

Actual Results

on the const allDocuments = firestore.getDocuments("paragraphs"); step

Library Version:
LaughDonor commented 4 years ago

Is your code running in V8, or Rhino runtime?

vitata78 commented 4 years ago

the issue above appeared in V8.

when I switch back to Rhino - the error is the following:

Missing ; before statement. (line 12, file "Auth", project "FirestoreApp")

LaughDonor commented 4 years ago

I wasn't able to reproduce the issue, did you follow the format of the key properly? The README templates this out appropriately.

vitata78 commented 4 years ago

here is the code I use (Rhino ver)

getFirestore() func works well, no errors. when tried to remove few chars from the key - got another error saying the key is invalid, so the key works and accepted.

the service account is Cloud Database Owner

Please advise..

image

vitata78 commented 4 years ago

I wasn't able to reproduce the issue, did you follow the format of the key properly? The README templates this out appropriately.

OK, sorry for this - figured out - the key was formatted not properly - you were right! everything works well now!

john-osullivan commented 1 year ago

Hey @vitata78 , what was your key formatting issue? I'm running into a similar problem -- albeit, not while using Firestore -- and can't figure out what's wrong with my key. I got this error instead of the invalid key one and assumed the key was set up, but it sounds like it might still not be?

Edit: Ye who find this thread, as of this posting time, the correct key format for Utilities. computeRsaSha256Signature() is to remove all newlines and whitespace from the private keyPKCS#8 format.

By default, the PEM format will have:

-----BEGIN RSA KEY-----
line 1 of 64 chars
line 2 of 64 chars
....
line 25 of 64 chars
line 26 of 24 chars
-----END RSA KEY-----

The newlines, and potentially whitespaces, between each line of the private key need to be removed in order to make GAS happy:

-----BEGIN RSA KEY-----
line 1 of 64 charsline 2 of 64 chars....line 25 of 64 charsline 26 of 24 chars
-----END RSA KEY-----