Skip to content

Commit 9052434

Browse files
committed
Add operation to list OIDC provider configs. (#404)
This adds an operation to list OIDC provider configs (can be done using either the tenant-aware or standard Firebase client). This work is part of adding multi-tenancy support (see issue #332).
1 parent f728f63 commit 9052434

12 files changed

+707
-36
lines changed

src/main/java/com/google/firebase/auth/AbstractFirebaseAuth.java

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
import com.google.firebase.FirebaseApp;
3030
import com.google.firebase.auth.FirebaseUserManager.EmailLinkType;
3131
import com.google.firebase.auth.FirebaseUserManager.UserImportRequest;
32+
import com.google.firebase.auth.ListProviderConfigsPage;
33+
import com.google.firebase.auth.ListProviderConfigsPage.DefaultOidcProviderConfigSource;
34+
import com.google.firebase.auth.ListUsersPage;
3235
import com.google.firebase.auth.ListUsersPage.DefaultUserSource;
33-
import com.google.firebase.auth.ListUsersPage.PageFactory;
3436
import com.google.firebase.auth.UserRecord;
3537
import com.google.firebase.auth.internal.FirebaseTokenFactory;
3638
import com.google.firebase.internal.CallableOperation;
@@ -503,8 +505,8 @@ private CallableOperation<ListUsersPage, FirebaseAuthException> listUsersOp(
503505
@Nullable final String pageToken, final int maxResults) {
504506
checkNotDestroyed();
505507
final FirebaseUserManager userManager = getUserManager();
506-
final PageFactory factory =
507-
new PageFactory(new DefaultUserSource(userManager, jsonFactory), maxResults, pageToken);
508+
final DefaultUserSource source = new DefaultUserSource(userManager, jsonFactory);
509+
final ListUsersPage.Factory factory = new ListUsersPage.Factory(source, maxResults, pageToken);
508510
return new CallableOperation<ListUsersPage, FirebaseAuthException>() {
509511
@Override
510512
protected ListUsersPage execute() throws FirebaseAuthException {
@@ -1170,6 +1172,7 @@ public OidcProviderConfig getOidcProviderConfig(@NonNull String providerId)
11701172

11711173
/**
11721174
* Similar to {@link #getOidcProviderConfig(String)} but performs the operation asynchronously.
1175+
* Page size will be limited to 100 provider configs.
11731176
*
11741177
* @param providerId A provider ID string.
11751178
* @return An {@code ApiFuture} which will complete successfully with an
@@ -1195,6 +1198,78 @@ protected OidcProviderConfig execute() throws FirebaseAuthException {
11951198
};
11961199
}
11971200

1201+
/**
1202+
* Gets a page of OIDC Auth provider configs starting from the specified {@code pageToken}.
1203+
*
1204+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1205+
* configs.
1206+
* @param maxResults Maximum number of provider configs to include in the returned page. This may
1207+
* not exceed 100.
1208+
* @return A {@link ListProviderConfigsPage} instance.
1209+
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
1210+
* invalid.
1211+
* @throws FirebaseAuthException If an error occurs while retrieving user data.
1212+
*/
1213+
public ListProviderConfigsPage<OidcProviderConfig> listOidcProviderConfigs(
1214+
@Nullable String pageToken, int maxResults) throws FirebaseAuthException {
1215+
return listOidcProviderConfigsOp(pageToken, maxResults).call();
1216+
}
1217+
1218+
/**
1219+
* Similar to {@link #listlistOidcProviderConfigs(String)} but performs the operation
1220+
* asynchronously. Page size will be limited to 100 provider configs.
1221+
*
1222+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1223+
* configs.
1224+
* @return An {@code ApiFuture} which will complete successfully with a
1225+
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
1226+
* config data, the future throws an exception.
1227+
* @throws IllegalArgumentException If the specified page token is empty.
1228+
*/
1229+
public ApiFuture<ListProviderConfigsPage<OidcProviderConfig>> listOidcProviderConfigsAsync(
1230+
@Nullable String pageToken) {
1231+
return listOidcProviderConfigsAsync(
1232+
pageToken,
1233+
FirebaseUserManager.MAX_LIST_PROVIDER_CONFIGS_RESULTS);
1234+
}
1235+
1236+
/**
1237+
* Similar to {@link #listOidcProviderConfigs(String, int)} but performs the operation
1238+
* asynchronously.
1239+
*
1240+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1241+
* configs.
1242+
* @param maxResults Maximum number of provider configs to include in the returned page. This may
1243+
* not exceed 100.
1244+
* @return An {@code ApiFuture} which will complete successfully with a
1245+
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
1246+
* config data, the future throws an exception.
1247+
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
1248+
* invalid.
1249+
*/
1250+
public ApiFuture<ListProviderConfigsPage<OidcProviderConfig>> listOidcProviderConfigsAsync(
1251+
@Nullable String pageToken,
1252+
int maxResults) {
1253+
return listOidcProviderConfigsOp(pageToken, maxResults).callAsync(firebaseApp);
1254+
}
1255+
1256+
private CallableOperation<ListProviderConfigsPage<OidcProviderConfig>, FirebaseAuthException>
1257+
listOidcProviderConfigsOp(@Nullable final String pageToken, final int maxResults) {
1258+
checkNotDestroyed();
1259+
final FirebaseUserManager userManager = getUserManager();
1260+
final DefaultOidcProviderConfigSource source = new DefaultOidcProviderConfigSource(userManager);
1261+
final ListProviderConfigsPage.Factory<OidcProviderConfig> factory =
1262+
new ListProviderConfigsPage.Factory<OidcProviderConfig>(source, maxResults, pageToken);
1263+
return
1264+
new CallableOperation<ListProviderConfigsPage<OidcProviderConfig>, FirebaseAuthException>() {
1265+
@Override
1266+
protected ListProviderConfigsPage<OidcProviderConfig> execute()
1267+
throws FirebaseAuthException {
1268+
return factory.create();
1269+
}
1270+
};
1271+
}
1272+
11981273
/**
11991274
* Deletes the provider config identified by the specified provider ID.
12001275
*

src/main/java/com/google/firebase/auth/FirebaseUserManager.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.google.firebase.auth.internal.GetAccountInfoRequest;
4545
import com.google.firebase.auth.internal.GetAccountInfoResponse;
4646
import com.google.firebase.auth.internal.HttpErrorResponse;
47+
import com.google.firebase.auth.internal.ListOidcProviderConfigsResponse;
4748
import com.google.firebase.auth.internal.ListTenantsResponse;
4849
import com.google.firebase.auth.internal.UploadAccountResponse;
4950
import com.google.firebase.internal.ApiClientUtils;
@@ -98,6 +99,7 @@ class FirebaseUserManager {
9899
.put("INVALID_DYNAMIC_LINK_DOMAIN", "invalid-dynamic-link-domain")
99100
.build();
100101

102+
static final int MAX_LIST_PROVIDER_CONFIGS_RESULTS = 100;
101103
static final int MAX_LIST_TENANTS_RESULTS = 1000;
102104
static final int MAX_GET_ACCOUNTS_BATCH_SIZE = 100;
103105
static final int MAX_DELETE_ACCOUNTS_BATCH_SIZE = 1000;
@@ -388,6 +390,26 @@ OidcProviderConfig getOidcProviderConfig(String providerId) throws FirebaseAuthE
388390
return sendRequest("GET", url, null, OidcProviderConfig.class);
389391
}
390392

393+
ListOidcProviderConfigsResponse listOidcProviderConfigs(int maxResults, String pageToken)
394+
throws FirebaseAuthException {
395+
ImmutableMap.Builder<String, Object> builder =
396+
ImmutableMap.<String, Object>builder().put("pageSize", maxResults);
397+
if (pageToken != null) {
398+
checkArgument(!pageToken.equals(
399+
ListTenantsPage.END_OF_LIST), "invalid end of list page token");
400+
builder.put("nextPageToken", pageToken);
401+
}
402+
403+
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + "/oauthIdpConfigs");
404+
url.putAll(builder.build());
405+
ListOidcProviderConfigsResponse response =
406+
sendRequest("GET", url, null, ListOidcProviderConfigsResponse.class);
407+
if (response == null) {
408+
throw new FirebaseAuthException(INTERNAL_ERROR, "Failed to retrieve provider configs.");
409+
}
410+
return response;
411+
}
412+
391413
void deleteProviderConfig(String providerId) throws FirebaseAuthException {
392414
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + getOidcUrlSuffix(providerId));
393415
sendRequest("DELETE", url, null, GenericJson.class);

0 commit comments

Comments
 (0)