Skip to content

Commit fc9732f

Browse files
committed
Merge branch 'master' into sampsa-dev
2 parents c785bc5 + eaa4437 commit fc9732f

File tree

8 files changed

+42
-241
lines changed

8 files changed

+42
-241
lines changed

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

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

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

release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
### Refactors
2020

21+
* ♻️ Refactor redirect labels to simplify removing the frontend. PR [#1208](https://github.com/tiangolo/full-stack-fastapi-template/pull/1208) by [@tiangolo](https://github.com/tiangolo).
22+
* 🔒️ Refactor migrate from python-jose to PyJWT. PR [#1203](https://github.com/tiangolo/full-stack-fastapi-template/pull/1203) by [@estebanx64](https://github.com/estebanx64).
2123
* 🔥 Remove duplicated code. PR [#1185](https://github.com/tiangolo/full-stack-fastapi-template/pull/1185) by [@alejsdev](https://github.com/alejsdev).
2224
* ♻️ Add delete_user_me endpoint and corresponding test cases. PR [#1179](https://github.com/tiangolo/full-stack-fastapi-template/pull/1179) by [@alejsdev](https://github.com/alejsdev).
2325
* ✅ Update test to add verification database records. PR [#1178](https://github.com/tiangolo/full-stack-fastapi-template/pull/1178) by [@estebanx64](https://github.com/estebanx64).
@@ -51,6 +53,7 @@
5153

5254
### Upgrades
5355

56+
* ⬆️ Bump jinja2 from 3.1.3 to 3.1.4 in /backend. PR [#1196](https://github.com/tiangolo/full-stack-fastapi-template/pull/1196) by [@dependabot[bot]](https://github.com/apps/dependabot).
5457
* Bump gunicorn from 21.2.0 to 22.0.0 in /backend. PR [#1176](https://github.com/tiangolo/full-stack-fastapi-template/pull/1176) by [@dependabot[bot]](https://github.com/apps/dependabot).
5558
* Bump idna from 3.6 to 3.7 in /backend. PR [#1168](https://github.com/tiangolo/full-stack-fastapi-template/pull/1168) by [@dependabot[bot]](https://github.com/apps/dependabot).
5659
* 🆙 Update React Query to TanStack Query. PR [#1153](https://github.com/tiangolo/full-stack-fastapi-template/pull/1153) by [@patrick91](https://github.com/patrick91).
@@ -59,6 +62,7 @@
5962

6063
### Docs
6164

65+
* ✏️ Update `README.md`. PR [#1205](https://github.com/tiangolo/full-stack-fastapi-template/pull/1205) by [@Craz1k0ek](https://github.com/Craz1k0ek).
6266
* ✏️ Fix Adminer URL in `deployment.md`. PR [#1194](https://github.com/tiangolo/full-stack-fastapi-template/pull/1194) by [@PhilippWu](https://github.com/PhilippWu).
6367
* 📝 Add `Enabling Open User Registration` to backend docs. PR [#1191](https://github.com/tiangolo/full-stack-fastapi-template/pull/1191) by [@alejsdev](https://github.com/alejsdev).
6468
* 📝 Update release-notes.md. PR [#1164](https://github.com/tiangolo/full-stack-fastapi-template/pull/1164) by [@alejsdev](https://github.com/alejsdev).

0 commit comments

Comments
 (0)