Skip to content

FR: add ability to communicate with Auth Emulator #493

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

Closed
branks opened this issue Nov 10, 2020 · 7 comments
Closed

FR: add ability to communicate with Auth Emulator #493

branks opened this issue Nov 10, 2020 · 7 comments

Comments

@branks
Copy link

branks commented Nov 10, 2020

On the emulator documentation it states the the Node SDK can connect to the Firebase Authentication Emulator by using an environment variable - https://firebase.google.com/docs/emulator-suite/connect_auth

export FIREBASE_AUTH_EMULATOR_HOST="localhost:9099"

It would be great if this could also be supported in the Java SDK

@dv-bv
Copy link

dv-bv commented Dec 17, 2020

Any timelines on this one? Any way we could help getting this through the door?

@yuchenshi
Copy link
Member

@dv-bv Sure! We welcome Pull Requests that add support for the environment variable to the Java Admin SDK.

Just keep in mind that we're still having some important discussions on verifyIdToken so that may not land soon. We'd be happy to review PRs for supporting all other methods. (And by the way, while we do not commit to timelines, your can definitely help to get this through the door.

@7agustibm
Copy link
Contributor

Hi! I start this PR: #510

@7agustibm
Copy link
Contributor

Hi! When will the new version be available with this feature?

@dmitri-gb
Copy link

Just keep in mind that we're still having some important discussions on verifyIdToken so that may not land soon.

@yuchenshi, are there any updates on those discussions about verifyIdToken? I noticed that the Node Admin SDK was recently changed to always accept unsigned tokens when the emulator is in use. Will the Java SDK follow suit?

@yuchenshi
Copy link
Member

@dmitri-gb As you've observed, we've reached some conclusions regarding verifyIdToken and we're now working on implementing consistent support across Admin SDKs. Namely, verifyIdToken will accept unsigned tokens if the environment variable is set and the emulator is running.

While we're unable to provide ETAs, please rest assured we're building on top of @7agustibm's amazing work for network communications and we'll release once we have ID token support as well.

@at15
Copy link

at15 commented Apr 3, 2023

A snippet for connecting to auth emulator and import user https://firebase.google.com/docs/auth/admin/import-users#java

package foo;

import java.util.ArrayList;
import java.util.List;

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.ImportUserRecord;
import com.google.firebase.auth.UserImportOptions;
import com.google.firebase.auth.hash.HmacSha256;
import com.google.firebase.internal.EmulatorCredentials;
import com.google.firebase.internal.FirebaseProcessEnvironment;

import org.junit.jupiter.api.Test;

public class ImportUserTest {
    @Test
    public void testImportLocal() throws FirebaseAuthException {
        // Create FirestoreAuth connecting to local emulator
        // https://github.com/firebase/firebase-admin-java/issues/493
        FirebaseProcessEnvironment.setenv("FIREBASE_AUTH_EMULATOR_HOST", "localhost:9099");
        FirebaseOptions options = FirebaseOptions.builder()
                .setProjectId("foo-abcd")
                .setCredentials(new EmulatorCredentials())
                .build();
        FirebaseApp.initializeApp(options);
        FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();

        List<ImportUserRecord> users = new ArrayList<>();
        users.add(ImportUserRecord.builder()
                .setUid("uid1")
                .setEmail("[email protected]")
                .setPasswordHash("passwordHash1".getBytes())
                .setPasswordSalt("salt1".getBytes())
                .build());
        UserImportOptions userImportOptions = UserImportOptions.withHash(
                HmacSha256.builder()
                        .setKey("secretKey".getBytes())
                        .build());
        firebaseAuth.importUsers(users, userImportOptions);
    }
}

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

No branches or pull requests

9 participants