Skip to content

Add operation to list OIDC provider configs. #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 78 additions & 3 deletions src/main/java/com/google/firebase/auth/AbstractFirebaseAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.FirebaseUserManager.EmailLinkType;
import com.google.firebase.auth.FirebaseUserManager.UserImportRequest;
import com.google.firebase.auth.ListProviderConfigsPage;
import com.google.firebase.auth.ListProviderConfigsPage.DefaultOidcProviderConfigSource;
import com.google.firebase.auth.ListUsersPage;
import com.google.firebase.auth.ListUsersPage.DefaultUserSource;
import com.google.firebase.auth.ListUsersPage.PageFactory;
import com.google.firebase.auth.UserRecord;
import com.google.firebase.auth.internal.FirebaseTokenFactory;
import com.google.firebase.internal.CallableOperation;
Expand Down Expand Up @@ -500,8 +502,8 @@ private CallableOperation<ListUsersPage, FirebaseAuthException> listUsersOp(
@Nullable final String pageToken, final int maxResults) {
checkNotDestroyed();
final FirebaseUserManager userManager = getUserManager();
final PageFactory factory =
new PageFactory(new DefaultUserSource(userManager, jsonFactory), maxResults, pageToken);
final DefaultUserSource source = new DefaultUserSource(userManager, jsonFactory);
final ListUsersPage.Factory factory = new ListUsersPage.Factory(source, maxResults, pageToken);
return new CallableOperation<ListUsersPage, FirebaseAuthException>() {
@Override
protected ListUsersPage execute() throws FirebaseAuthException {
Expand Down Expand Up @@ -1033,6 +1035,7 @@ public OidcProviderConfig getOidcProviderConfig(@NonNull String providerId)

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

/**
* Gets a page of OIDC Auth provider configs starting from the specified {@code pageToken}.
*
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
* configs.
* @param maxResults Maximum number of provider configs to include in the returned page. This may
* not exceed 100.
* @return A {@link ListProviderConfigsPage} instance.
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
* invalid.
* @throws FirebaseAuthException If an error occurs while retrieving user data.
*/
public ListProviderConfigsPage<OidcProviderConfig> listOidcProviderConfigs(
@Nullable String pageToken, int maxResults) throws FirebaseAuthException {
return listOidcProviderConfigsOp(pageToken, maxResults).call();
}

/**
* Similar to {@link #listlistOidcProviderConfigs(String)} but performs the operation
* asynchronously. Page size will be limited to 100 provider configs.
*
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
* configs.
* @return An {@code ApiFuture} which will complete successfully with a
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
* config data, the future throws an exception.
* @throws IllegalArgumentException If the specified page token is empty.
*/
public ApiFuture<ListProviderConfigsPage<OidcProviderConfig>> listOidcProviderConfigsAsync(
@Nullable String pageToken) {
return listOidcProviderConfigsAsync(
pageToken,
FirebaseUserManager.MAX_LIST_PROVIDER_CONFIGS_RESULTS);
}

/**
* Similar to {@link #listOidcProviderConfigs(String, int)} but performs the operation
* asynchronously.
*
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
* configs.
* @param maxResults Maximum number of provider configs to include in the returned page. This may
* not exceed 100.
* @return An {@code ApiFuture} which will complete successfully with a
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
* config data, the future throws an exception.
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
* invalid.
*/
public ApiFuture<ListProviderConfigsPage<OidcProviderConfig>> listOidcProviderConfigsAsync(
@Nullable String pageToken,
int maxResults) {
return listOidcProviderConfigsOp(pageToken, maxResults).callAsync(firebaseApp);
}

private CallableOperation<ListProviderConfigsPage<OidcProviderConfig>, FirebaseAuthException>
listOidcProviderConfigsOp(@Nullable final String pageToken, final int maxResults) {
checkNotDestroyed();
final FirebaseUserManager userManager = getUserManager();
final DefaultOidcProviderConfigSource source = new DefaultOidcProviderConfigSource(userManager);
final ListProviderConfigsPage.Factory<OidcProviderConfig> factory =
new ListProviderConfigsPage.Factory<OidcProviderConfig>(source, maxResults, pageToken);
return
new CallableOperation<ListProviderConfigsPage<OidcProviderConfig>, FirebaseAuthException>() {
@Override
protected ListProviderConfigsPage<OidcProviderConfig> execute()
throws FirebaseAuthException {
return factory.create();
}
};
}

/**
* Deletes the provider config identified by the specified provider ID.
*
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/google/firebase/auth/FirebaseUserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.google.firebase.auth.internal.DownloadAccountResponse;
import com.google.firebase.auth.internal.GetAccountInfoResponse;
import com.google.firebase.auth.internal.HttpErrorResponse;
import com.google.firebase.auth.internal.ListOidcProviderConfigsResponse;
import com.google.firebase.auth.internal.ListTenantsResponse;
import com.google.firebase.auth.internal.UploadAccountResponse;
import com.google.firebase.internal.ApiClientUtils;
Expand Down Expand Up @@ -94,6 +95,7 @@ class FirebaseUserManager {
.put("INVALID_DYNAMIC_LINK_DOMAIN", "invalid-dynamic-link-domain")
.build();

static final int MAX_LIST_PROVIDER_CONFIGS_RESULTS = 100;
static final int MAX_LIST_TENANTS_RESULTS = 1000;
static final int MAX_LIST_USERS_RESULTS = 1000;
static final int MAX_IMPORT_USERS = 1000;
Expand Down Expand Up @@ -338,6 +340,26 @@ OidcProviderConfig getOidcProviderConfig(String providerId) throws FirebaseAuthE
return sendRequest("GET", url, null, OidcProviderConfig.class);
}

ListOidcProviderConfigsResponse listOidcProviderConfigs(int maxResults, String pageToken)
throws FirebaseAuthException {
ImmutableMap.Builder<String, Object> builder =
ImmutableMap.<String, Object>builder().put("pageSize", maxResults);
if (pageToken != null) {
checkArgument(!pageToken.equals(
ListTenantsPage.END_OF_LIST), "invalid end of list page token");
builder.put("nextPageToken", pageToken);
}

GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + "/oauthIdpConfigs");
url.putAll(builder.build());
ListOidcProviderConfigsResponse response =
sendRequest("GET", url, null, ListOidcProviderConfigsResponse.class);
if (response == null) {
throw new FirebaseAuthException(INTERNAL_ERROR, "Failed to retrieve provider configs.");
}
return response;
}

void deleteProviderConfig(String providerId) throws FirebaseAuthException {
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + getOidcUrlSuffix(providerId));
sendRequest("DELETE", url, null, GenericJson.class);
Expand Down
Loading