Skip to content
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
40 changes: 39 additions & 1 deletion src/main/java/com/google/firebase/auth/AbstractFirebaseAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.common.base.Preconditions.checkState;

import com.google.api.client.json.JsonFactory;
import com.google.api.client.util.Clock;
import com.google.api.core.ApiFuture;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -64,7 +65,7 @@ public abstract class AbstractFirebaseAuth {
private final Supplier<? extends FirebaseUserManager> userManager;
private final JsonFactory jsonFactory;

AbstractFirebaseAuth(Builder builder) {
protected AbstractFirebaseAuth(Builder builder) {
this.firebaseApp = checkNotNull(builder.firebaseApp);
this.tokenFactory = threadSafeMemoize(builder.tokenFactory);
this.idTokenVerifier = threadSafeMemoize(builder.idTokenVerifier);
Expand All @@ -73,6 +74,43 @@ public abstract class AbstractFirebaseAuth {
this.jsonFactory = builder.firebaseApp.getOptions().getJsonFactory();
}

protected static Builder builderFromAppAndTenantId(final FirebaseApp app, final String tenantId) {
return AbstractFirebaseAuth.builder()
.setFirebaseApp(app)
.setTokenFactory(
new Supplier<FirebaseTokenFactory>() {
@Override
public FirebaseTokenFactory get() {
return FirebaseTokenUtils.createTokenFactory(app, Clock.SYSTEM, tenantId);
}
})
.setIdTokenVerifier(
new Supplier<FirebaseTokenVerifier>() {
@Override
public FirebaseTokenVerifier get() {
return FirebaseTokenUtils.createIdTokenVerifier(app, Clock.SYSTEM, tenantId);
}
})
.setCookieVerifier(
new Supplier<FirebaseTokenVerifier>() {
@Override
public FirebaseTokenVerifier get() {
return FirebaseTokenUtils.createSessionCookieVerifier(app, Clock.SYSTEM);
}
})
.setUserManager(
new Supplier<FirebaseUserManager>() {
@Override
public FirebaseUserManager get() {
return FirebaseUserManager
.builder()
.setFirebaseApp(app)
.setTenantId(tenantId)
.build();
}
});
}

/**
* Creates a Firebase custom token for the given UID. This token can then be sent back to a client
* application to be used with the <a
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/com/google/firebase/auth/FirebaseAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import com.google.firebase.FirebaseApp;
import com.google.firebase.ImplFirebaseTrampolines;
import com.google.firebase.auth.internal.FirebaseTokenFactory;
import com.google.firebase.auth.multitenancy.TenantManager;
import com.google.firebase.internal.CallableOperation;
import com.google.firebase.internal.FirebaseService;
import com.google.firebase.internal.NonNull;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* This class is the entry point for all server-side Firebase Authentication actions.
Expand All @@ -45,15 +45,13 @@ public final class FirebaseAuth extends AbstractFirebaseAuth {
private static final String SERVICE_ID = FirebaseAuth.class.getName();

private final Supplier<TenantManager> tenantManager;
private final AtomicBoolean tenantManagerCreated = new AtomicBoolean(false);

FirebaseAuth(final Builder builder) {
super(builder);
tenantManager = threadSafeMemoize(new Supplier<TenantManager>() {
@Override
public TenantManager get() {
tenantManagerCreated.set(true);
return new TenantManager(builder.firebaseApp, getUserManager());
return new TenantManager(builder.firebaseApp);
}
});
}
Expand Down Expand Up @@ -213,12 +211,7 @@ FirebaseTokenVerifier getSessionCookieVerifier(boolean checkRevoked) {
}

@Override
protected void doDestroy() {
// Only destroy the tenant manager if it has been created.
if (tenantManagerCreated.get()) {
getTenantManager().destroy();
}
}
protected void doDestroy() { }
Comment thread
micahstairs marked this conversation as resolved.

private static FirebaseAuth fromApp(final FirebaseApp app) {
return new FirebaseAuth(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ final class FirebaseTokenVerifierImpl implements FirebaseTokenVerifier {
"https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit";
private static final String ERROR_INVALID_CREDENTIAL = "ERROR_INVALID_CREDENTIAL";
private static final String ERROR_RUNTIME_EXCEPTION = "ERROR_RUNTIME_EXCEPTION";
static final String TENANT_ID_MISMATCH_ERROR = "tenant-id-mismatch";

private final JsonFactory jsonFactory;
private final GooglePublicKeysManager publicKeysManager;
Expand Down Expand Up @@ -287,7 +288,7 @@ private void checkTenantId(final FirebaseToken firebaseToken) throws FirebaseAut
String tokenTenantId = Strings.nullToEmpty(firebaseToken.getTenantId());
if (!this.tenantId.equals(tokenTenantId)) {
throw new FirebaseAuthException(
FirebaseUserManager.TENANT_ID_MISMATCH_ERROR,
TENANT_ID_MISMATCH_ERROR,
String.format(
"The tenant ID ('%s') of the token did not match the expected value ('%s')",
tokenTenantId,
Expand Down
Loading