Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit 4d3866d

Browse files
authored
Add auth bulk get/delete snippets (#8)
1 parent 38884a1 commit 4d3866d

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ build/
88
*.ear
99
*.aar
1010
*.iml
11+
12+
.project
13+
.classpath
14+
.settings

admin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ repositories {
1515

1616
dependencies {
1717
// Firebase Admin Java SDK
18-
compile 'com.google.firebase:firebase-admin:6.12.2'
18+
compile 'com.google.firebase:firebase-admin:6.13.0'
1919
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2020 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.firebase.example;
17+
18+
import com.google.firebase.auth.DeleteUsersResult;
19+
import com.google.firebase.auth.EmailIdentifier;
20+
import com.google.firebase.auth.ErrorInfo;
21+
import com.google.firebase.auth.FirebaseAuth;
22+
import com.google.firebase.auth.GetUsersResult;
23+
import com.google.firebase.auth.PhoneIdentifier;
24+
import com.google.firebase.auth.ProviderIdentifier;
25+
import com.google.firebase.auth.UidIdentifier;
26+
import com.google.firebase.auth.UserIdentifier;
27+
import com.google.firebase.auth.UserRecord;
28+
import java.util.Arrays;
29+
30+
public class FirebaseAuthSnippets {
31+
32+
public static void bulkGetUsers() throws Exception {
33+
// [START bulk_get_users]
34+
GetUsersResult result = FirebaseAuth.getInstance().getUsersAsync(Arrays.asList(
35+
new UidIdentifier("uid1"),
36+
new EmailIdentifier("[email protected]"),
37+
new PhoneIdentifier("+15555550003"),
38+
new ProviderIdentifier("google.com", "google_uid4"))).get();
39+
40+
System.out.println("Successfully fetched user data:");
41+
for (UserRecord user : result.getUsers()) {
42+
System.out.println(user.getUid());
43+
}
44+
45+
System.out.println("Unable to find users corresponding to these identifiers:");
46+
for (UserIdentifier uid : result.getNotFound()) {
47+
System.out.println(uid);
48+
}
49+
// [END bulk_get_users]
50+
}
51+
52+
public static void bulkDeleteUsers() throws Exception {
53+
// [START bulk_delete_users]
54+
DeleteUsersResult result = FirebaseAuth.getInstance().deleteUsersAsync(
55+
Arrays.asList("uid1", "uid2", "uid3")).get();
56+
57+
System.out.println("Successfully deleted " + result.getSuccessCount() + " users");
58+
System.out.println("Failed to delete " + result.getFailureCount() + " users");
59+
for (ErrorInfo error : result.getErrors()) {
60+
System.out.println("error #" + error.getIndex() + ", reason: " + error.getReason());
61+
}
62+
// [END bulk_delete_users]
63+
}
64+
}

0 commit comments

Comments
 (0)