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 · 4 comments
Open

Auth using Emulator with demo project #844

Ticlext-Altihaf opened this issue Nov 24, 2023 · 4 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', // [email protected]
    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...

@cmenkemeller
Copy link

cmenkemeller commented Oct 1, 2024

@jeromegamez Did you ever find a solution for this? I am running into a similar issue where verifyIdToken() is making calls to google apis even though I'm pointing to the Firebase Emulators.

Offline fails with curl error -
Next Kreait\Firebase\Exception\Database\ApiConnectionFailed: Unable to connect to the API: cURL error 6: Could not resolve host: oauth2.googleapis.com (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://oauth2.googleapis.com/token in ...vendor/kreait/firebase-php/src/Firebase/Exception/DatabaseApiExceptionConverter.php:37

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

3 participants