Skip to content
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

Auth using Emulator with demo project #844

Open
Ticlext-Altihaf opened this issue Nov 24, 2023 · 3 comments
Open

Auth using Emulator with demo project #844

Ticlext-Altihaf opened this issue Nov 24, 2023 · 3 comments
Assignees

Comments

@Ticlext-Altihaf
Copy link

Describe the feature you would like to see

Is it possible to use Firebase Emulator with demo Firebase project, it would be useful for CI testing where the current setup require creating new Firebase project and issue service account.

https://firebase.google.com/docs/emulator-suite/connect_auth#choose_a_firebase_project

Example from using official Admin SDK for Node.js, it works without requiring internet connection or having Firebase project.
firebase emulators:start --project=demo-project

process.env.FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099"
import { initializeApp } from 'firebase-admin/app';
import { getAuth } from 'firebase-admin/auth';

initializeApp({
    projectId: 'demo-project',
});

const newUserData = {
    email: Math.random()*10000 + '@example.com', // XXXX@example.com
    emailVerified: false,
    phoneNumber: '+1' + Math.random()*10000000000, // +1XXXXXXXXXX
    password: 'secretPassword',
    displayName: 'John Doe',
    photoURL: 'http://www.example.com/12345678/photo.png',
    disabled: false,
};

const user = await getAuth().createUser(newUserData)

// Getting the ID token with signInWithPassword
let idToken = await fetch(`http://127.0.0.1:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=random`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        email: user.email,
        password: "secretPassword",
        returnSecureToken: true,
    }),
})

idToken = await idToken.json()
idToken = idToken.idToken

const userFromIdToken = await getAuth().verifyIdToken(idToken)

await getAuth().deleteUser(userFromIdToken.uid)
@jeromegamez
Copy link
Member

jeromegamez commented Nov 24, 2023

@Ticlext-Altihaf
Copy link
Author

Ticlext-Altihaf commented Nov 24, 2023

Uh.. I think you misunderstood me, I did read the docs I can't find the guide where I can use Firebase Demo Project, yes it work with Real Firebase Project.

image

The code, where in Node.js SDK it work without credentials.

        $request = CreateUser::new()
            ->withEmail($email)
            ->withPhoneNumber($phoneNumber)
            ->withClearTextPassword($password)
            ->withDisplayName($faker->name);


        $firebaseUser = Firebase::auth()->createUser($request);

image

@jeromegamez jeromegamez reopened this Nov 24, 2023
@jeromegamez
Copy link
Member

jeromegamez commented Nov 24, 2023

Ah, I understand now, sorry for closing the issue so early 🙏🏻 (it's early here 😅)

I think this should be working, I'm running emulator tests with it, but seeing the demo- prefix... I've perhaps been doing it wrong the whole time 😬

FIREBASE_AUTH_EMULATOR_HOST: localhost:9099

I'll try to look into it as soon as I find the time, I'm currently working on the next major release for PHP 8.3, and I do have only limited time...

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

No branches or pull requests

2 participants