Transcription

Firebase EssentialsAndroid Edition

Firebase Essentials – Android EditionFirst Edition 2017 Neil Smyth / Payload Media, Inc. All Rights Reserved.This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited.All rights reserved.The content of this book is provided for informational purposes only. Neither the publisher nor the author offersany warranties or representation, express or implied, with regard to the accuracy of information contained in thisbook, nor do they accept any liability for any loss or damage arising from any errors or omissions.This book contains trademarked terms that are used solely for editorial purposes and to the benefit of the respectivetrademark owner. The terms used within this book are not intended as infringement of any trademarks.Rev 1.0

Table of Contents1. Introduction .11.1 Downloading the Code Samples . 11.2 Feedback . 11.3 Errata . 12. Getting Started with Firebase .32.1 Signing into the Firebase Console . 32.2 Creating a New Project . 42.3 Firebase Projects . 52.4 Firebase Pricing Plans . 52.5 Summary . 53. Firebase User Authentication .73.1 An Overview of Firebase Authentication . 73.1.1 FirebaseAuth Instance . 73.1.2 AuthUI Instance . 83.1.3 FirebaseUser Class . 83.1.4 AuthCredential Classes . 83.1.5 Authentication Provider Classes . 83.2 FirebaseUI Auth Authentication . 93.3 Firebase SDK Authentication . 93.4 Summary . 104. Email/Password Authentication using FirebaseUI Auth . 114.1 Creating the Example Project . 114.2 Connecting the Project to Firebase . 114.3 Adding the FirebaseUI Project Dependencies . 144.4 Enabling Firebase Email/Password Authentication . 154.5 Adding the Signed-In Activity . 164.6 Designing the SignedInActivity Layout . 164.7 Firebase Initialization Steps . 174.8 Initiating the Sign-in Process. 184.9 Handling the Sign In Activity Result . 194.10 Handling the Sign-in . 204.11 Signing Out. 214.12 User Account Removal . 224.13 Summary . 235. Testing and Customizing FirebaseUI Auth Authentication . 255.1 Authentication Testing Environment . 255.2 Firebase Console User Management . 255.3 Testing the FirebaseAuth App. 265.4 Customizing the Password Reset Email Message . 275.5 Testing the Password Reset . 305.6 Enabling Smart Lock for Passwords . 305.7 Color Customization. 325.8 Specifying a Logo . 33i

5.9 Deleting the Test Account . 345.10 Summary . 346. Google Sign-In Authentication using FirebaseUI Auth . 356.1 Preparing the Project . 356.2 Obtaining the SHA-1 Fingerprint . 356.3 Adding the SHA-1 Key to the Firebase Project . 366.4 Enabling the Google Sign-In Method . 376.5 Adding the Google Sign-In Provider within the App . 386.6 Testing Google Sign-In . 396.7 Displaying the User’s Profile Photo . 416.8 Summary . 447. Facebook Login Authentication using FirebaseUI Auth . 477.1 Preparing the Project . 477.2 Obtaining the Facebook App ID and App Secret . 477.3 Adding the App ID and Secret to the Firebase Project . 497.4 Adding the Facebook Login Product to the App . 497.5 Setting the OAuth Redirect URI . 507.6 Adding the Debug and Release Key Hash . 517.7 Modifying the App . 527.8 Testing Facebook Login Authentication . 547.9 Summary . 568. Twitter Sign-In Authentication using FirebaseUI Auth . 578.1 Preparing the Project . 578.2 Enabling Twitter Authentication . 578.3 Creating a Twitter App . 578.4 Obtaining the Twitter API Keys . 588.5 Generating the Access Token . 598.6 Adding the API Keys to the Project . 598.7 Adding Twitter to the Provider List. 608.8 Adding the Twitter Library Dependency . 608.9 Testing Twitter Authentication . 608.10 Summary . 629. Phone Number Sign-in Authentication using FirebaseUI Auth . 639.1 Preparing the Project . 639.2 Enabling Phone Number Authentication . 639.3 Adding Phone Verification to the Provider List . 639.4 Testing Phone Number Authentication . 649.5 Summary . 6610. Email/Password Authentication using the Firebase SDK . 6710.1 Creating the PasswordAuth Project . 6710.2 Enabling Authentication Providers . 6710.3 Connecting the Project to Firebase . 6810.4 Designing the User Interface Layout . 6810.5 Getting View Object References . 7110.6 Adding a User Notification Method . 7210.7 Accessing the FirebaseAuth Instance . 7210.8 Adding the Authentication State Listener . 73ii

10.9 Adding and Removing the Listener . 7410.10 Creating the User Account . 7510.11 Implementing the Sign-In Method. 7610.12 Signing Out . 7710.13 Implementing the Password Reset Option . 7710.14 Testing the Project . 7710.15 Summary . 7811. Managing User Accounts using the Firebase SDK . 7911.1 Enhancing the User’s Profile Information . 7911.2 Changing a User’s Email Address . 8011.3 Changing a User’s Password . 8111.4 Deleting a User Account . 8211.5 Verifying the User’s Email Address . 8211.6 Understanding Security Sensitive Actions . 8311.7 Summary . 8312. Handling Firebase Authentication Errors and Failures . 8512.1 Completion Listeners and Basic Failure Detection . 8512.2 The Failure Listener. 8612.3 FirebaseAuth Exception Types . 8712.4 FirebaseAuth Error Code