Hi,
I try to connect to the firebase REST API : https://firebase.google.com/docs/database/rest/auth
so I need a google oauth2 access tokens. Google provide 3 sets of client library, JAVA, NODE.JS and PYTHON
of course no coldfusion.
I found this project : https://github.com/timmaybrown/firebase-cfml
but it stand : “The token can be your secret, but is less secure than generating a JWT that expires or based on a $uid with a library like the awesome cf-simple-jwt”
of course the awesome library cf-jwt-simple is far to be as simple as the NODE.JS version of the library …: https://github.com/jsteinshouer/cf-jwt-simple
Anyone managed to get an access token from a google service account with a json file ? a really need an example …
Thanks for your help
Stéphane
PS : the solution with the node.js lib is straightforward :
var google = require("googleapis");
// Load the service account key JSON file.
var serviceAccount = require("./myjsonfile.json");
// Define the required scopes.
var scopes = [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database"
];
// Authenticate a JWT client with the service account.
var jwtClient = new google.auth.JWT(
serviceAccount.client_email,
null,
serviceAccount.private_key,
scopes
);
// Use the JWT client to generate an access token.
jwtClient.authorize(function(error, tokens) {
if (error) {
console.log("Error making request to generate access token:", error);
} else if (tokens.access_token === null) {
console.log("Provided service account does not have permission to generate access tokens");
} else {
var accessToken = tokens.access_token;
console.log("Access tokens "+ accessToken);
// See the "Using the access token" section below for information
// on how to use the access token to send authenticated requests to
// the Realtime Database REST API.
}
});