1.0.6 • Published 4 years ago
firebase-idtoken-getter v1.0.6
Firebase idToken getter
Overview
This is the library to get the idToken from Firebase Authorization which you'd already set. If you want to get idToken of Firebase Authorization in Node.js project, you can get it easily.

Caution
I think you should keep idToken in secret. Because someone can access private information, if someone without you get your idToken. This library should be used in internal process like CI/CD.
How to use
Sample code
// initial setting
const FirebaseTokenGetter = require("firebase-idtoken-getter");
let FirebaseTokenGetterObject = new FirebaseTokenGetter(
"<-- JSON File for GOOGLE_APPLICATION_CREDENTIALS -->",
"<-- User ID of Firebase Authorization -->",
"<-- API key of Firebase -->",
"<-- Project ID of Firebase Autorization -->"
);
// execute to get idToken
let getIdtoken = async () => {
let token = await FirebaseTokenGetterObject.createIdTokenBycustomToken();
console.log(token);
}
getIdtoken();Function
(1) FirebaseTokenGetter.constractor
The function must be called at first.
Argument
The function need 4 argument.
- credentialJson : It is for JSON File for
GOOGLE_APPLICATION_CREDENTIALS. The file is a service account JSON file of GCP. - firebaseUserId : It is User ID of Firebase Authorization. It is equivalent to User UID of in the page.
- apikey : It is Firebase's API key. You can see it here
- projectId : It is Firebase's project id. You can see it here
Process
Both Firebase Admin SDK intialization and Firebase SDK initialization are processed in this function.
- At First,
Firebase Admin SDK intializationis processed by using a service account JSON file. - Second,
Firebase SDK initializationis processed by using both API key and Project ID of Firebase.
(2) createIdTokenBycustomToken()
You can get idToken by calling this function.
Argument
Nothing.
Process
3 functions of firebase are processed in "createIdTokenBycustomToken()".
- At First,
admin.auth().createCustomTokenis processed. Firebase custom token is created by the function. - Second,
firebase.auth().signInWithCustomTokenis processed. Firebase SDK is signined by the custom token. - Last,
firebase.auth().currentUser.getIdToken(true).then((idToken)is processed. User's idToken is generated.
Licence
Firebase idToken Getter Copyright (c) 2020 Lichtwork.com MIT License