From the course: Building RESTful APIs with Flask
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Authenticating users and passing the token
From the course: Building RESTful APIs with Flask
Authenticating users and passing the token
- [Instructor] Now that we have the ability to register new users, we need a way for existing users to log in. We're going to need to add a route for this, but before I do that, I want to go through the customary setup steps for our new JWT library. For this, I'm going to scroll all the way to the top of the code, and let's add a line in our imports. I'll say from flask_jwt_extended import JWTManager, jwt_required, and create_access_token. Then we're going to have my app.config setup. Let's add a key to this, so I'll say app.config, and the name of the key is JWT_SECRET_KEY in all caps. Normally you would set this equal to some secure string like a GUID or a UUID, but I'm just going to set mine to super-secret. I'll say change this in real life just to remind you if you're looking at this later. We got the app config'd. The next step is to go ahead and initialize the JWTManager, and that looks like this. I'll create a variable called jwt, and I'll set it equal to JWTManager. I'll pass…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.