Commit graph

17 commits

Author SHA1 Message Date
fusion44
868457ffa5
fix(api): replace deprecated asyncio.get_event_loop()
get_event_loop() is deprecated on Python 3.11+ when there is no running
loop and is slated to change behaviour further.

- SSEManager.setup() ran at import time (app.api.utils) via
  get_event_loop(); this only worked because uvicorn imports the app
  inside its loop and would break when imported without a running loop
  (e.g. a Celery worker). Start the broadcast consumer lazily from
  within a running loop instead.
- everywhere else the pattern was get_event_loop().create_task(x)
  inside a coroutine; replace with asyncio.create_task(x).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 22:34:44 +02:00
fusion44
dccaa17a8e
fix(auth): correct JWT expiry unit and use standard exp claim
sign_jwt added JWT_EXPIRY_TIME (seconds) to a milliseconds epoch and
stored it in a custom 'expires' claim, while register_cookie_updater
slept JWT_EXPIRY_TIME as seconds. With the code default (300) tokens
effectively expired almost immediately; with the sampled 3600000 the
cookie-refresh loop slept ~41 days, so the local .cookie held an
expired token nearly always. The custom claim also meant PyJWT never
validated expiry itself.

- issue standard 'iat'/'exp' claims (seconds) and let PyJWT validate,
  requiring 'exp' on decode
- derive the cookie refresh interval from the same unit, guarded
  against tiny/negative values
- default BAPI_JWT_EXPIRY_TIME to 3600s and fix .env_sample (was
  3600000 'milliseconds')

Existing tokens and the local .cookie are invalidated by this change;
clients re-login and the cookie regenerates at startup.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 20:35:34 +02:00
fusion44
25e4be8441 feat: make config loading more flexible
If the environment variable BAPI_ENV_PATH is set, the config system will
try to read configs from the given path instead of .env in pwd

If no file is found .env in pwd will be used as a fallback

Env variables will always override settings in .env files.
2025-03-23 17:43:39 +01:00
fusion44
adf472ac8b feat: implement Ruff as a linter; fix given errors 2023-06-25 07:17:00 +02:00
fusion44
2435b1c57f
feat: improve logging and remove print statements 2022-12-18 20:55:48 +01:00
fusion44
f06d84c29f
fix: return auth token as plain text on login 2022-10-22 11:45:59 +02:00
fusion44
fcb23c2fc0 fix: token expiry time check
fixes #105
2022-08-21 20:08:55 +02:00
fusion44
85d2de19e4
chore: fix some naming issues 2022-03-23 21:03:50 +01:00
fusion44
516550bd9f
chore: format source using the pre_commit command 2022-03-20 17:20:56 +01:00
Stefan Stammberger
71f87e06d7
feat: implement local cookie authentication
This is only useful for application running directly on the Raspiblitz.
This will create a file in ~/.blitz_api/.cookie with a valid JWT token.
Local applications can use this to authenticate to the API without
having to ask for the password. This is similar to how Bitcoin Cores
cookie auth works.
2021-11-28 08:42:52 +01:00
Stefan Stammberger
63c52d2ba7
fix: encode JWT expiry time as int, not float
fixes #46
2021-11-22 20:44:14 +01:00
Stefan Stammberger
964514f90c
fix: return HTTP status 401 when unauthorized
Previous status code 403 was inappropriately used.
2021-11-19 08:36:15 +01:00
Stefan Stammberger
070ac2131c
fix: update wrong PyJWT version
Also: don't silently eat exceptions when decoding a JWT token
2021-09-25 17:58:53 +02:00
Stefan Stammberger
f482c441cc
chore: format all files using black 2021-09-05 08:56:53 +02:00
Stefan Stammberger
c33351d968
refactor: move some config vars to the .env file 2021-07-25 17:24:33 +02:00
Stefan Stammberger
51e369cf14
feat: implement get hardware info api 2021-06-12 15:07:35 +02:00
Stefan Stammberger
9046195d02
initial commit 2021-06-10 21:13:26 +02:00