Skip to content

Instantly share code, notes, and snippets.

@TopekoX
Created June 14, 2022 10:38
Show Gist options
  • Save TopekoX/a9a5bd7823e2ef9f05cec43f1ddc2351 to your computer and use it in GitHub Desktop.
Save TopekoX/a9a5bd7823e2ef9f05cec43f1ddc2351 to your computer and use it in GitHub Desktop.
Google Firebase Account Service generate Token Server with Node.js
var { google } = require('googleapis')
var SCOPES = ["https://www.googleapis.com/auth/firebase.messaging"]
var http = require('http')
function getAccessToken() {
return new Promise(function (resolve, reject) {
const key = require('./service-account.json');
const jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
null
);
jwtClient.authorize(function (err, tokens) {
if (err) {
reject(err);
return;
}
resolve(tokens.access_token);
});
});
}
getAccessToken().then(function(access_token){
console.log(access_token)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment