Firebase身份验证(使用自定义令牌,适用于Linkedin)返回一个没有电子邮件和没有数据的用户(仅限于uid) [英] Firebase Auth (with Custom Token, for Linkedin) returns a user with no email and no data (only uid)

查看:191
本文介绍了Firebase身份验证(使用自定义令牌,适用于Linkedin)返回一个没有电子邮件和没有数据的用户(仅限于uid)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用Linkedin和Firebase登录。我在我的服务器上生成自定义令牌,我有我的私钥,我使用RS256,这是我的有效载荷:

 iss :service_account_email 
sub:service_account_email
aud,https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit
iat,日期().timeIntervalSince1970
exp,Date()。timeIntervalSince1970.advanced(by:3600)
uid,String.randomString(length:28)



我创建令牌,将其发送回应用程序,并从此执行:

<$在

中完成:{(用户,错误))pre> Auth.auth

我没有收到任何错误和用户返回,所以令牌是有效的。问题是用户没有值(没有电子邮件,没有displayName等)。唯一的是uid这是我设置:String.randomString(长度:28)

如何检索用户的电子邮件和其他信息?一个显示名称,电子邮件,图片等,但在这里没有。

谢谢

解决方案

你必须手动设置。 Firebase身份验证具有更新个人资料(照片网址和显示名称)以及电子邮件的API。您可以将LinkedIn数据与自定义令牌一起发送到您的应用程序,使用自定义令牌登录,然后更新自定义令牌用户的个人资料和电子邮件。



通过方法是将LinkedIn ID设置为该用户的UID。不要使用随机字符串。否则,下次您使用LinkedIn登录时,同一用户将会映射到另一个用户。


I'm trying to login with Linkedin and Firebase. I generate on my server the custom token, I have my private key, I use RS256 and this is my payload:

"iss" :  service_account_email
"sub" :  service_account_email
"aud", "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
"iat", Date().timeIntervalSince1970
"exp", Date().timeIntervalSince1970.advanced(by: 3600)
"uid", String.randomString(length:28)

I create the token, send it back to the app and from this I do:

Auth.auth().signIn(withCustomToken: token!, completion: { (user, error) in

I receive no error and a user back, so the token is valid. The problem is that the user has no values (no email, no displayName etc). the only thing is the uid which is the one that I set with: String.randomString(length:28)

How can I retrieve the user email and other info? In my linkedin account I have a displayname, email, picture etc. But here nothing.

Thanks

解决方案

You have to set that manually. Firebase Auth has APIs to update profile (photo URL and display name) as well as email. You can send this LinkedIn data along with the custom token to your app, sign in with custom token and then update profile and email on that signed in custom token user.

By the way, set the LinkedIn ID as the UID for that user. Do not use a random string. Otherwise the next time you sign in with LinkedIn, the same user will map to another one.

这篇关于Firebase身份验证(使用自定义令牌,适用于Linkedin)返回一个没有电子邮件和没有数据的用户(仅限于uid)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆