Laravel Firebase移动号码(OTP)身份验证

时间:2018-04-02 09:11:32

标签: php laravel firebase firebase-authentication laravel-5.5

有没有最好的方法将Firebase移动号码(otp)身份验证与Laravel集成?或任何包裹?

2 个答案:

答案 0 :(得分:1)

您可以按照firebase official steps进行身份验证,以允许用户使用OTP验证手机号码。

如果您要从服务器(Laravel)访问Firebase, 您可以尝试使用此软件包kreait/laravel-firebase 并使用手机号码来获取用户是否已通过身份验证。

代码可能看起来像这样 (如果对用户进行身份验证,您将获得用户的信息。否则,您将获得异常)

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();
}

答案 1 :(得分:0)

https://www.codeproject.com/Articles/1256245/Integrate-Firebase-Phone-Authentication-With-Larav

这是您所看到的。

到目前为止,我在laravel中没有找到任何可以这样做的软件包。您必须手动执行。

相关问题