Google Authentication with Google Spread Sheet via App Script

孤街醉人 提交于 2019-12-08 09:37:27

问题


In FireBase Console I had set the below rule in the database :

and below is the Script Editor of Google Spread sheet :

Since any one can write into data base, there is no permission required and till here am able to write into database.

Now I want only one user able write into database, so I changed the rule to :

{
  "rules": {
    ".read": true,
    ".write": "'User_UID_xyz' === auth.uid"
  }
}

And I logged-in to account with user id 'User_UID_xyz', and running the same script in Google Spreed Sheet. But I am getting the permission denied issue. So, Do I need to make the user authenticate here?? But it is already logged-in to the account which is authenticated by FireBase.

///////////////////////////////
////////////////////////////
Also, I had gone through the link :
https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/tutorials/using-secured-client-authentication-for-real-time-read-and-write-calls But I got confuse. Why should I used Web App here??


回答1:


All server side calls to the database are considered "admin" and can read and write to any location in the database. Your example code is missing the firebase secret when connecting to the database. It should look like:

FirebaseApp.getDatabaseByUrl(firebaseURL, secret);

You can find the secret in the database tab of the project settings.

As for that article, It is specifically written about Apps Script web apps. The other article describes server side calls, though it was pre-google IO and the interface has changed, the API calls remane the same.

https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/tutorials/read-and-write-data-in-firebase-from-apps-script



来源:https://stackoverflow.com/questions/38949432/google-authentication-with-google-spread-sheet-via-app-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!