Setting Up Your Development Environment
00:00 To build the demo app you’ll make use of several Python packages. Flask is a microframework for building web apps. Being a microframework, Flask provides only the bare minimum services needed to create a web app. Basically, this just means handling HTTP traffic and mapping requests to routes.
00:19 Flask-Login is a package that provides user session management. In other words, it simply determines if a user is logged in or logged out. It also does some other things, but remember that a large part of authenticating users in the demo app will be handled by Google. As you saw earlier, there are a number of steps in the OAuth flow.
Implementing the flow from scratch can be tricky, and if you make a mistake, it can leave major security holes in your app. Fortunately, the Python community has provided the
00:52 This package is widely used and has almost a decade of experience, so you can be sure that it is sufficient for your needs. You’ll also need a way to call the URLs on the provider, independent of Flask.
This will be required to exchange the authorization code for the tokens. While the Python standard library includes the
urllib package, here’s an easier way to make HTTP requests—and it’s a package called
The author refers to it as “HTTP for Humans,” and it reduces calling an HTTP endpoint to just a few lines of code. Finally, you may have noticed that the URLs provided to Google during the registration process use secure HTTP, and this is a requirement. By default, Flask does not implement secure HTTP but instead relies on the
01:41 It’s time to get hands-on. I’ll be using Visual Studio Code with the Python extension installed for the demo, but you can use any text editor such as Atom or IDE such as PyCharm. In Visual Studio Code, open the terminal with Control + ` (backtick) and create a new directory to serve as the project root. Next, create a virtual environment for the demo app.
02:05 Restart Visual Studio Code, opening the new directory as a project.
02:11 In Visual Studio Code, associate the project with the virtual environment. Press Control + Shift + P, or Command + Shift + P on macOS, and search for “python select default interpreter.” Select that command, and then the virtual environment you just created.
If you are not using Visual Studio Code, you can activate the virtual environment by running the
activate script inside of the scripts folder of the virtual environment.
Now open a new terminal window, which will trigger the
activate script for the virtual environment. Create a new text file
requirements.txt and add the following to it.
02:50 Each line represents one of the packages and a specific version to install. Newer versions may work, but these have been tested for the demo app.
Install the packages using
pip. This will read from the
requirements.txt file. Coming up next, you’ll look at some helper code.
Become a Member to join the conversation.