I am building a Google Docs add-on.
I specifically need to access Firebase resources (eg. Firestore) as the user that is logged in to Google Docs and hence I need to have a Firebase ID token to access Firebase and not with "admin" access to Firebase using a service account, which most Firebase docs refer to when describing using a Google OAuth token directly.
In the add-on JS code I do this to get the current users OAuth token:
var authToken = ScriptApp.getOAuthToken();
console.log("Auth TOK:"+authToken);
as described in the docs for the sample code from Google. This seems to work and gives me something that looks like a valid token.
I then try to exchange that for a Firebase ID token, for now I'm just trying this using curl:
curl 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]' \
-H 'Content-Type: application/json' \
--data-binary '{"postBody":"id_token=[GOOGLE_ID_TOKEN]&providerId=[google.com]","requestUri":"[http://localhost]","returnIdpCredential":true,"returnSecureToken":true}'
the above is taken from the Firebase REST API documentation.
Its also basically the same as what is mentioned in another answer here and here.
BUT unfortunately it doesn't seem to work and I get an error response back:
{
"error": {
"code": 400,
"message": "INVALID_IDP_RESPONSE : Invalid Idp Response: access_token audience is not for this project",
"errors": [
{
"message": "INVALID_IDP_RESPONSE : Invalid Idp Response: access_token audience is not for this project",
"domain": "global",
"reason": "invalid"
}
]
}
}
And in my Firebase project I have Google set as one of my sign-in providers.
As far as I know I have used the required scopes in my App Script appscript.json:
{
"timeZone": "America/New_York",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": ["profile", "email", "openid","https://www.googleapis.com/auth/firebase" ,"https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/datastore", "https://www.googleapis.com/auth/documents.currentonly", "https://www.googleapis.com/auth/script.container.ui"],
"runtimeVersion": "V8"
}
Would anyone have any idea of what I'm missing here? I guess there is something needed to tell Firebase to allow using Google OAuth tokens with my Firebase project?