Hello guys, I have been trying to fetch data from firebase realtime database with my azure function (cloud script) and I managed to get that, if database has public read/write rules. But I want to limit access only after authentication. So, I decided to go with OAuth2 authentication.
I have created service account key file on firebase but, I have no idea how to use that in Azure function since firebase documentation don't provide C# sample for that. (https://firebase.google.com/docs/database/rest/auth#google_oauth2_access_tokens)
My Current code is:
HttpRequestMessage httpRequestMessage = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri(FIREBASE_URL), Headers = { { HttpRequestHeader.Accept.ToString(), "application/json;odata=nometadata" }, { HttpRequestHeader.Authorization.ToString(), "Bearer ???" } } }; HttpClient requestClient = new HttpClient(); HttpResponseMessage response = await requestClient.SendAsync(httpRequestMessage); string rawData = await response.Content.ReadAsStringAsync();
This code runs without authentication, though.
But, I need to generate access token from my service account key file. Can anyone guide me how can I generate the token?
Thanks,