summaryrefslogtreecommitdiff
path: root/src/middleware.py
diff options
context:
space:
mode:
authorKristofer Hallin <kristofer@sunet.se>2021-10-08 14:17:43 +0200
committerKristofer Hallin <kristofer@sunet.se>2021-10-08 14:17:43 +0200
commit99f02077ed897b73fb9f452926e8f3f1fed72358 (patch)
tree96520ef7bc3446a3501f8f23d796d9ea931c74ef /src/middleware.py
parent446d9f04be3602d395407e79e781b7c591b45ad5 (diff)
First draft implementation on JWT.
Diffstat (limited to 'src/middleware.py')
-rw-r--r--src/middleware.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/middleware.py b/src/middleware.py
new file mode 100644
index 0000000..2e38190
--- /dev/null
+++ b/src/middleware.py
@@ -0,0 +1,24 @@
+from falcon_auth import FalconAuthMiddleware, JWTAuthBackend
+
+
+TEMPORARY_SECRET_KEY_TO_BE_CHANGED = 'testing123'
+TEMPORARY_JWT_ALGORITHM_TO_BE_CHANGED = 'HS256'
+
+
+def user_check(credential):
+ return {'user': credential['sub'], 'role': credential['role'], 'domains': credential['domains']}
+
+
+jwt_auth = JWTAuthBackend(
+ user_loader=user_check,
+ secret_key=TEMPORARY_SECRET_KEY_TO_BE_CHANGED,
+ algorithm=TEMPORARY_JWT_ALGORITHM_TO_BE_CHANGED,
+ auth_header_prefix='Bearer',
+ leeway=600,
+ expiration_delta=900,
+ audience='localhost'
+)
+
+middleware_jwt = [
+ FalconAuthMiddleware(jwt_auth)
+]