I want to Fetch data from firestore and append all the data in a new Google sheet.
Creating sheet is where i am finding problem.
as far as i have researched, i ve found out there are 3 methods to access google api,
1)API key
2)Service account
3)Oauth
Ignoring API key,
While using service account, i have found out that sheet which is getting created will be owned by service account so no one else can remove it.
when using Oauth, i have used OAuth json credential from GCP , in which when i try to use it in local host, it shows me Google's Logging screen, but when i deploy it in app engine, it doesnt redirect it to logging screen.
https://developers.google.com/sheets/api/quickstart/nodejs
this is the document where i find the approach.
One more method i have found i.e. Access token. i.e. putting access token in
const sheets = google.sheets({ version: "v4",headers:{ Authorization:`Bearer ${accessToken}` }});
but that wont be possible, as in Front end i am using
auth.onAuthStateChanged
which doesnt provide me Access token just the ID token.
Please help!
Based on your auth.onAuthStateChanged code it looks like you're using Firebase Authentication to sign in on the frontend.
Firebase Authentication is based around JWT ID tokens, which are not the same as OAuth tokens. You can't use such an ID token to make calls to the Google Sheets API.
If you're signing in with Google or another OAuth provider on the frontend, you can capture the OAuth token from that provider before you sign in to Firebase with it, and then use the OAuth token to call the Google Sheets API.
Related
I am trying to use Firebase Auth credentials to access FirebaseStorage bucket. I have been successful in using the REST API https://firebasestorage.googleapis.com/v0/b/BUCKET_NAME/o/ to perform uploads and downloads; even though the official documentation requires to use https://storage.googleapis.com/upload/storage/v1/b/BUCKET_NAME/o?uploadType=media&name=OBJECT_NAME for uploads and https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME?alt=media for downloads, I am unable to use Firebase Auth credentials for them.
I am trying to implement resumable uploads and initiating it using https://firebasestorage.googleapis.com/v0/b/BUCKET_NAME/o?uploadType=resumable&name=OBJECT_NAME but there is no SESSION-URI that is returned. I tried to create my own URI using the id from the X-GUploader-UploadID header to create the URI in the format https://firebasestorage.googleapis.com/v0/b/BUCKET_NAME/o?uploadType=resumable&name=OBJECT_NAME&upload_id=UPLOAD_ID to start a single chunk upload but I got a Not Found error.
I need help on either rectifying that or using Firebase Auth to access the https://storage.googleapis.com/upload/storage/v1/b/BUCKET_NAME REST API
I am trying to put pictures that are on Firebase into a google Drive by using google App script. I've no code, I only tried reading the documentation, but it seems to be deprecated. There seems to be a way to use an Oauth token but I could not find a token on my firebase database.
I go into a lot of detail about using OAuth2 and service accounts with Google Apps Script in this story on Medium.
I suppose you want to use Firebase storage? The approach should be similar:
Create a service account
Use the OAuth2 library to generate a Bearer token
Use that token with the API call via UrlFetchApp
It would help if you shared more details on what you're trying to achieve, but this should set you on the right track.
I need to send product details to Google shopping Content API but for using that i need to generate oAuth token with refresh token throgh Azure data factory.I have generated service account and client-secret json .How i will do it through function app?
Firstly, we need to understand that functions should not be used to do UI-related actions. In any app service the pop up for the login ( which allows to provide the credentials) will not be supported.
E.g. : To avoid this scenario , in case of AD auth we may use service principle where we feed the required credential to acquire the token. So if we want to use the google auth SDK we need to connect to the concerned team ( Google team) to understand if this is feasible at all.
For this you may check the Server-To-Server Service Account Authentication, as below:
https://cloud.google.com/docs/authentication/production
In case you need any assistance in this, we would recommend you to reach out to the concerned support team.
I am currently working on a simple web app that will make an GET call to a user's google fit data.
To reduce the complexity of the app, I plan to host it on firebase and take full advantage of cloud functions, firestore and the authentication tools.
So far, I have managed to read my google fit data using googleapis node library on the frontend by passing the fitness scope https://www.googleapis.com/auth/fitness.activity.read
as part of the google sign in button.
If I were to use firebase's google auth implementation, this would have a different client ID / different scopes than the credentials I made for reading the google fit data.
It seems if I want to use firebase AND google fit, the user would have to login using firebase's google auth so I can authenticate database writes to my app, and also grant me access to their google fit data from within the app.
If there a way this could be combined so I could use a single token to authenticate and read google fit data?
Looks like I just had to dig a bit deeper, you can add scopes to your google auth provider instance.
https://firebase.google.com/docs/auth/web/google-signin
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/fitness.activity.read');
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
})
Then to make the fitness reading, use the access token returned in the Authorization header
Authorization: `Bearer ${accessToken}`
axios.post('https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate?alt=json', data, axiosconfig)
Note: If you want to do background requests to a users data while they are not in the app (offline in oauth2 terms), you will need to use firebase in conjunction with gapis js library.
I have some user data stored in Firebase in users/userID/data
I'm using Dialogflow to recognize for example the following intent:
retrieve my email
which triggers a webhook and passes as parameter email, which is the data the user wants to retrieve. How to I pass the firebase userID? I guess I need to implement some kind of logging for the Google Assistant, but I cannot find how can I link the Firebase user account to google actions and how would I get this firebase userID
Is there a standard or recommend way to achieve this?
There is no pre-built solution for this right now.
You will need to implement Account Linking with the Google Assistant.It was done this way to give you, and your users, maximum flexibility. You'll be able to authenticate them using a variety of methods, not just Google Auth, and users are able to use a Google identity for you that may be different than the one they use for the Assistant. Account Linking will associate them without revealing to you which account they use on the Assistant.
This means creating an OAuth server that lets users log in using their Firebase account and issuing tokens to the Assistant. Google does provide some information about the procedure you should follow when creating your OAuth server, and you should be able to create this using Firebase Hosting and Firebase Cloud Functions.
Then, each time the Assistant calls your action, it will send the tokens back to you. You would use this token to determine the Firebase userid and then can look them up in the database.