Skip to content

Commit 68edeb3

Browse files
committed
Add operation to list OIDC provider configs.
1 parent ee98321 commit 68edeb3

12 files changed

+705
-36
lines changed

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

Lines changed: 77 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.DefaultOidcProviderConfigSource;
33+
import com.google.firebase.auth.ListProviderConfigsPage.ProviderConfigPageFactory;
3234
import com.google.firebase.auth.ListUsersPage.DefaultUserSource;
33-
import com.google.firebase.auth.ListUsersPage.PageFactory;
35+
import com.google.firebase.auth.ListUsersPage.UserPageFactory;
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 UserPageFactory factory = new UserPageFactory(source, maxResults, pageToken);
505507
return new CallableOperation<ListUsersPage, FirebaseAuthException>() {
506508
@Override
507509
protected ListUsersPage execute() throws FirebaseAuthException {
@@ -1058,6 +1060,78 @@ protected OidcProviderConfig execute() throws FirebaseAuthException {
10581060
};
10591061
}
10601062

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

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)