firebase-php icon indicating copy to clipboard operation
firebase-php copied to clipboard

Deprecated Methods

Open brunnohofmann opened this issue 8 years ago • 6 comments

1. Which version of kreait/firebase-php are you using?

3.5

2. Which version of PHP are you using?

7.1

3. What's the issue?

I wanna update my lib from 3.5, but some methods was removed. What can I use instead of the deprecated method "getUserByEmailAndPassword"? I'm using it to sign in users in my system... so I can get a especific user by email and password, now - on the actual version - I can only get a user with an id, and I havent.

brunnohofmann avatar Mar 05 '18 13:03 brunnohofmann

I removed signing in users from the library because I considered the scope of the Admin SDK to be managing users, not authenticating users, which is already provided in a secure way by the client SDKs.

Another reason was that getUserByEmailAndPassword and other similar methods have the side effect that user data ist not only fetched, but altered in the way that their last login time is changed to the timestamp of the method call.

On the other hand, you are not the first developer to need this feature back, so I will perhaps add this back in an upcoming release. Until then, unfortunately, if you rely on this method, you are stuck with 3.x. :/

jeromegamez avatar Mar 05 '18 13:03 jeromegamez

If you have control over the front- and backend of your application, the recommended way would be to sign in the user on the client side with one of the official client SDKs, then pass the user's ID token to the backend, verify the token and then use the included UID to access the firebase from the backend with limited privileges.

  • https://firebase.google.com/docs/auth/admin/verify-id-tokens#retrieve_id_tokens_on_clients
  • https://firebase-php.readthedocs.io/en/latest/authentication.html#verify-a-firebase-id-token
  • https://firebase-php.readthedocs.io/en/latest/authentication.html#authenticate-with-limited-privileges

jeromegamez avatar Mar 05 '18 14:03 jeromegamez

@brunnohofmann The functionality is coming back (in parts) in the next release with https://github.com/kreait/firebase-php/commit/ed00dacdfa493e3ecd11ce1f1fbfa526a0c5b4af .

Please note that this will return a UserRecord, and not perform the following requests with the permissions of this user. To replicate the behavior, you will have to create a new firebase instance with the user ID as a factory parameter:

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');

$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->create();

try {
    $userRecord = $auth->verifyPassword($email, $password);
} catch (Kreait\Firebase\Exception\Auth\InvalidPassword $e) {
    echo $e->getMessage();
    exit;
}

$userConnection = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->asUser($userRecord->uid)
    ->create();

jeromegamez avatar Mar 08 '18 15:03 jeromegamez

This is now included in 4.2.0 so I will close this issue - but feel free to add more comments if you have further questions!

jeromegamez avatar Mar 08 '18 19:03 jeromegamez

Wowwww.... any question! I only have to say THANK YOU :D Awaaaaasome

brunnohofmann avatar Mar 09 '18 18:03 brunnohofmann

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Mar 15 '19 20:03 lock[bot]