Skip to content

Instantly share code, notes, and snippets.

@tyagiakhilesh
Last active November 17, 2022 17:08
Show Gist options
  • Save tyagiakhilesh/e9f84412bb2505ccf962d7022955755e to your computer and use it in GitHub Desktop.
Save tyagiakhilesh/e9f84412bb2505ccf962d7022955755e to your computer and use it in GitHub Desktop.
Get User details of FirebaseUser with an UID also contain example of getting custom token
public void testTopicSubscribeUnSubscribe() {
try (final InputStream inputStream = CloudDatabase.class.getClassLoader().getResourceAsStream(<service acc file>)) {
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(inputStream))
.setServiceAccountId("<service account email id>")
.build();
FirebaseApp.initializeApp(options);
final UserRecord userRecord = FirebaseAuth.getInstance().getUser("1cf4b276125bf7743124a2");
final String phoneNumber = userRecord.getEmail().replace("@nobrokerhood.abcd", "");
String uid = "some-uid";
String customToken = FirebaseAuth.getInstance().createCustomToken(uid);
System.out.println("customToken is : " + customToken);
System.out.println("Phone number is : " + phoneNumber);
System.out.println(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(userRecord));
} catch (Exception e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment