SignInWithCustomToken () with native Firebase tokens

I want to authenticate users on multiple websites using a JWT token. The token was originally created by firebase, so I assume it is a good and valid token (tested on jwt.io and seems to be in order). I get it from user.getToken().

As I call signInWithCustomToken(token), I always get an error message auth/invalid-custom-tokenwith a message "The custom token format is incorrect. Please check the documentation.".

Oddly enough, it does an HTTP POST request for https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken..., which returns HTTP 400. I tried both on the local host and on the https live website ... but the same result. I am using Firebase 3.3.

Any ideas what could be wrong? I used this function with old Firebase.

+4
source share
1 answer

You do not provide code snippets, so I will reflect here.

I assume that you are using node.js to create a custom token. Try this in a node script:

var firebase = require("firebase");
var adminConfig = {
    serviceAccount: "serviceAccountCredentials.json"
};
var adminApp = firebase.initializeApp(adminConfig, 'admin');
var token = adminApp.auth().createCustomToken('12345678', {
    customField: 'customValue'
});

Then, on the client, try signing the InWithCustomToken (token). Make sure that the client uses the same api key that belongs to the same project in which the service account was created.

+1
source

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


All Articles