Skip to content

feat: Added new error codes for IdP management and multitenancy #458

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 3 commits into from
Jul 30, 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
13 changes: 13 additions & 0 deletions src/main/java/com/google/firebase/auth/AuthErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public enum AuthErrorCode {
*/
CERTIFICATE_FETCH_FAILED,

/**
* No IdP configuration found for the given identifier.
*/
CONFIGURATION_NOT_FOUND,

/**
* A user already exists with the provided email.
*/
Expand Down Expand Up @@ -71,8 +76,16 @@ public enum AuthErrorCode {
*/
REVOKED_SESSION_COOKIE,

/**
* Tenant ID in the JWT does not match.
*/
TENANT_ID_MISMATCH,

/**
* No tenant found for the given identifier.
*/
TENANT_NOT_FOUND,

/**
* A user already exists with the provided UID.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ final class AuthErrorHandler extends AbstractHttpErrorHandler<FirebaseAuthExcept

private static final Map<String, AuthError> ERROR_CODES =
ImmutableMap.<String, AuthError>builder()
.put(
"CONFIGURATION_NOT_FOUND",
new AuthError(
ErrorCode.NOT_FOUND,
"No IdP configuration found corresponding to the provided identifier",
AuthErrorCode.CONFIGURATION_NOT_FOUND))
.put(
"DUPLICATE_EMAIL",
new AuthError(
Expand Down Expand Up @@ -67,6 +73,12 @@ final class AuthErrorHandler extends AbstractHttpErrorHandler<FirebaseAuthExcept
ErrorCode.ALREADY_EXISTS,
"The user with the provided phone number already exists",
AuthErrorCode.PHONE_NUMBER_ALREADY_EXISTS))
.put(
"TENANT_NOT_FOUND",
new AuthError(
ErrorCode.NOT_FOUND,
"No tenant found for the given identifier",
AuthErrorCode.TENANT_NOT_FOUND))
.put(
"UNAUTHORIZED_DOMAIN",
new AuthError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public final class AuthHttpClient {

private static final String CLIENT_VERSION = "Java/Admin/" + SdkUtils.getVersion();

private final JsonFactory jsonFactory;
private final ErrorHandlingHttpClient<FirebaseAuthException> httpClient;
private final JsonFactory jsonFactory;

private HttpResponseInterceptor interceptor;

public AuthHttpClient(JsonFactory jsonFactory, HttpRequestFactory requestFactory) {
this.jsonFactory = jsonFactory;
AuthErrorHandler authErrorHandler = new AuthErrorHandler(jsonFactory);
this.httpClient = new ErrorHandlingHttpClient<>(requestFactory, jsonFactory, authErrorHandler);
this.jsonFactory = jsonFactory;
}

public static Set<String> generateMask(Map<String, Object> properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ final class FirebaseTenantClient {
private final AuthHttpClient httpClient;

FirebaseTenantClient(FirebaseApp app) {
checkNotNull(app, "FirebaseApp must not be null");
String projectId = ImplFirebaseTrampolines.getProjectId(app);
this(
ImplFirebaseTrampolines.getProjectId(checkNotNull(app)),
app.getOptions().getJsonFactory(),
ApiClientUtils.newAuthorizedRequestFactory(app));
}

FirebaseTenantClient(
String projectId, JsonFactory jsonFactory, HttpRequestFactory requestFactory) {
checkArgument(!Strings.isNullOrEmpty(projectId),
"Project ID is required to access the auth service. Use a service account credential or "
+ "set the project ID explicitly via FirebaseOptions. Alternatively you can also "
+ "set the project ID via the GOOGLE_CLOUD_PROJECT environment variable.");
this.tenantMgtBaseUrl = String.format(ID_TOOLKIT_URL, "v2", projectId);
JsonFactory jsonFactory = app.getOptions().getJsonFactory();
HttpRequestFactory requestFactory = ApiClientUtils.newAuthorizedRequestFactory(app);
this.httpClient = new AuthHttpClient(jsonFactory, requestFactory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public final class TenantManager {
* @hide
*/
public TenantManager(FirebaseApp firebaseApp) {
this.firebaseApp = firebaseApp;
this.tenantClient = new FirebaseTenantClient(firebaseApp);
this(firebaseApp, new FirebaseTenantClient(firebaseApp));
}

@VisibleForTesting
TenantManager(FirebaseApp firebaseApp, FirebaseTenantClient tenantClient) {
this.firebaseApp = checkNotNull(firebaseApp);
this.tenantClient = checkNotNull(tenantClient);
this.tenantAwareAuths = new HashMap<>();
}

Expand Down
Loading