Skip to content

Commit 5d60e6a

Browse files
authored
Merge pull request #53 from tecladocode/jose/cou-97-write-flask-jwt-extended-section
2 parents 90180f9 + 89c1fc5 commit 5d60e6a

File tree

426 files changed

+17928
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

426 files changed

+17928
-11
lines changed

docs/docs-upcoming/07_flask_admin/01_project_overview/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/docs-upcoming/07_flask_admin/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/docs-upcoming/07_flask_admin/_category_.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/docs-upcoming/08_flask_jwt_extended/01_project_overview/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/docs-upcoming/08_flask_jwt_extended/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/docs/06_sql_storage_sqlalchemy/01_project_overview_sqlalchemy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Let's look at what we'll do in this section. There are no changes t
66
# Project Overview (and why use SQLAlchemy)
77

88
- [x] Set metadata above
9-
- [ ] Start writing!
9+
- [x] Start writing!
1010

1111
In this section we'll make absolutely no changes to the API! However, we will completely change the way we store data.
1212

docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class StoreModel(db.Model):
5959
</Tabs>
6060
</div>
6161

62+
Remember to import the `TagModel` in `models/__init__.py` so that it is then imported by `app.py`. Otherwise SQLAlchemy won't know about it, and it won't be able to create the tables.
63+
6264
## The marshmallow schemas
6365

6466
These are the new schemas we'll add. Note that none of the tag schemas have any notion of "items". We'll add those to the schemas when we construct the many-to-many relationship.

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class ItemsTags(db.Model):
6363
tag_id = db.Column(db.Integer, db.ForeignKey("tags.id"))
6464
```
6565

66+
Let's also add this to our `models/__init__.py` file:
67+
68+
```python title="models/__init__.py"
69+
from models.item import ItemModel
70+
from models.tag import TagModel
71+
from models.store import StoreModel
72+
from models.item_tags import ItemsTags
73+
```
74+
6675
### Using the secondary table in the main models
6776

6877

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Changes in this section
3+
description: Overview of the API endpoints we'll use for user registration and authentication.
4+
---
5+
6+
# Changes in this section
7+
8+
In this section we will add the following endpoints:
9+
10+
| Method | Endpoint | Description |
11+
| -------------- | ----------------- | ----------------------------------------------------- |
12+
| `POST` | `/register` | Create user accounts given an `email` and `password`. |
13+
| `POST` | `/login` | Get a JWT given an `email` and `password`. |
14+
| 🔒 <br/> `POST` | `/logout` | Revoke a JWT. |
15+
| 🔒 <br/> `POST` | `/refresh` | Get a fresh JWT given a refresh JWT. |
16+
| `GET` | `/user/{user_id}` | (dev-only) Get info about a user given their ID. |
17+
| `DELETE` | `/user/{user_id}` | (dev-only) Delete a user given their ID. |
18+
19+
We will also protect some existing endpoints by requiring a JWT from clients. You can see which endpoints will be protected in [The API we'll build in this course](/docs/course_intro/what_is_rest_api/#the-api-well-build-in-this-course)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: What is a JWT?
3+
description: Understand what a JWT is, what data it contains, and how it may be used.
4+
---
5+
6+
# What is a JWT?
7+
8+
A JWT is a signed JSON object with a specific structure. Our Flask app will sign the JWTs with the secret key, proving that _it generated them_.
9+
10+
The Flask app generates a JWT when a user logs in (with their username and password). In the JWT, we'll store the user ID. The client then stores the JWT and sends it to us on every request.
11+
12+
Because we can prove our app generated the JWT (through its signature), and we will receive the JWT with the user ID in every request, we can _treat requests that include a JWT as "logged in"_.
13+
14+
For example, if we want certain endpoints to only be accessible to logged-in users, all we do is require a JWT in them. Since the client can only get a JWT after logging in, we know that including a JWT is proof that the client logged in successfully at some point in the past.
15+
16+
And since the JWT includes the user ID inside it, when we receive a JWT we know _who logged in_ to get the JWT.
17+
18+
There's a lot more information about JWTs here: [https://jwt.io/introduction](https://jwt.io/introduction). This includes information such as:
19+
20+
- What is stored inside a JWT?
21+
- Are JWTs secure?

0 commit comments

Comments
 (0)