Transcript
Hello friends. Previously I have created multiple videos about social login or auth, and now we are going to add auth with, uh, apple. So here I have already added this, uh, auth with Apple in superl.com. Let's see how it works. I will click on the sign in with the Apple button, and as I'm using uh, Mac, it will automatically show the native, uh, apple ID to authenticate and sign in. So, uh, here I have passed the authentication and, uh, voila, I have signed in my via my Apple account. Okay, looks good. Let's see how you can do it in your application. First of all, the hottest thing you need to get the Apple API keys to do. So you need to enroll to the Apple Developer Program. So you go to this page and you click on start your Enrollment. Next, you have to create an Apple ID and pay $100. Actually, it costs $100 per year to keep your Apple developer ID active. So when you have created the id, you can go to your account page right here and you will go to certificates, IDs, and profiles. So you will click on, let's say certificates. It'll take you to this page and you'll need to go to Identifiers. First of all, you will create, uh, an app id, let's go to continue app. And, um, so description, uh, devise, uh, uh, demo out. And bundle ID would be, uh, usually the reverse of your domain and the app name. So it's say if I using super.com, I would have, uh, uh, com Super Rails, uh, device Al. And here in the, uh, capabilities, I would need to go down and add the sign in with Apple. You don't need to click on edit here. You can do it, uh, later. You don't need to edit here. Okay, you just check this checkbox and you click on continue. Now, just to confirm, you click on register. Okay, so we have created an identifier. This is an app id, and now we need to go and create a service ID. Here, I don't have, uh, this service id. I have an old one that I created previously. I will go to identify us, create a service Id continue, uh, description, uh, device, uh, al demo service, id, identify again com, super rails, uh, do device, uh, uh, alpha Author service, continue and register. Okay, so we have created this, uh, service id. Let's click on it. And we need to add the send in with Apple and click on configure. So domains and sub domains. You can add your rule production domain, but uh, if you want to make it work in local host, you can just use local host. You would need to use something like, uh, nro. Uh, I've created a video about NRO previously so that you will get a virtual, uh, URL that points to your local host here in my example app that I have already just installed. Device I am running, uh, nro, and this is my URL. So, um, let me, uh, add the CRL and the return URL is going to be slash users slash al slash apple slash callback. Uh, next, okay, this has to be without HHPS and here it has to been actual URL. Okay, let's click on, uh, next. And, uh, yeah, before clicking, uh, done, how can we verify that this is the right, uh, URL? Let's go to our roots of our application. Yeah, actually I have add basic device applications run in. So I have like just a simple app where I can, uh, let's say, uh, log in. So I'm not logged in. Now I can just visit the homepage. To visit the dashboard, I need to log in and have the normal device, email and password flow. I don't have any authentication yet. So let's have a look at the route here. Let's say rails roots grab, uh, apple, we don't have an Apple route yet, but if we go to user RB and say Omni Apple and, uh, omni providers will have Apple and run the rails roots grab Apple. Once again, it's going to give us an error. Uh, why? Because we didn't add the Apple, uh, authentication gem yet. So let's add the Apple out gem. It is this omni alt Apple gem. Let's, uh, add the gem to our gem file. Now we run, uh, bundle. Let's check the route once again. So it has added the route, uh, slash users out Apple callback. So let's, uh, verify it here. Yes, it's the right, uh, URL. Let's click on Don. Okay, and continue. Now we have, uh, this app identifier and we have checked the, the sign in the Apple. Okay, save. Okay, and now we need to add the keys. So we'll go to Keys and create the key. So device, uh, uh, demo out. Uh, I will click on sign in with Apple Configure. We will select the app that we have just created, save and uh, continue register. And we have the key ID and we have the security key. We can download the secret key. Let's, uh, show it in finder and we can actually drag and drop it into our editor and see our private key. Okay, so, uh, this is good. Let's click on Don and let's go and, uh, add the rail spot. So we have already added all the, uh, authentications we need in the Apple pod. We've added the, uh, app id, the service id, the keys, and now we can add the gem itself. So we've added the gem, Omni Apple, and inside our, uh, device.org, we can find omni auth and uh, uh, providers. Let's see. Uh, yeah, so here I'm going to go with these, uh, keys and I'm going to say contact Omni Auth Apple, and the client ID is going to be the service id. So going to identifiers, service IDs, uh, we are going to call it this identifier. Yeah, this identifier. Okay. Then, uh, team ID is going to be this id, it's o at copy pasting. So, uh, this is the team id. Next thing is the key id. So I will go back to our keys. Uh, the key, this is the key ID And the PEM. So it is this one. Let's copy it and, uh, put it inside. Okay, we have the key. Let's, uh, see what's next. So, uh, we have added the omni health keys. We've added the callback. And let's, uh, go back to our user B if we have added the providers Apple. Okay, we have most of the setup done. Let's see if it works. I'm going to run bundle once again and start the server rails server Again, as a reminder, I'm running the on clock. Okay. And you see now we have the sign in with Apple button because we added the, uh, apple Omni provider inside our user rb. So let's click on this and, uh, if, uh, all the credentials are correct, it might, uh, work, but, uh, okay, could not authenticate from Apple because authenticity error. So to fix, uh, this error, I've only to install, uh, the gem that you need now for all the omni health providers, gem, uh, omni Health Rails, CSFR protection. So this gem should help us with the fixing the authenticity error. Let's start the rail server once again and click on sign in with Apple. And here we have this. Let's click on, uh, sign in, and we have this invalid authenticity, uh, token. So, uh, to fix this, uh, error, uh, what would we need to do? Uh, one thing we definitely need to do is, uh, so you see, uh, in the gem, uh, pull requests, we see there is, uh, this, uh, error. Uh, I mean this fix to a problem that error is having. And basically the gem doesn't work correctly without, uh, this, uh, change. So we would need to set the nos to local. So I'm going to use not the gem itself, but I'm going to use, uh, the GEMS version from B fogal. So, uh, I will say, uh, uh, GitHub b fogal, uh, omni out apple and brunch. It'll be, uh, fix apple session handling. Okay, uh, let's run bundle once again. Uh, okay, it's not found. Yeah, it should be slash So now we run bundle. Okay. And inside our device, a b we'll need to set the nons to local and, uh, raw, wider, ignore state to true. Okay, to true. Uh, let's, uh, start the server once again and let's, uh, go and sign in and see if it works. Okay, let's continue. Uh, And, uh, great. So, uh, we have fixed all the onal problems, and now we try to hit the device Onal Callbox controller, and, uh, it says the action Apple could not be found, so it actually does the authentication part, uh, but we need to actually, uh, add the part inside our app, uh, to handle the Omni Out request. So I'm not going to go through the Hulu process now, I've already done in previous videos, but basically I'm going to add the, the Omni ath callbox controller inside our application. So I will go to, uh, slash controller slash users. Here. I will create omni ath Callbox controller. I will, uh, copy the controller here. I will rename it from Azure to Apple. I don't need this provider and your ID. So I have, uh, the Callbox controller that should, uh, handle the request and, uh, find the user from the, uh, uh, information received from the Apple, uh, payload and find the user or create the user and log the user in and direct to the application. Uh, this is fine. Now we need to go to our roots and say that we are using this controller. So controllers, onar, callbacks slash users, Onar callbacks. Okay, let's, uh, start the server once again and, uh, try to sign in with Apple. Okay, we get this invalid authenticity to token. And, uh, for Apple specifically, we would need to skip, uh, before action verify authenticity token. Uh, other omni health providers usually send, get requests, but Apple also sends post requests. That's why we need the, to skip this before action. Let's, uh, try once again. So log in And we have signed into our account via Apple. So Luke's file. So, uh, to summarize, initially, we need to, uh, sign up to the Apple developer program, get all the API keys afterwards. We need to add the, uh, right versions of the gems, uh, that work. We need to add our keys to device RB inside user RB via add Omni Providers Apple. Uh, in our route we say that we're using Omni Callbox controller and the Skip Before Action Token and Sign Infinite Apple. So that's about it, and, uh, thanks for being with me and see you in the next one.
0