JWT server
JWTServer Π»ΡΠ³ΠΊΠΈΠΉ ΠΈ Π±ΡΡΡΡΡΠΉ ΠΌΠΈΠΊΡΠΎΡΠ΅ΡΠ²ΠΈΡ JWT.
JWT Server ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΌΠΈΠΊΡΠΎΡΠ΅ΡΠ²ΠΈΡΠΎΠΌ Π΄Π»Ρ Π°Π²ΡΠΎΡΠΈΠ·Π°ΡΠΈΠΈ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Π΅ΠΉ. ΠΠΌΠ΅ΡΡΠΈΠΉ Π³ΠΈΠ±ΠΊΠΈΠ΅ Π½Π°ΡΡΡΠΎΠΉΠΊΠΈ ΠΈ ΡΠ°Π·Π½ΡΠ΅ Π²Π΅ΡΡΠΈΠΈ API.
- ΠΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Google Recaptcha V3
- ΠΡΠΏΡΠ°Π²ΠΊΠ° ΠΊΠΎΠ΄Π° ΡΠ΅ΡΠ΅Π· ΡΠ΅ΡΠ²ΠΈΡ https://smsc.ru/ (ΡΡΠ°Π΄ΠΈΡ ΡΠ΅ΡΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ)
ΠΡΠΎΠ±Π΅Π½Π½ΠΎΡΡΠΈ
- ΠΡΡΡΡΡΠΉ ΡΡΠ°ΡΡ
- ΠΠΎΡ ΠΎΠ΄ΠΈΡ Π΄Π»Ρ ΡΠ΅ΡΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ frontend
- ΠΡΠ½ΠΎΠ²Π°Π½ Π½Π° Fast API framework ΠΈ Π²Π΄ΠΎΡ Π½ΠΎΠ²Π»Π΅Π½ ΡΠ°Π±ΠΎΡΠ°ΠΌΠΈ tiangolo
Route Entrypoints
Login
- [POST] - /api/v1/login/access-token
- [POST] - /api/v1/login/test-token
- [POST] - /api/v1/password-recovery/{email}
- [POST] - /api/v1/reset-password/
- [POST] - /api/v1/phone_status/
Users
- [GET] - /api/v1/users/
- [POST] - /api/v1/users/
- [GET] - /api/v1/users/me
- [PUT] - /api/v1/users/me
- [POST] - /api/v1/users/open
- [GET] - /api/v1/users/{user_id}
- [PUT] - /api/v1/users/{user_id}
Utils
- [POST] - /api/v1/utils/test-celery/
- [POST] - /api/v1/utils/test-email/
Items
- [GET] - /api/v1/items/
- [POST] - /api/v1/items/
- [GET] - /api/v1/items/{id}
- [PUT] - /api/v1/items/{id}
- [DELETE] - /api/v1/items/{id}
ΠΠΎΠ΄Π΄Π΅ΡΠΆΠΊΠ° ΠΊΠΎΠ΄Π° https://github.com/goltsevnet/jwtserver
ΠΠ°Π²ΠΈΡΠΈΠΌΠΎΡΡΠΈ
- uvicorn https://www.uvicorn.org/
- fastapi https://fastapi.tiangolo.com/
- starlette https://www.starlette.io/
- passlib https://pypi.org/project/passlib/
- pydantic https://pydantic-docs.helpmanual.io/
- redis https://pypi.org/project/redis/
- python-jose https://pypi.org/project/python-jose/
- sqlalchemy https://pypi.org/project/SQLAlchemy/
- sqlalchemy_utils https://sqlalchemy-utils.readthedocs.io/
- asyncpg https://pypi.org/project/asyncpg/
- psycopg2-binary https://pypi.org/project/psycopg2-binary/
- httpx https://www.python-httpx.org/
- python-dotenv https://pypi.org/project/python-dotenv/
Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ°
python -m pip install jwtserver
ΠΠΎΠ΄Π³ΠΎΡΠΎΠ²ΡΡΠ΅ Π±Π°Π·Ρ Π΄Π°Π½Π½ΡΡ
Postgres 14
ΠΈ Π²ΡΡΠ΅ Π²Π΅ΡΡΠΈΠΈ.
ΠΡΠΏΠΎΠ»ΡΠ·ΡΠΉΡΠ΅ ΠΊΠ°ΠΊ Π²Π°ΡΠΈΠ°Π½Ρ docker-compose.yaml
version: '3.1'
services:
db:
image: postgres:14.1-alpine
restart: always
build: .
environment:
POSTGRES_PASSWORD: example
ports:
- 5433:5432
ΠΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΡΡΠ΅ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΡ Π² ΡΡΠ΅Π΄Ρ: POSTGRES__DSN
Π΄Π»Ρ ΠΌΠΈΠ³ΡΠ°ΡΠΈΠΉ.
ΠΡΠΏΠΎΠ»Π½ΠΈΡΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ:
upgradehead
ΠΠΎΠ»ΠΆΠ½Ρ ΡΠ²ΠΈΠ΄Π΅ΡΡ:
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 98f3d19d2c0d, initial
ΠΡΡΠ°Π»ΡΠ½ΡΠ΅ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΠ΅ ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ Π² ΡΠ°ΠΉΠ» .env
ΠΈΠ»ΠΈ ΡΠ΅ΡΠ΅Π· dotenv.
ENVIRONMENT=production
PROJECT_NAME=JwtServer
SMS__LOGIN=login
SMS__PASSWORD=password
SMS__IGNORE_ATTEMPTS=True
POSTGRES__DSN=postgresql+psycopg2://postgres:example@localhost:5433/postgres
RECAPTCHA=True
GOOGLE__RECAPTCHA__SECRET_KEY=SECRET_KEY
TOKEN__V1_SOL=12345679100987654321
TOKEN__SECRET_KEY=SECRET_KEY
TOKEN__ACCESS_TOKEN_EXPIRE_MINUTES=90
API_V1_STR=/api/v1
ΠΡΠΈΠΌΠ΅ΡΡ:
ΠΠ»Ρ ΡΠ°Π·ΡΠ°Π±ΠΎΡΠΊΠΈ
- ΡΠΎΠ·Π΄Π°ΠΉΡΠ΅ ΡΠ°ΠΉΠ»
dev.py
from jwtserver.server import dev
if __name__ == "__main__":
dev(host="localhost", port=5000, log_level="info")
ΠΠ½ΡΠ΅ΡΠ°ΠΊΡΠΈΠ²Π½Π°Ρ API Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΡ
ΠΎΡΠΊΡΠΎΠΉΡΠ΅ Interactive API docs http://localhost:5000/docs
ΠΡ ΡΠ²ΠΈΠ΄ΠΈΡΠ΅ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΡΡ ΠΈΠ½ΡΠ΅ΡΠ°ΠΊΡΠΈΠ²Π½ΡΡ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΡ ΠΏΠΎ API.
ΠΠ»ΡΡΠ΅ΡΠ½Π°ΡΠΈΠ²Π½Π°Ρ API Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΡ
ΠΎΡΠΊΡΠΎΠΉΡΠ΅ Alternative API redoc http://localhost:5000/redoc
ΠΠ»Ρ ΠΏΡΠΎΠ΄ΡΠΊΡΠΈΠΈ
- ΡΠΎΠ·Π΄Π°ΠΉΡΠ΅ ΡΠ°ΠΉΠ»
main.py
from jwtserver.app import app
app.debug = False
-
Gunicorn:
gunicorn main:app
ΠΠΈΡΠ΅Π½Π·ΠΈΡ
ΠΡΠΎΡ ΠΏΡΠΎΠ΅ΠΊΡ Π½Π°Ρ ΠΎΠ΄ΠΈΡΡΡ ΠΏΠΎΠ΄ Π»ΠΈΡΠ΅Π½Π·ΠΈΠ΅ΠΉ Apache 2.0.