Firebase REST auth when creating a token with node.js admin sdk

I know that this problem has been asked a lot here, but I still cannot find the exact answer that can solve my problem.

I want to access Firebase using REST calls by adding the access_token parameter.

Access_token is created using the Node.js Admin SDK using the following code:

var admin = require("firebase-admin");

var serviceAccount = require("./pk.json");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://XXX.firebaseio.com"
});

var uid = "1234";


admin.auth().createCustomToken(uid)
  .then(function(customToken) {
    // Send token back to client
    console.log("Token: "+customToken);
  })
  .catch(function(error) {
    console.log("Error creating custom token:", error);
  });

The problem is that if I take the token created from Node.js and use it with my REST call, I get an error Unauthorized request.

In some questions, I read that people added an area parameter when issuing a token, but did not find a way to do this using the Node.js Admin SDK.

Google Docs aren’t as detailed with this issue. Any idea what I can try to solve this?

+4
1

, REST API Firebase, . Firebase Auth, SDK- Firebase signInWithCustomToken(), .

API REST Firebase : Firebase ID ( ) Google OAuth2 ( ).

ID Firebase

. , SDK- Firebase. Firebase ID REST API:

: https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=<API_KEY>

: POST

{ "token": <CUSTOM_TOKEN>, "returnSecureToken": true }

<API_KEY> - API, Firebase Console, Firebase. <CUSTOM_TOKEN> - Firebase.

, , REST API:

: https://securetoken.googleapis.com/v1/token?key=<API_KEY>

: POST

: { "refresh_token": <REFRESH_TOKEN>, "grant_type": "refresh_token" }

<API_KEY> - API, . <REFRESH_TOKEN> - API.

, REST API auth . Firebase, , , .

Google Access

Google OAuth2, , , . . , . Java, , Node.js. , , REST API access_token . , Firebase .

+5

Source: https://habr.com/ru/post/1672820/


All Articles