SPEAKER 1: Firebase Auth is a secure authentication system
that allows users to sign in and sign up for your application.
It allows Federated identity through providers
like Facebook, Twitter, and, of course, Google.
Now when doing this, your users generally
demand a rich user experience.
And providing this, as well as solving identity problems,
can be a lot of work.
Luckily, Firebase Auth UI makes all of this really easy.
And in this video, I'll show you how
to do sign-in and sign-up with Google in an Android app,
as well as using email password combinations.
Before we start, you'll need to create a Firebase project
and then enable authentication on it.
The console will provide you with code snippets
that you can put into your app.
Let's take a look.
Here you can see I have a project set up
in Firebase Console.
I've associated it with an Android app in the typical way.
Then, in the Authentication tab, I
set up email password and Google as my sign-in providers.
And that's all I need to do in the console.
If you don't have it already, be sure to get
the google-services.json file for your app by going
to the app in the overview and then clicking Settings.
Firebase UI is open source and it
contains a sample app that shows you how to do sign-in flows.
You can download the source code for the app at this link.
I'll be using that app to demonstrate how sign-in works.
So let's take a look.
Here's the Firebase UI sample app in action.
When you start it, it will ask if you
want a chat activity, an Auth UI demo, or storage image demo.
Pick the Auth UI demo and you'll see this screen.
I'm using the google-services.json file that
I just downloaded from the console and there,
where I picked email and Google as my authentication providers.
As such, it will show that the Facebook and Twitter
services are not configured.
Let's look first at how email sign-in works.
So just check email and leave Google unchecked.
Press start, and the first thing that you might see
is a list like this.
This is a list of the e-mails that I've
configured in Smart Lock for Passwords, i.e.
other e-mails that are associated with my main
account on this phone.
It's a nice shortcut for your users
and if they want to use one of those emails
as an associated ID.
But I'm going to say none of the above.
And what will happen is I can now sign up with a new email.
I'll just enter something.
I'm then asked to specify first and last name as well as
the password for this account.
Remember, this isn't the password for that email address
on its host, it's the password that the person identified
by this email address will use to sign into this app.
Once I save it, I'm asked to save it also with Smart Lock.
I'll say yes.
I'm now signed into the app.
And if I sign out and try to sign back in again,
the framework is smart enough to know that I had previously
tried to sign in with this identity
and it will just allow me to use it.
You just saw a lot of functionality
that makes your user experience a lot easier.
And you probably thought that that would take a lot of code.
Well, guess what, it really didn't.
As much of this flow was handled for you by the Auth UI classes.
Let's take a look at how they did it next.
In the source code, find the Auth UI activity.
It should be in the comm.firebase.uidemo namespace,
as you can see here.
Scroll down to find the sign-in function.
This is what gets called when the user clicks
the Sign In button.
You'll see it starts an activity for the result
from creating an intent builder for the Auth UI class.
This class is part of the Firebase Auth UI framework
and is completely open source.
You can see it here.
When we start the activity, we give it a code, RC_SIGN_IN, so
that when Android detects an activity result,
it will give you a callback with that activity code.
And you can see that here.
Upon the activity being RC_SIGN_IN,
we call Handle Sign In Response.
In this function, we simply handle
the different sign-in conditions.
If the sign-in was canceled or failed for no network,
we can show a snack bar.
Otherwise, if it was OK, we can start
a new activity, the signed-in activity, passing it the data.
The signed-in activity renders the "You
are signed in" message.
It's really that simple.
What's really neat about this code
and this class is that it encapsulates the entire user
flow--
signing up, signing in, using Smart Lock, stuff like that.
Earlier, we left Google turned off.
So now let's turn it on and we'll
see what it looks like to go through that user flow.
And we didn't write any extra code to do it.
Now when I run my app, I will see that when
I try to sign in, that I have two options.
I'll pick the sign-in with Google,
and I'll get a list of Google accounts I use on this device.
There's only one, so let me just pick it.
You can see that I get signed in and the basic profile
information from my Google account is given to the app.
If I sign out and try again, this time,
supposing I don't want to use that account,
I can select Add Account.
This will take me through the standard Google
flow for either adding an existing account to this device
to sign into the app or just creating a new account.
So if I, for example, sign in with a different Gmail account,
I'll get taken into the app.
Subsequently, when I try to sign in with Smart Lock or just
Google sign-in from the button, I'll
get the ability to choose this account,
saving me from having to remember.
And as I save the password with Smart Lock,
I can sign in without a password.
This is optional, of course.
But I just chose to do it that way.
And that's it.
That's how easy it is to use the powerful open source Auth UI
libraries to add a full sign-in, sign-up experience to your app
that uses the standard Google workflows
or gives you the ability to have your own email-based identity
provider in a way that's simple to implement and friendly
for your users.
Thanks for watching.
And if you have any questions, please leave them
in the comments below.
And don't forget to hit that Subscribe button.
[MUSIC PLAYING]