1 00:00:00,630 --> 00:00:06,240 We are right in the middle of generating the production set of our API credentials for the Google API. 2 00:00:06,660 --> 00:00:13,580 At this point we have to enter in our authorized javascript origin and our javascript authorized redirect 3 00:00:13,650 --> 00:00:18,780 you or I in both cases the addresses that we put here are going to be different. 4 00:00:18,780 --> 00:00:21,630 So you are not going to put in the same thing that I've put in. 5 00:00:21,630 --> 00:00:23,580 We're going to put in slightly different addresses. 6 00:00:23,730 --> 00:00:29,880 And that's because our respective Heroku applications are hosted on different domains. 7 00:00:30,060 --> 00:00:35,560 So to figure out what domain or what address you should use in here I'm going to open up my terminal. 8 00:00:35,650 --> 00:00:37,320 I'm going to find my running server. 9 00:00:37,590 --> 00:00:42,950 I'm going to kill it and I'm going to run the command Heroku open. 10 00:00:43,350 --> 00:00:49,060 This is going to open up a browser window at our running Heroku server. 11 00:00:49,140 --> 00:00:55,360 So up in the address bar this is the address that you want to use for your authorized redirect. 12 00:00:55,380 --> 00:00:57,300 So I'm going to select this address. 13 00:00:57,300 --> 00:01:00,630 I will copy it and then flip back over. 14 00:01:00,630 --> 00:01:04,860 Now to be a hundred percent clear you do not want to use the same address as me. 15 00:01:04,920 --> 00:01:08,650 Like do not type in agile by you it will not work for you. 16 00:01:08,700 --> 00:01:12,330 So make sure you use your own respective address. 17 00:01:13,040 --> 00:01:14,070 Back over. 18 00:01:14,510 --> 00:01:20,370 So let's do the authorized redirect you or I first remember this is the setting that says it is OK if 19 00:01:20,370 --> 00:01:25,760 users get redirected from the Google off flow to this address. 20 00:01:25,770 --> 00:01:30,930 So for us in the production world it will be our address right here. 21 00:01:31,350 --> 00:01:38,330 Slash Auth. slash Google slash Colback like so. 22 00:01:38,940 --> 00:01:45,190 And then for our authorized javascript origin This is where it is valid to send the user into the OT 23 00:01:45,510 --> 00:01:46,740 flow from. 24 00:01:46,740 --> 00:01:53,400 So in other words if we redirect our users from the address we put in here over to the Google flow then 25 00:01:53,400 --> 00:01:56,870 that is valid and okay and Google is going to allow it. 26 00:01:56,880 --> 00:02:02,580 So inside of here we're going to just put in the domain by itself and then make sure cause you're probably 27 00:02:02,580 --> 00:02:05,010 going to paste it with a slash at the end. 28 00:02:05,010 --> 00:02:08,140 Google this format here does not want to see that flash. 29 00:02:08,250 --> 00:02:12,260 If you click out it's going to turn red and it's going to say cannot end with Flash. 30 00:02:12,330 --> 00:02:16,260 So make sure you go in there and you delete that little slash on the end. 31 00:02:16,410 --> 00:02:18,470 And now it's OK and good to go. 32 00:02:19,120 --> 00:02:19,410 OK. 33 00:02:19,410 --> 00:02:20,480 So that's pretty much it. 34 00:02:20,520 --> 00:02:25,230 We will create our credentials by clicking create at the bottom and then we'll get this nice pop up 35 00:02:25,290 --> 00:02:29,060 that shows us our new set of production credentials. 36 00:02:29,160 --> 00:02:36,390 So we now have our production version of the Google API credentials and our production credentials for 37 00:02:36,390 --> 00:02:38,350 our Mongo database. 38 00:02:38,910 --> 00:02:39,880 OK. 39 00:02:40,380 --> 00:02:43,430 So that's pretty much it on the resource generation side. 40 00:02:43,470 --> 00:02:48,690 Now we're going to flip over to our actual code and set up our keys. 41 00:02:48,810 --> 00:02:54,840 File to require in the correct set of credentials depending on whether or not we are running our server 42 00:02:54,870 --> 00:02:56,890 in development or production. 43 00:02:56,970 --> 00:03:02,290 So to be really clear about one change that we're going to make here that might not be entirely obvious. 44 00:03:02,370 --> 00:03:07,650 Remember that right now all of our keys are in the Keys don't just file and we are not committing that 45 00:03:07,650 --> 00:03:09,380 to source control right now. 46 00:03:09,440 --> 00:03:12,280 And so moving forward we're going to change that. 47 00:03:12,320 --> 00:03:16,880 We are going to make sure that we do in fact commit this file to source control. 48 00:03:16,890 --> 00:03:22,950 We will commit it to get so that no matter what our application will always have something to at least 49 00:03:23,100 --> 00:03:25,500 point to the right set of keys to use. 50 00:03:25,740 --> 00:03:29,080 So keys to J.S. will no longer contain the actual keys. 51 00:03:29,130 --> 00:03:32,950 It will just have some logic to decide what set to use. 52 00:03:33,030 --> 00:03:36,180 Now we're not going to commit and use stuff down here. 53 00:03:36,180 --> 00:03:40,980 It's just about making sure that we do not commit the set of keys. 54 00:03:41,540 --> 00:03:43,370 All right so let's get to it. 55 00:03:43,560 --> 00:03:49,380 Back in my code editor I'm going to find my config folder and then inside of there I'm going to make 56 00:03:49,380 --> 00:03:51,660 my dev js file. 57 00:03:51,810 --> 00:03:53,580 So dev J.S.. 58 00:03:53,790 --> 00:03:59,870 So this is where we're going to place all of our actual very real development API keys. 59 00:04:00,110 --> 00:04:03,700 All of those keys are currently listed in the Keys G-S file. 60 00:04:03,780 --> 00:04:10,950 So I'm going to cut everything out of us and paste it into depth now just to make sure that it's really 61 00:04:10,950 --> 00:04:12,790 clear what file I'm in. 62 00:04:12,810 --> 00:04:15,880 Because we're going to be jumping between a lot of files very quickly. 63 00:04:15,960 --> 00:04:19,480 I'm going to put a little comment here at the top that says death. 64 00:04:19,540 --> 00:04:22,230 J.S. don't commit this. 65 00:04:22,560 --> 00:04:23,130 OK. 66 00:04:23,250 --> 00:04:25,100 So you don't have to put this comments up here. 67 00:04:25,110 --> 00:04:30,290 I just want you to have something as you're watching a video where you can easily say OK we're in Def 68 00:04:30,300 --> 00:04:32,980 Jam right now. 69 00:04:32,990 --> 00:04:39,370 Now back inside of keys yes I'm going to put a comment that says he's just yes and I'll say. 70 00:04:39,370 --> 00:04:44,260 Figure out what set of credentials to return. 71 00:04:44,940 --> 00:04:45,240 OK. 72 00:04:45,250 --> 00:04:50,950 So in case you start G-S we have to put some logic to decide whether or not we are in a production or 73 00:04:50,950 --> 00:04:52,740 development environment. 74 00:04:52,900 --> 00:04:57,440 And so there might actually be a production or develop as I said. 75 00:04:57,460 --> 00:04:59,670 So this might seem like something that's kind of hard to do. 76 00:04:59,680 --> 00:05:03,360 You might be sitting there thinking like you know how in the world do we do this. 77 00:05:03,490 --> 00:05:06,100 In reality it's actually pretty straightforward. 78 00:05:06,100 --> 00:05:14,560 When you deploy your server to Heroku there is an existing environment variable called node underscore 79 00:05:14,660 --> 00:05:21,590 EMV that environment very well tells us whether or not we are running in a production environment. 80 00:05:21,610 --> 00:05:26,530 Now we have previously already used one production or one environment variable that is being set up 81 00:05:26,560 --> 00:05:29,930 by Heroku back inside of our indexed file. 82 00:05:30,250 --> 00:05:33,850 So if we go back over there and then we go to the very bottom of the file. 83 00:05:34,090 --> 00:05:40,190 Remember we had previously read the port from the environment variables set up by Heroku. 84 00:05:40,480 --> 00:05:46,450 So we're going to do the exact same thing decide whether or not we are in production because Heroku 85 00:05:46,480 --> 00:05:51,400 is going to set up this other environment variable for us automatically as well. 86 00:05:51,400 --> 00:06:05,320 So inside the key file we will say if process EMV dot node underscore EMV is equal to production then 87 00:06:05,320 --> 00:06:11,250 we're going to say we are in production return the Prague's set of keys. 88 00:06:11,800 --> 00:06:20,990 Else we are in development returned the dev keys OK. 89 00:06:21,120 --> 00:06:22,580 So that's pretty much it. 90 00:06:23,070 --> 00:06:24,780 So at this point let's take a quick break. 91 00:06:24,780 --> 00:06:30,000 When we come back we're going to figure out exactly how we return the correct set of keys from both 92 00:06:30,000 --> 00:06:31,140 these statements. 93 00:06:31,140 --> 00:06:33,540 So quick break and I'll see you in the next section.