2

I am trying to write the integration test cases One of the tests need to send X-auth firebase header

How to generate the Firebase auth token in Java?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Are you looking [this question](https://stackoverflow.com/questions/31042347/using-firebase-java-library-on-server-without-authentication-process)? Also please check [doc](https://firebase.google.com/docs/database/rest/auth). – Naresh Kumar Jan 02 '20 at 06:30

1 Answers1

2

You can use the Firebase Admin SDK for Java to generate a Firebase Authentication token.

In its simplest form, generating the token looks like this:

String uid = "some-uid";

String customToken = FirebaseAuth.getInstance().createCustomToken(uid);

You can also set specific claims in the token, with something like this:

String uid = "some-uid";
Map<String, Object> additionalClaims = new HashMap<String, Object>();
additionalClaims.put("premiumAccount", true);

String customToken = FirebaseAuth.getInstance()
    .createCustomToken(uid, additionalClaims);

Both examples come straight from the documentation I linked, so I highly recommend checking that out for more details.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807