How to integrate Firebase into Google Apps Script without using (deprecated) database secret
up vote
2
down vote
favorite
For a while ago I was using integration of Firebase in Google Apps Script as a server side and it was working finely and still working in my old projects.
But today after creating a new Firebase project and a new realtime database then trying to integrate Firebase Project into my Google Script project I got an error and it's not working completely. And I realize that Firebase deprecated database secret for new projects.
So, my question now is how to come over this problem? Is there another way to integrate Firebase into Google Script project?
add a comment |
up vote
2
down vote
favorite
For a while ago I was using integration of Firebase in Google Apps Script as a server side and it was working finely and still working in my old projects.
But today after creating a new Firebase project and a new realtime database then trying to integrate Firebase Project into my Google Script project I got an error and it's not working completely. And I realize that Firebase deprecated database secret for new projects.
So, my question now is how to come over this problem? Is there another way to integrate Firebase into Google Script project?
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
For a while ago I was using integration of Firebase in Google Apps Script as a server side and it was working finely and still working in my old projects.
But today after creating a new Firebase project and a new realtime database then trying to integrate Firebase Project into my Google Script project I got an error and it's not working completely. And I realize that Firebase deprecated database secret for new projects.
So, my question now is how to come over this problem? Is there another way to integrate Firebase into Google Script project?
For a while ago I was using integration of Firebase in Google Apps Script as a server side and it was working finely and still working in my old projects.
But today after creating a new Firebase project and a new realtime database then trying to integrate Firebase Project into my Google Script project I got an error and it's not working completely. And I realize that Firebase deprecated database secret for new projects.
So, my question now is how to come over this problem? Is there another way to integrate Firebase into Google Script project?
edited Nov 8 at 14:23
Frank van Puffelen
218k25361386
218k25361386
asked Nov 8 at 12:38
Muhammad Saleh
30529
30529
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You'll need to add the correct OAuth scopes to the manifest file of your Apps Script project, and then pass in an access_token parameter (or in the Authorization header) instead of the auth parameter you currently use.
Based on Doug's gist here, the basic steps are:
- Open the
manifest.jsonfrom the script editor, by clicking View > Show manifest file. Add or edit the manifest to have these OAuth scopes:
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets"
]That last scope grants it access to the spreadsheet itself. If you're using another GSuite type (document, slides, form, etc) you'll need the scope that corresponds that to type.
Now you can get the OAuth token from within your script and add it to your request:
var response = UrlFetchApp.fetch(databaseUrl,
method: "PUT",
headers:
"Content-type": "application/json",
"Authorization": "Bearer "+ScriptApp.getOAuthToken()
,
payload: JSON.stringify(json)
);
Logger.log(response.getContentText());
A major advantage of this is that your script will now run as an actual user, meaning that you can ensure it can only perform authorized actions through security rules.
Thank You Frank!. I really appreciate your help.
– Muhammad Saleh
Nov 9 at 8:23
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You'll need to add the correct OAuth scopes to the manifest file of your Apps Script project, and then pass in an access_token parameter (or in the Authorization header) instead of the auth parameter you currently use.
Based on Doug's gist here, the basic steps are:
- Open the
manifest.jsonfrom the script editor, by clicking View > Show manifest file. Add or edit the manifest to have these OAuth scopes:
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets"
]That last scope grants it access to the spreadsheet itself. If you're using another GSuite type (document, slides, form, etc) you'll need the scope that corresponds that to type.
Now you can get the OAuth token from within your script and add it to your request:
var response = UrlFetchApp.fetch(databaseUrl,
method: "PUT",
headers:
"Content-type": "application/json",
"Authorization": "Bearer "+ScriptApp.getOAuthToken()
,
payload: JSON.stringify(json)
);
Logger.log(response.getContentText());
A major advantage of this is that your script will now run as an actual user, meaning that you can ensure it can only perform authorized actions through security rules.
Thank You Frank!. I really appreciate your help.
– Muhammad Saleh
Nov 9 at 8:23
add a comment |
up vote
1
down vote
accepted
You'll need to add the correct OAuth scopes to the manifest file of your Apps Script project, and then pass in an access_token parameter (or in the Authorization header) instead of the auth parameter you currently use.
Based on Doug's gist here, the basic steps are:
- Open the
manifest.jsonfrom the script editor, by clicking View > Show manifest file. Add or edit the manifest to have these OAuth scopes:
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets"
]That last scope grants it access to the spreadsheet itself. If you're using another GSuite type (document, slides, form, etc) you'll need the scope that corresponds that to type.
Now you can get the OAuth token from within your script and add it to your request:
var response = UrlFetchApp.fetch(databaseUrl,
method: "PUT",
headers:
"Content-type": "application/json",
"Authorization": "Bearer "+ScriptApp.getOAuthToken()
,
payload: JSON.stringify(json)
);
Logger.log(response.getContentText());
A major advantage of this is that your script will now run as an actual user, meaning that you can ensure it can only perform authorized actions through security rules.
Thank You Frank!. I really appreciate your help.
– Muhammad Saleh
Nov 9 at 8:23
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You'll need to add the correct OAuth scopes to the manifest file of your Apps Script project, and then pass in an access_token parameter (or in the Authorization header) instead of the auth parameter you currently use.
Based on Doug's gist here, the basic steps are:
- Open the
manifest.jsonfrom the script editor, by clicking View > Show manifest file. Add or edit the manifest to have these OAuth scopes:
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets"
]That last scope grants it access to the spreadsheet itself. If you're using another GSuite type (document, slides, form, etc) you'll need the scope that corresponds that to type.
Now you can get the OAuth token from within your script and add it to your request:
var response = UrlFetchApp.fetch(databaseUrl,
method: "PUT",
headers:
"Content-type": "application/json",
"Authorization": "Bearer "+ScriptApp.getOAuthToken()
,
payload: JSON.stringify(json)
);
Logger.log(response.getContentText());
A major advantage of this is that your script will now run as an actual user, meaning that you can ensure it can only perform authorized actions through security rules.
You'll need to add the correct OAuth scopes to the manifest file of your Apps Script project, and then pass in an access_token parameter (or in the Authorization header) instead of the auth parameter you currently use.
Based on Doug's gist here, the basic steps are:
- Open the
manifest.jsonfrom the script editor, by clicking View > Show manifest file. Add or edit the manifest to have these OAuth scopes:
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets"
]That last scope grants it access to the spreadsheet itself. If you're using another GSuite type (document, slides, form, etc) you'll need the scope that corresponds that to type.
Now you can get the OAuth token from within your script and add it to your request:
var response = UrlFetchApp.fetch(databaseUrl,
method: "PUT",
headers:
"Content-type": "application/json",
"Authorization": "Bearer "+ScriptApp.getOAuthToken()
,
payload: JSON.stringify(json)
);
Logger.log(response.getContentText());
A major advantage of this is that your script will now run as an actual user, meaning that you can ensure it can only perform authorized actions through security rules.
edited Nov 8 at 19:21
answered Nov 8 at 16:15
Frank van Puffelen
218k25361386
218k25361386
Thank You Frank!. I really appreciate your help.
– Muhammad Saleh
Nov 9 at 8:23
add a comment |
Thank You Frank!. I really appreciate your help.
– Muhammad Saleh
Nov 9 at 8:23
Thank You Frank!. I really appreciate your help.
– Muhammad Saleh
Nov 9 at 8:23
Thank You Frank!. I really appreciate your help.
– Muhammad Saleh
Nov 9 at 8:23
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53207906%2fhow-to-integrate-firebase-into-google-apps-script-without-using-deprecated-dat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown