Everyone welcome back.
Johnny B here with slopes not come and in this lesson we're going to take a look at the Google log in
process.
So with each of the social platforms that we're going to look at Google Facebook and Twitter.
The process is very similar.
All right so it's twofold for each of them.
First we are going to be working with the social platforms SDK whether it's Google Facebook or Twitter.
And what we're going to be doing is we are going to use their the case to basically log in and return
and authentication credentials.
All right.
At that point then we move over to the firebase side where we take that authentication credential and
we pass it into the firebase auth function and from there we're able to actually create a firebase user.
All right.
So that's kind of the the flow for each platform we use we use the platform STK to log in and return
and credential.
Then we take that credential we pass it into fire bases methods and we create a new user.
All right so they're actually kind of completely separate like we could just do a Google logon.
But if we want to use Google or Facebook to log in and get a firebase user then we have to add on that
second part using firebase which is to pass the credential to firebase.
So anyways let's let's get started.
We're going to work with Google first and what we're going to do is let's go ahead and we are going
to just do a search for firebase Google logon and you can find this documentation here authenticate
using Google sign in on iOS and we're going to loosely follow this documentation here.
I'm not going to follow it step by step because in my opinion it's not in the most natural order.
But yes we're going to just so you know where to go if you get stuck or if you need further documentation
help.
So the first thing we are going to do is we are going to add to this or else scheme here and get services
that we need to add a your L scheme with the reversed claimed ID key that we get in our Google service
info it up the list.
So if we jump back into X code and the one that we need right here Google service and fold up the list
and this guy right he reversed client id getting going to grab this and copy it and then we're going
to Slik our firebase target here and we're going to go into info and then we're going to go to your
L types and we are going to add a new U R L type and here for the U or L scheme we are just going to
paste what we copied from our info from our Google service info up list.
Okay that's good.
I'm going to save that for each and every one of these platforms.
It's just going to be a lot of procedure and steps that we just got to do to make it work.
All right.
So this is step one.
Adding are your L scheme.
Next up we're going to go into our app delegate and I'm going to delete all these methods that we're
not going to be using just to clean things up a little bit.
And here I'm going to import both firebase and G.
D Google Science and that's it.
All right and so the app delegate We need to conform to the G Id sign and delegate right here.
OK.
And that's going to tell us that we need to implement some methods.
So I'm going to say fix and it's going to add in this method right here I'm going to cut and paste it
down here.
All right.
It's going to move that would go and looks pretty good.
So this is the method that is called Once we have signed in using Google and we get the parameters error
and yes so let's go ahead and do a check on that.
We're going to if that error is equal to error then we're going to say we're going to debug print debug
print and we're going to say could not log in with Google and then we're going to just print out that
error
else.
We're just going to print out for now.
Logged in.
OK.
And then here in the did finish launching with options we need to initialize our firebase app.
So when I say firebase app that configure and then we need to set a couple of Google seinen variables.
When I say a G Id sign in that shared instance or this is the shared instance for the Google sign in
class and I'm going to say Dot client id and we are going to set that equal to our firebase app that
app that options that client id then we're going to say Gee Id seinen that shared instance that delegate
is equal to self.
So now that we have set the same delegate here conform to its methods and added our delegate and Client
ID here.
Now we're going to move over to our view controller does swift file and we are going to add a Google
sign in button.
All right.
So if we check out our documentation here we have gone through this here we've done through Step 1 here.
We have come through Step two here where we add the sign in delegate.
We've come through Step three here and it's here.
We have more Skipp stuff for for now and see here.
I think that's pretty good for now.
We'll check back in there here in a minute.
But first I want to add that I said Here in mind story board X I want to show you in the documentation
what it says so says here.
Here we go.
Add adhd sign in button to your storyboard zip file or instantiated programmatically to add the button
to your storyboard or zip file add a view and said It's custom class to G Id sign in button and then
a note here says when you add the GED sign in button to your storyboard the sign in button doesn't render
and the interface builder.
Run the app to see the sign in button.
All right so I wanted to show you that that is the actual way that the documentation says to do this.
So we're going to add in a view here and I'm going to just resize it going to pinnate going to say Tony
from the left and 20 from the top and from the right.
And when I set the height to 40 I say add four constraints and then just so that we can see it I'm going
to set the background to a light gray color and that won't show up when we run this.
So I'm going to select it again and set the class to G Id sign in.
And there we go.
And now let's go ahead and open up our assistant editor with our view controller so that we can add
an action for this view.
So right here interview did load into control and drag from our view.
And I'm going to call this and it changes to an action.
Want to call this Google sign tapped.
And we're going to say connect and then we're going to close it and jump back into our control adults
with file.
And here in the Google sign in tapped I'm going to say Oh well first we import we got to import Let's
go import firebase and Google sign it.
And here in our view control the protocol that we want to add is Je Id sign and you don't get in here
in our view though we will set the ID sign in that shared instance that you Idella get equal to self.
OK.
And now last step is Id sign in that shared instance that sign in and we were going to do is launch
the Google logon screen.
All right so let's go and test this out.
All right so here is that Id sign in button.
And so this is kind of the default button that you can use out of the box for Google sign in.
And if we click on it lets see what happens.
All right so this is we want to use Google dot com to sign in.
We cannot continue and allow it.
And then this pops up and we were able to choose an account to log into and I'm going to pick my Johnny
Depp's up one and look at that.
If you see down here it says logged in.
All right so that is being called here from the app delegate if you remember from the did sign in for
user.
So we are successfully logging in with Google.
So I was pretty dang cool.
So I think were going to finish up here with this lesson and in the next lesson we are going to actually
integrate this with firebase so that we can use what we've got here so far logging in with Google to
actually log in with firebase and create users the firebase database with this Google log and are all
seeing the next one.