firebase登录验证
Firebase Authentication is a tool for managing user identity in a Firebase project. It provides a lot of authentication methods, including email/password, phone number and Facebook, etc. Facebook login is a very common option in modern app. App can benefit a lot by implementing Facebook login feature.
˚Firebase认证是在火力地堡项目管理用户身份的工具。 它提供了很多身份验证方法,包括电子邮件/密码 , 电话号码和Facebook等。Facebook登录是现代应用程序中非常常见的选项。 通过实现Facebook登录功能,应用程序可以受益匪浅。
Developer has to first create both the Firebase and Facebook project in order to complete the authentication process. The step for implementing the whole feature is as short as 9 steps. Let’s start!
开发人员必须先创建Firebase和Facebook项目,才能完成身份验证过程。 实现整个功能的步骤仅需9个步骤。 开始吧!
程序 (Procedures)
1.项目初始化 (1. Project initialisation)
Create a Firebase project at Firebase Console and a Facebook project at Facebook Developer Console.
在Firebase控制台上创建一个Firebase项目,并在Facebook Developer Console上创建一个Facebook项目。
2.启用Facebook登录方法 (2. Enable Facebook Sign-In method)
Navigate to the “Sign-in method” tab of “Authentication” session and enable the Facebook Sign-In method.
导航到“身份验证”会话的“登录方法”选项卡,然后启用Facebook登录方法。
The App ID can be found at the Facebook Developer Console here:
可以在以下Facebook开发者控制台中找到该应用程序ID :
3.将OAuth重定向URI复制到Facebook项目设置 (3. Copy the OAuth redirect URI to Facebook Project settings)
4. Firebase项目设置 (4. Firebase project setup)
Link your iOS app to Firebase project with the use of GoogleService-Info.plist
, which is a file generated during your app registration and containing important information, e.g. PROJECT_ID
, BUNDLE_ID
and API_KEY
.
使用GoogleService-Info.plist
将iOS应用程序链接到Firebase项目,该文件是在应用程序注册期间生成的文件,其中包含重要信息,例如PROJECT_ID
, BUNDLE_ID
和API_KEY
。
5.添加Firebase身份验证依赖项 (5. Adding Firebase Authentication dependency)
Firebase Authentication SDK can be added by CocoaPods. Include pod 'Firebase/Auth'
in Podfile
and run pod install
afterward.
Firebase身份验证SDK可以由CocoaPods添加。 在Podfile
包含Podfile
pod 'Firebase/Auth'
,然后运行pod install
。
6.初始化Firebase SDK (6. Initialise Firebase SDK)
Initialise the Firebase configuration at the AppDelegate.swift
file at the start of the app, see line 8.
在应用程序启动时,通过AppDelegate.swift
文件初始化Firebase配置,请参阅第8行。
7.实施Facebook登录SDK (7. Implement Facebook login SDK)
Facebook provides an easy to use login SDK for user to login and grant permission for app to retrieve his/ her personal information. Either SDK default login button or custom button can be used to trigger login function. Default login button is easier to be implemented.
Facebook提供了易于使用的登录SDK,供用户登录并授予应用程序检索其个人信息的权限。 SDK默认登录按钮或自定义按钮均可用于触发登录功能。 默认登录按钮更易于实现。
Make sure the loginButton(_: didCompleteWith: error:)
of LoginButtonDelegate
is implemented correctly such that the successful login callback can be caught and Firebase Authentication process (next step) can be called consecutively.
确保正确实施loginButton(_: didCompleteWith: error:)
的loginButton(_: didCompleteWith: error:)
, LoginButtonDelegate
可以捕获成功的登录回调,并可以连续调用Firebase身份验证过程(下一步)。
8.使用Facebook访问令牌登录Firebase (8. Sign-in Firebase with Facebook access token)
After successfully logging in through Facebook SDK, an AccessToken
is generated. The tokenString
property can be used to identify a user. Firebase Auth SDK would use this to create a user at Firebase database.
通过Facebook SDK成功登录后,将生成一个AccessToken
。 tokenString
属性可用于标识用户。 Firebase Auth SDK将使用它来在Firebase数据库中创建用户。
9.验证Firebase用户已创建 (9. Verify Firebase user is created)
After all process, new user data should be shown at the “Users” tab of the “Authentication” session.
完成所有过程后,应在“身份验证”会话的“用户”选项卡上显示新的用户数据。
摘要 (Summary)
- Firebase provides Facebook Authentication option to create a user account with Facebook access token. Firebase提供了Facebook身份验证选项,以创建具有Facebook访问令牌的用户帐户。
- Developer has to create both the Firebase and Facebook project at the developer consoles first. The Facebook Sign-In option must be enabled at the Firebase Console. 开发人员必须首先在开发人员控制台上创建Firebase和Facebook项目。 必须在Firebase控制台上启用Facebook登录选项。
Developer has to first implement the Facebook Login SDK and capture the login success callback in the
LoginButtonDelegate
.开发人员必须首先实现Facebook Login SDK,并在
LoginButtonDelegate
捕获登录成功回调。
You are welcome to follow me at Twitter@myrick_chow for more information and articles. Thank you for reading this article. Have a nice day! 😄
欢迎您通过Twitter @ myrick_chow关注我,以获取更多信息和文章。 感谢您阅读本文。 祝你今天愉快! 😄
翻译自: https://itnext.io/firebase-authentication-facebook-i-93aaf489839d
firebase登录验证