Skip to content

Commit b0e94d9

Browse files
authored
Merge branch 'tiangolo:master' into master
2 parents c647e16 + bf04594 commit b0e94d9

17 files changed

Lines changed: 64 additions & 253 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
- 🦇 Dark mode support.
1717
- 🐋 [Docker Compose](https://www.docker.com) for development and production.
1818
- 🔒 Secure password hashing by default.
19-
- 🔑 JWT token authentication.
19+
- 🔑 JWT (JSON Web Token) authentication.
2020
- 📫 Email based password recovery.
2121
- ✅ Tests with [Pytest](https://pytest.org).
2222
- 📞 [Traefik](https://traefik.io) as a reverse proxy / load balancer.

backend/app/api/deps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from collections.abc import Generator
22
from typing import Annotated
33

4+
import jwt
45
from fastapi import Depends, HTTPException, status
56
from fastapi.security import OAuth2PasswordBearer
6-
from jose import JWTError, jwt
7+
from jwt.exceptions import InvalidTokenError
78
from pydantic import ValidationError
89
from sqlmodel import Session
910

@@ -32,7 +33,7 @@ def get_current_user(session: SessionDep, token: TokenDep) -> User:
3233
token, settings.SECRET_KEY, algorithms=[security.ALGORITHM]
3334
)
3435
token_data = TokenPayload(**payload)
35-
except (JWTError, ValidationError):
36+
except (InvalidTokenError, ValidationError):
3637
raise HTTPException(
3738
status_code=status.HTTP_403_FORBIDDEN,
3839
detail="Could not validate credentials",

backend/app/core/security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime, timedelta
22
from typing import Any
33

4-
from jose import jwt
4+
import jwt
55
from passlib.context import CryptContext
66

77
from app.core.config import settings

backend/app/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from typing import Any
66

77
import emails # type: ignore
8+
import jwt
89
from jinja2 import Template
9-
from jose import JWTError, jwt
10+
from jwt.exceptions import InvalidTokenError
1011

1112
from app.core.config import settings
1213

@@ -112,5 +113,5 @@ def verify_password_reset_token(token: str) -> str | None:
112113
try:
113114
decoded_token = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"])
114115
return str(decoded_token["sub"])
115-
except JWTError:
116+
except InvalidTokenError:
116117
return None

backend/poetry.lock

Lines changed: 21 additions & 223 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@ pydantic = ">2.0"
1616
emails = "^0.6"
1717

1818
gunicorn = "^22.0.0"
19-
jinja2 = "^3.1.2"
19+
jinja2 = "^3.1.4"
2020
alembic = "^1.12.1"
21-
python-jose = {extras = ["cryptography"], version = "^3.3.0"}
2221
httpx = "^0.25.1"
2322
psycopg = {extras = ["binary"], version = "^3.1.13"}
2423
sqlmodel = "^0.0.16"
2524
# Pin bcrypt until passlib supports the latest
2625
bcrypt = "4.0.1"
2726
pydantic-settings = "^2.2.1"
2827
sentry-sdk = {extras = ["fastapi"], version = "^1.40.6"}
28+
pyjwt = "^2.8.0"
2929

3030
[tool.poetry.group.dev.dependencies]
3131
pytest = "^7.4.3"
3232
mypy = "^1.8.0"
3333
ruff = "^0.2.2"
3434
pre-commit = "^3.6.2"
35-
types-python-jose = "^3.3.4.20240106"
3635
types-passlib = "^1.7.7.20240106"
3736
coverage = "^7.4.3"
3837

docker-compose.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ services:
8484
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls=true
8585
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls.certresolver=le
8686

87+
# Define Traefik Middleware to handle domain with and without "www" to redirect to only one
88+
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^http(s)?://www.(${DOMAIN?Variable not set})/(.*)
89+
# Redirect a domain with www to non-www
90+
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=http$${1}://${DOMAIN?Variable not set}/$${3}
91+
92+
# Enable www redirection for HTTP and HTTPS
8793
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.middlewares=https-redirect,${STACK_NAME?Variable not set}-www-redirect
8894
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
8995

@@ -113,16 +119,8 @@ services:
113119
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls=true
114120
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls.certresolver=le
115121

116-
# Handle domain with and without "www" to redirect to only one
117-
# To disable www redirection remove the next line
118-
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^http(s)?://www.(${DOMAIN?Variable not set})/(.*)
119-
# Redirect a domain with www to non-www
120-
# To disable it remove the next line
121-
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=http$${1}://${DOMAIN?Variable not set}/$${3}
122-
# Middleware to redirect www, to disable it remove the next line
122+
# Enable www redirection for HTTP and HTTPS
123123
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
124-
# Middleware to redirect www, and redirect HTTP to HTTPS
125-
# to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
126124
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.middlewares=https-redirect,${STACK_NAME?Variable not set}-www-redirect
127125
volumes:
128126
app-db-data:

frontend/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Full Stack FastAPI Project</title>
8-
<link rel="icon" type="image/x-icon" href="./src/assets/images/favicon.png" />
8+
<link rel="icon" type="image/x-icon" href="/assets/images/favicon.png" />
99
</head>
1010
<body>
1111
<div id="root"></div>
File renamed without changes.

0 commit comments

Comments
 (0)