php – Firebase Auth – >使用signInWithCustomToken创建的用户没有电子邮件地址
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Firebase Auth – >使用signInWithCustomToken创建的用户没有电子邮件地址,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2452字,纯文字阅读大概需要4分钟。
内容图文
![php – Firebase Auth – >使用signInWithCustomToken创建的用户没有电子邮件地址](/upload/InfoBanner/zyjiaocheng/811/fb6315951b224ba8a3ace60f668115ac.jpg)
我正在使用Firebase自定义身份验证系统用于使用Ionic制作的移动应用程序,我使用Laravel 5.2作为自定义Auth后端.
当新用户注册时,我在laravel中生成一个令牌(使用firebase / php-jwt)并将其返回到移动应用程序.
在此注册过程中,应用程序接收令牌并使用以下代码在firebase上创建用户:
firebase.auth().signInWithCustomToken($auth.getToken())
.then(function(response) {
$log.debug(response);
})
.catch(function(error) {
$log.debug(error.code + ' - ' + error.message);
});
在后端我使用下面的代码生成令牌:
private function create_custom_token($uid, $email, $is_premium_account) {
$service_account_email = env('SERVICE_ACCOUNT_EMAIL');
$private_key = env('SERVICE_PRIVATE_KEY');
$now_seconds = time();
$payload = array(
"iss" => $service_account_email,
"sub" => $service_account_email,
"aud" => "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
"iat" => $now_seconds,
"exp" => $now_seconds+(60*60), // Maximum expiration time is one hour
"uid" => $uid,
"claims" => array(
"premium_account" => $is_premium_account,
"email" => $email,
)
);
return JWT::encode($payload, $private_key, "RS256");
}
正如您在下面的图像中看到的那样,用户是在firebase上生成的,但问题是它没有电子邮件地址,只有UID.
拥有电子邮件地址以便轻松识别用户会更好.
也许有人帮助.谢谢!
更新:
我为create_custom_token函数更改了一点$payload:
$payload = array(
"iss" => $service_account_email,
"sub" => $service_account_email,
"aud" => "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
"iat" => $now_seconds,
"exp" => $now_seconds+(60*60), // Maximum expiration time is one hour
"uid" => $uid,
"email" => $email,
"email_verified" => false,
"claims" => array(
"premium_account" => $is_premium_account,
"email" => $email,
"email_verified" => false,
)
);
我还做了一些测试,看到传递给firebase的令牌包含所有需要的数据.我在后端使用相同的库(firabase / php-jwt)解码编码的令牌,然后接缝就可以了,但firebase仍然创建没有电子邮件地址的用户.
我不知道我错过了什么:(
解决方法:
我不认为使用自定义令牌是可行的.
node.js Admin SDK允许您创建/ updateUser并为该用户创建自定义令牌.这将是理想的方式,但是当你使用php时,我推荐以下解决方案:
您必须使用客户端js库设置电子邮件:
>在创建自定义令牌后,将其与电子邮件一起发送给客户端应用程序.无论如何,您已经发送了它,只需将电子邮件随身携带即可.
>在客户端应用程序中,signInWIthCustomToken和用户使用提供的电子邮件返回updateEmail,如下所示:
firebase.auth().signInWithCustomToken(token)
.then(function(u??ser) {
return user.updateEmail(email);
}).catch(...)
内容总结
以上是互联网集市为您收集整理的php – Firebase Auth – >使用signInWithCustomToken创建的用户没有电子邮件地址全部内容,希望文章能够帮你解决php – Firebase Auth – >使用signInWithCustomToken创建的用户没有电子邮件地址所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。