Reputation: 85
Is there any best way to integrate Firebase mobile number (otp) authentication to Laravel ? or any package ?
Upvotes: 4
Views: 7769
Reputation: 326
You can make user be authenticated by following firebase official steps to let user verify cellphone number with OTP.
If you want to access firebase from server(Laravel), you can try this package kreait/laravel-firebase and use cellphone number to get whether the user have been authenticated or not.
the code may look like this (you will get user's information if user is authenticated. Otherwise, you will get exception)
use Kreait\Firebase\Factory;
// other code
// change $keyPath to yours, do not just copy and paste
$keyPath = storage_path("app/firebase/blog-361f6-firebase-adminsdk-h5dyf-2287bc06a5.json");
$auth = (new Factory)->withServiceAccount($keyPath)->createAuth();
try {
// change $examplePhoneNumber to yours
$examplePhoneNumber = '+886900000000';
$user = $auth->getUserByPhoneNumber($examplePhoneNumber);
print_r($user);
} catch (Exception $e) {
echo $e->getMessage();
}
Upvotes: 5
Reputation: 209
https://www.codeproject.com/Articles/1256245/Integrate-Firebase-Phone-Authentication-With-Larav
This is something you can see.
As of now I don't found any package in laravel to do so. you have to do it manually.
Upvotes: -1