Last active
November 17, 2022 17:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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