From 41b72fd216281a1d9cfb3c69f5d23c8342f2577b Mon Sep 17 00:00:00 2001 From: grillazz Date: Fri, 25 Jun 2021 09:05:52 +0200 Subject: [PATCH] add jwt to config.py --- .env | 2 ++ Makefile | 5 ++++- Pipfile | 1 + Pipfile.lock | 25 ++++++++++++++++++++++++- the_app/config.py | 4 ++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 8fc775b..5419367 100644 --- a/.env +++ b/.env @@ -7,3 +7,5 @@ SQL_HOST=db SQL_USER=user SQL_PASS=secret +ALGORITHM=HS256 +ACCESS_TOKEN_EXPIRE_MINUTES=30 diff --git a/Makefile b/Makefile index eda4c6c..35db4e8 100644 --- a/Makefile +++ b/Makefile @@ -31,9 +31,12 @@ safety: ## Check project and dependencies with safety https://github.com/pyupio/ docker-compose run --rm app safety check .PHONY: lint -lint: ## Linte project code. +lint: ## Lint project code. isort . black --fast --line-length=120 . mypy --ignore-missing-imports the_app flake8 --config .flake8 . +.PHONY: secret +secret: ## Generate random secret. + openssl rand -hex 32 diff --git a/Pipfile b/Pipfile index eca9e06..7004fb5 100644 --- a/Pipfile +++ b/Pipfile @@ -18,6 +18,7 @@ sqlalchemy = "*" pytest-asyncio = "*" pytest-cov = "*" python-jose = {extras = ["cryptography"], version = "*"} +passlib = {extras = ["bcrypt"], version = "*"} [dev-packages] icecream = "*" diff --git a/Pipfile.lock b/Pipfile.lock index b724f5b..b5f98d7 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "3335e2946336154720339ea7bccc5516814debc3168eee03ba6918d7e9d0e685" + "sha256": "86d6d53f88f48a5b54981346f5454046d18bafd4f7d28fa7ec722657d09f2c02" }, "pipfile-spec": 6, "requires": { @@ -68,6 +68,18 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", "version": "==21.2.0" }, + "bcrypt": { + "hashes": [ + "sha256:5b93c1726e50a93a033c36e5ca7fdcd29a5c7395af50a6892f5d9e7c6cfbfb29", + "sha256:63d4e3ff96188e5898779b6057878fecf3f11cfe6ec3b313ea09955d587ec7a7", + "sha256:81fec756feff5b6818ea7ab031205e1d323d8943d237303baca2c5f9c7846f34", + "sha256:a67fb841b35c28a59cebed05fbd3e80eea26e6d75851f0574a9273c80f3e9b55", + "sha256:c95d4cbebffafcdd28bd28bb4e25b31c50f6da605c81ffd9ad8a3d1b2ab7b1b6", + "sha256:cd1ea2ff3038509ea95f687256c46b79f5fc382ad0aa3664d200047546d511d1", + "sha256:cdcdcb3972027f83fe24a48b1e90ea4b584d35f1cc279d76de6fc4b13376239d" + ], + "version": "==3.2.0" + }, "black": { "hashes": [ "sha256:dc132348a88d103016726fe360cb9ede02cecf99b76e3660ce6c596be132ce04", @@ -432,6 +444,17 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==20.9" }, + "passlib": { + "extras": [ + "bcrypt" + ], + "hashes": [ + "sha256:aa6bca462b8d8bda89c70b382f0c298a20b5560af6cbfa2dce410c0a2fb669f1", + "sha256:defd50f72b65c5402ab2c573830a6978e5f202ad0d984793c8dde2c4152ebe04" + ], + "index": "pypi", + "version": "==1.7.4" + }, "pathspec": { "hashes": [ "sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd", diff --git a/the_app/config.py b/the_app/config.py index 3c9526c..df2adaf 100644 --- a/the_app/config.py +++ b/the_app/config.py @@ -34,6 +34,10 @@ class Settings(BaseSettings): asyncpg_url: str = f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_database}" asyncpg_test_url: str = f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_test_database}" + jwt_secret_key: str = os.getenv("SECRET_KEY", "") + jwt_algorithm: str = os.getenv("ALGORITHM", "") + jwt_access_toke_expire_minutes: int = os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", 1) + @lru_cache() def get_settings():