Skip to content

Commit c396d6a

Browse files
authored
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 ee98321 commit c396d6a

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;
@@ -500,8 +502,8 @@ private CallableOperation<ListUsersPage, FirebaseAuthException> listUsersOp(
500502
@Nullable final String pageToken, final int maxResults) {
501503
checkNotDestroyed();
502504
final FirebaseUserManager userManager = getUserManager();
503-
final PageFactory factory =
504-
new PageFactory(new DefaultUserSource(userManager, jsonFactory), maxResults, pageToken);
505+
final DefaultUserSource source = new DefaultUserSource(userManager, jsonFactory);
506+
final ListUsersPage.Factory factory = new ListUsersPage.Factory(source, maxResults, pageToken);
505507
return new CallableOperation<ListUsersPage, FirebaseAuthException>() {
506508
@Override
507509
protected ListUsersPage execute() throws FirebaseAuthException {
@@ -1033,6 +1035,7 @@ public OidcProviderConfig getOidcProviderConfig(@NonNull String providerId)
10331035

10341036
/**
10351037
* Similar to {@link #getOidcProviderConfig(String)} but performs the operation asynchronously.
1038+
* Page size will be limited to 100 provider configs.
10361039
*
10371040
* @param providerId A provider ID string.
10381041
* @return An {@code ApiFuture} which will complete successfully with an
@@ -1058,6 +1061,78 @@ protected OidcProviderConfig execute() throws FirebaseAuthException {
10581061
};
10591062
}
10601063

1064+
/**
1065+
* Gets a page of OIDC Auth provider configs starting from the specified {@code pageToken}.
1066+
*
1067+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1068+
* configs.
1069+
* @param maxResults Maximum number of provider configs to include in the returned page. This may
1070+
* not exceed 100.
1071+
* @return A {@link ListProviderConfigsPage} instance.
1072+
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
1073+
* invalid.
1074+
* @throws FirebaseAuthException If an error occurs while retrieving user data.
1075+
*/
1076+
public ListProviderConfigsPage<OidcProviderConfig> listOidcProviderConfigs(
1077+
@Nullable String pageToken, int maxResults) throws FirebaseAuthException {
1078+
return listOidcProviderConfigsOp(pageToken, maxResults).call();
1079+
}
1080+
1081+
/**
1082+
* Similar to {@link #listlistOidcProviderConfigs(String)} but performs the operation
1083+
* asynchronously. Page size will be limited to 100 provider configs.
1084+
*
1085+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1086+
* configs.
1087+
* @return An {@code ApiFuture} which will complete successfully with a
1088+
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
1089+
* config data, the future throws an exception.
1090+
* @throws IllegalArgumentException If the specified page token is empty.
1091+
*/
1092+
public ApiFuture<ListProviderConfigsPage<OidcProviderConfig>> listOidcProviderConfigsAsync(
1093+
@Nullable String pageToken) {
1094+
return listOidcProviderConfigsAsync(
1095+
pageToken,
1096+
FirebaseUserManager.MAX_LIST_PROVIDER_CONFIGS_RESULTS);
1097+
}
1098+
1099+
/**
1100+
* Similar to {@link #listOidcProviderConfigs(String, int)} but performs the operation
1101+
* asynchronously.
1102+
*
1103+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1104+
* configs.
1105+
* @param maxResults Maximum number of provider configs to include in the returned page. This may
1106+
* not exceed 100.
1107+
* @return An {@code ApiFuture} which will complete successfully with a
1108+
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
1109+
* config data, the future throws an exception.
1110+
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
1111+
* invalid.
1112+
*/
1113+
public ApiFuture<ListProviderConfigsPage<OidcProviderConfig>> listOidcProviderConfigsAsync(
1114+
@Nullable String pageToken,
1115+
int maxResults) {
1116+
return listOidcProviderConfigsOp(pageToken, maxResults).callAsync(firebaseApp);
1117+
}
1118+
1119+
private CallableOperation<ListProviderConfigsPage<OidcProviderConfig>, FirebaseAuthException>
1120+
listOidcProviderConfigsOp(@Nullable final String pageToken, final int maxResults) {
1121+
checkNotDestroyed();
1122+
final FirebaseUserManager userManager = getUserManager();
1123+
final DefaultOidcProviderConfigSource source = new DefaultOidcProviderConfigSource(userManager);
1124+
final ListProviderConfigsPage.Factory<OidcProviderConfig> factory =
1125+
new ListProviderConfigsPage.Factory<OidcProviderConfig>(source, maxResults, pageToken);
1126+
return
1127+
new CallableOperation<ListProviderConfigsPage<OidcProviderConfig>, FirebaseAuthException>() {
1128+
@Override
1129+
protected ListProviderConfigsPage<OidcProviderConfig> execute()
1130+
throws FirebaseAuthException {
1131+
return factory.create();
1132+
}
1133+
};
1134+
}
1135+
10611136
/**
10621137
* Deletes the provider config identified by the specified provider ID.
10631138
*

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.google.firebase.auth.internal.DownloadAccountResponse;
4444
import com.google.firebase.auth.internal.GetAccountInfoResponse;
4545
import com.google.firebase.auth.internal.HttpErrorResponse;
46+
import com.google.firebase.auth.internal.ListOidcProviderConfigsResponse;
4647
import com.google.firebase.auth.internal.ListTenantsResponse;
4748
import com.google.firebase.auth.internal.UploadAccountResponse;
4849
import com.google.firebase.internal.ApiClientUtils;
@@ -94,6 +95,7 @@ class FirebaseUserManager {
9495
.put("INVALID_DYNAMIC_LINK_DOMAIN", "invalid-dynamic-link-domain")
9596
.build();
9697

98+
static final int MAX_LIST_PROVIDER_CONFIGS_RESULTS = 100;
9799
static final int MAX_LIST_TENANTS_RESULTS = 1000;
98100
static final int MAX_LIST_USERS_RESULTS = 1000;
99101
static final int MAX_IMPORT_USERS = 1000;
@@ -338,6 +340,26 @@ OidcProviderConfig getOidcProviderConfig(String providerId) throws FirebaseAuthE
338340
return sendRequest("GET", url, null, OidcProviderConfig.class);
339341
}
340342

343+
ListOidcProviderConfigsResponse listOidcProviderConfigs(int maxResults, String pageToken)
344+
throws FirebaseAuthException {
345+
ImmutableMap.Builder<String, Object> builder =
346+
ImmutableMap.<String, Object>builder().put("pageSize", maxResults);
347+
if (pageToken != null) {
348+
checkArgument(!pageToken.equals(
349+
ListTenantsPage.END_OF_LIST), "invalid end of list page token");
350+
builder.put("nextPageToken", pageToken);
351+
}
352+
353+
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + "/oauthIdpConfigs");
354+
url.putAll(builder.build());
355+
ListOidcProviderConfigsResponse response =
356+
sendRequest("GET", url, null, ListOidcProviderConfigsResponse.class);
357+
if (response == null) {
358+
throw new FirebaseAuthException(INTERNAL_ERROR, "Failed to retrieve provider configs.");
359+
}
360+
return response;
361+
}
362+
341363
void deleteProviderConfig(String providerId) throws FirebaseAuthException {
342364
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + getOidcUrlSuffix(providerId));
343365
sendRequest("DELETE", url, null, GenericJson.class);

0 commit comments

Comments
 (0)