如何通过iOS(swift)将Firebase Auth与MySQL DB同步? [英] How to sync Firebase Auth with MySQL DB via iOS(swift)?

查看:80
本文介绍了如何通过iOS(swift)将Firebase Auth与MySQL DB同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS应用程序中构建注册/登录/保存"功能.

I'm building SignUp/LogIn/Saving functionality in iOS app.

对于注册/登录",我选择"Firebase身份验证".
但是,Firebase Auth只能保存基本属性(例如电子邮件地址,密码,URL等)
因此,为了保存用户的其他属性,我计划单独使用其他MySQL数据库.(通过制作用户数据库,用户表,用户ID主键和其他列)

For SignUp/LogIn, I choose 'Firebase Auth'.
But, Firebase Auth can only save basic properties(ex. email address, password, URL, etc)
So, to save user's other properties, I'm planning to use additional MySQL DB separately.(By making user DB, user Table, userID primary key, and other columns)

要与Firebase Auth和MySQL通信,我发现必须进行用户验证.
并且将使用JWT(Json Web令牌)进行验证.

To communicate with Firebase Auth and MySQL, I found that the user verification is a must.
And JWT(Json Web Token) will be used for verifying.

但是,为了使用JWT验证用户,我认为Firebase Auth和MySQL必须预先具有公共密钥(例如,用户ID,电子邮件地址等).

But, to verify users by using JWT, I think both Firebase Auth and MySQL must have common key(such as userID, E-Mail address, etc) in advance.

但是我不确定这是否是常见的方式(简单又安全).

But I'm not sure whether this is the common way(easy and safe) or not.

我读了多个线程,

将Android Firebase Auth用户安全地存储在MySQL中数据库
我可以构建一个使用Firebase身份验证但使用自定义数据库(例如MySQL)的Android应用
Firebase,如何将身份验证服务与一个node.js RESTapi后端

Securely store Android Firebase Auth users in a MySQL database
Can i build an Android app that uses Firebase authentication but a custom database(eg MySQL)
Firebase, how to use auth service with a node.js RESTapi backend

但是我无法完成此过程的第一步.

But I couldn't get the first step of this process.

我现在有疑问.



问题1.到目前为止,我了解的是正确的吗?

问题2.要验证用户,在注册"步骤中,我是否需要预先在Firebase Auth和MySQL中都存储一个公共密钥?

问题2-1-1. (如果是的话)在Firebase Auth和MySQL中拥有相同的数据是否不是安全问题? (当然,我不能在MySQL中保存任何其他私有数据(密码,电话号码等))

问题2-1-2. (如果是)您如何看待通用密钥的最佳数据? (用户ID,电子邮件地址,自动增加的用户ID等)

问题2-2. (如果没有)如何通过iOS同步Firebase和MySQL?

问题3.那整个过程是正确的吗?

I have questions at this point.



Question1. So far, what I've understand is correct?

Question2. To verify user, at 'SignUp' step, do I need to store a common key in both Firebase Auth and MySQL in advance?

Question2-1-1. (If yes) Wouldn't it be a security problem by having identical data in Firebase Auth and MySQL? (Of course, I must not save any other private data(password, phone number, etc) in MySQL)

Question2-1-2. (If yes) What do you think of the best data for common key? (userID, E-Mail Address, auto-incremented userID, etc)

Question2-2. (If not) How can I sync Firebase and MySQL via iOS?

Question3. Then, this whole process is correct?

  1. 设置iOS,Firebase身份验证,MySQL
  2. 用户注册后,电子邮件地址(可能还有用户ID)将同时发送到Firebase Auth和MySQL.但是密码只会发送到Firebase.
  3. 在登录期间,如果用户设置并保存了首选项,则iOS会将数据发布到MySQL的用户"表中的用户ID"行.
  4. 当用户再次登录时,iOS将从Firebase Auth获取令牌并将其发送到MySQL.
  5. 令牌将用于通过比较解密的令牌和MySQL公共密钥来验证用户.
  6. 如果通过验证,则MySQL会将用户的其他属性发送到iOS.
  7. iOS将获取用户的属性数据.



这是我第一次构建此功能.
请回答我的问题!
预先谢谢你!



It is my first experience of building this functionality.
Please reply to my question!
Thank you in advance!





推荐答案

不,您不需要预先存储公共密钥.

No, you don't need to store a common key in advance.

当用户登录时,您将在客户端(iOS设备)上获得一个JWT.然后,将此JWT附加到针对服务器的每个请求的标头.然后,在您的服务器上,您将使用此JWT向Firebase进行身份验证,如果成功,它将返回您的用户ID.而且您可以将其存储在数据库中.

You will get a JWT on your client (iOS device) when user does a sign in. Then you will attach this JWT to the header for every request to your server. Then on your server you will use this JWT to authenticate with Firebase, which will return you a user id if successful. And that you can store on your database.

这篇关于如何通过iOS(swift)将Firebase Auth与MySQL DB同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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