Skip to content

[FR] Connect to Firebase Emulator (Auth) using custom hostname and port #772

Description

@alinturbut

Is your feature request related to a problem? Please describe.
I am trying to setup a testing phase that would run tests on the Emulator by connecting to it. The Emulator is prepared using TestContainers which don't open specific ports, but rather random. Because of this I cannot use the environment variable specified as that blocks me into selecting a hostname and port.

Describe the solution you'd like
Make the hostname and port dynamic when initialising FirebaseAuth / FirebaseApp.

Describe alternatives you've considered

Additional context

Expected usage

FirebaseAuth.getInstance(firebaseApp()).useEmulator('localhost', '9099')

For example, Firestore has this enabled using FirestoreOptions.newBuilder().setEmulatorHost()

Activity

  1. google-oss-bot commented on Feb 20, 2023

    @google-oss-bot

    I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

  2. lahirumaramba commented on Feb 28, 2023

    @lahirumaramba
    Member

    Hi @alinturbut, This is interesting... for Node.js I would suggest setting the env variable at runtime with process.env, but I am realizing that it is not that straightforward in Java. I can't promise you a timeline on this, but I think this is a reasonable feature to add to the SDK. In the meantime, how are you getting the port currently? Are you able to set an environment variable in your workspace after you start your emulator instance?

  3. alinturbut commented on Mar 2, 2023

    @alinturbut
    Author

    @lahirumaramba After Java 17, it's not possible to set environment variables at runtime, unfortunately. For this reason, I haven't yet found a way to start using testcontainers a Firebase Auth Emulator.

  4. alinturbut commented on Mar 2, 2023

    @alinturbut
    Author

    @lahirumaramba if I get the time this weekend, I might submit a PR (would add a variable in FirebaseOptions that would add in FirebaseProcessEnvironment.localCache the needed values. I think this would do the job). I've signed the CLA for contributions. How do I get branch push rights?

  5. lahirumaramba commented on Mar 2, 2023

    @lahirumaramba
    Member

    I am not familiar with Testcontainers, could you explain how you would set the emulator host and port in your code if you don't know the port on Testcontainers ahead of time?

  6. alinturbut commented on Mar 3, 2023

    @alinturbut
    Author

    Testcontainers are initialised statically (or during early start of the spring boot app), therefore, when we initialize FirebaseOptions, we would already know the host and port of the testcontainers by setting up an application property (spring)

  7. lahirumaramba commented on Mar 3, 2023

    @lahirumaramba
    Member

    Thank you for the clarification! An API to set the emulator host sounds like a reasonable approach then. Happy to review any PRs if you would like to contribute to the codebase. :) You have to fork the repo and create a PR against the main branch of firebase/firebase-admin-java. Please note that any changes to the public API requires an internal API review. This can take a while, but I will initiate the process internally once we have a PR. Thanks!

  8. alinturbut commented on Mar 11, 2023

    @alinturbut
    Author

    please let me know if you think this is enough: https://github.com/firebase/firebase-admin-java/pull/781/files

  9. lahirumaramba commented on Mar 13, 2023

    @lahirumaramba
    Member

    Thank you @alinturbut for submitting the PR! We will review the changes and initiate the API review process internally. Please note that this can take some time.

    In the meantime, are you able to use a docker-compose file to inject environment variables to spawned containers used by Testcontainers? See: https://stackoverflow.com/a/69767792/1526201

    # docker-compose.yml
    services:
      my-service:
        environment:
          FIREBASE_AUTH_EMULATOR_HOST: ${FIREBASE_AUTH_EMULATOR_HOST}
    new DockerComposeContainer<>(new File("../docker-compose.yml"))
        .withEnv(Map.of("FIREBASE_AUTH_EMULATOR_HOST", "localhost:9092"))
        .withLocalCompose(true)
        .start();
  10. alinturbut commented on Mar 14, 2023

    @alinturbut
    Author

    @lahirumaramba thanks for getting back. I have tried this approach which works locally, but haven't managed to do it in the CI/CD pipelines (but haven't invested too much time on that approach, anyway) as docker compose was started but it couldn't connect to localhost.

  11. alinturbut commented on May 23, 2023

    @alinturbut
    Author

    @lahirumaramba any news?

  12. lucagonzalez commented on May 28, 2024

    @lucagonzalez

    Hey everyone, any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions