Created
June 14, 2022 10:38
-
-
Save TopekoX/a9a5bd7823e2ef9f05cec43f1ddc2351 to your computer and use it in GitHub Desktop.
Google Firebase Account Service generate Token Server with Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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