Skip to content

Commit 0d3f2d6

Browse files
authored
feat: Added new error codes for IdP management and multitenancy (#458)
* feat: Added new error codes for IdP management and multitenancy * fix: Updated integration tests * fix: Renamed helper method
1 parent bd737b5 commit 0d3f2d6

File tree

9 files changed

+261
-136
lines changed

9 files changed

+261
-136
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public enum AuthErrorCode {
2626
*/
2727
CERTIFICATE_FETCH_FAILED,
2828

29+
/**
30+
* No IdP configuration found for the given identifier.
31+
*/
32+
CONFIGURATION_NOT_FOUND,
33+
2934
/**
3035
* A user already exists with the provided email.
3136
*/
@@ -71,8 +76,16 @@ public enum AuthErrorCode {
7176
*/
7277
REVOKED_SESSION_COOKIE,
7378

79+
/**
80+
* Tenant ID in the JWT does not match.
81+
*/
7482
TENANT_ID_MISMATCH,
7583

84+
/**
85+
* No tenant found for the given identifier.
86+
*/
87+
TENANT_NOT_FOUND,
88+
7689
/**
7790
* A user already exists with the provided UID.
7891
*/

src/main/java/com/google/firebase/auth/internal/AuthErrorHandler.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ final class AuthErrorHandler extends AbstractHttpErrorHandler<FirebaseAuthExcept
3636

3737
private static final Map<String, AuthError> ERROR_CODES =
3838
ImmutableMap.<String, AuthError>builder()
39+
.put(
40+
"CONFIGURATION_NOT_FOUND",
41+
new AuthError(
42+
ErrorCode.NOT_FOUND,
43+
"No IdP configuration found corresponding to the provided identifier",
44+
AuthErrorCode.CONFIGURATION_NOT_FOUND))
3945
.put(
4046
"DUPLICATE_EMAIL",
4147
new AuthError(
@@ -67,6 +73,12 @@ final class AuthErrorHandler extends AbstractHttpErrorHandler<FirebaseAuthExcept
6773
ErrorCode.ALREADY_EXISTS,
6874
"The user with the provided phone number already exists",
6975
AuthErrorCode.PHONE_NUMBER_ALREADY_EXISTS))
76+
.put(
77+
"TENANT_NOT_FOUND",
78+
new AuthError(
79+
ErrorCode.NOT_FOUND,
80+
"No tenant found for the given identifier",
81+
AuthErrorCode.TENANT_NOT_FOUND))
7082
.put(
7183
"UNAUTHORIZED_DOMAIN",
7284
new AuthError(

src/main/java/com/google/firebase/auth/internal/AuthHttpClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ public final class AuthHttpClient {
4040
private static final String CLIENT_VERSION = "Java/Admin/" + SdkUtils.getVersion();
4141

4242
private final ErrorHandlingHttpClient<FirebaseAuthException> httpClient;
43+
private final JsonFactory jsonFactory;
4344

4445
public AuthHttpClient(JsonFactory jsonFactory, HttpRequestFactory requestFactory) {
4546
AuthErrorHandler authErrorHandler = new AuthErrorHandler(jsonFactory);
4647
this.httpClient = new ErrorHandlingHttpClient<>(requestFactory, jsonFactory, authErrorHandler);
48+
this.jsonFactory = jsonFactory;
4749
}
4850

4951
public static Set<String> generateMask(Map<String, Object> properties) {

src/main/java/com/google/firebase/auth/multitenancy/FirebaseTenantClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ final class FirebaseTenantClient {
4646
private final AuthHttpClient httpClient;
4747

4848
FirebaseTenantClient(FirebaseApp app) {
49-
checkNotNull(app, "FirebaseApp must not be null");
50-
String projectId = ImplFirebaseTrampolines.getProjectId(app);
49+
this(
50+
ImplFirebaseTrampolines.getProjectId(checkNotNull(app)),
51+
app.getOptions().getJsonFactory(),
52+
ApiClientUtils.newAuthorizedRequestFactory(app));
53+
}
54+
55+
FirebaseTenantClient(
56+
String projectId, JsonFactory jsonFactory, HttpRequestFactory requestFactory) {
5157
checkArgument(!Strings.isNullOrEmpty(projectId),
5258
"Project ID is required to access the auth service. Use a service account credential or "
5359
+ "set the project ID explicitly via FirebaseOptions. Alternatively you can also "
5460
+ "set the project ID via the GOOGLE_CLOUD_PROJECT environment variable.");
5561
this.tenantMgtBaseUrl = String.format(ID_TOOLKIT_URL, "v2", projectId);
56-
JsonFactory jsonFactory = app.getOptions().getJsonFactory();
57-
HttpRequestFactory requestFactory = ApiClientUtils.newAuthorizedRequestFactory(app);
5862
this.httpClient = new AuthHttpClient(jsonFactory, requestFactory);
5963
}
6064

src/main/java/com/google/firebase/auth/multitenancy/TenantManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ public final class TenantManager {
5454
* @hide
5555
*/
5656
public TenantManager(FirebaseApp firebaseApp) {
57-
this.firebaseApp = firebaseApp;
58-
this.tenantClient = new FirebaseTenantClient(firebaseApp);
57+
this(firebaseApp, new FirebaseTenantClient(firebaseApp));
58+
}
59+
60+
@VisibleForTesting
61+
TenantManager(FirebaseApp firebaseApp, FirebaseTenantClient tenantClient) {
62+
this.firebaseApp = checkNotNull(firebaseApp);
63+
this.tenantClient = checkNotNull(tenantClient);
5964
this.tenantAwareAuths = new HashMap<>();
6065
}
6166

0 commit comments

Comments
 (0)