Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Unified authentication and logging middleware #523

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

martastain
Copy link
Member

@martastain martastain commented Feb 25, 2025

This pull request involves significant changes to the authentication middleware and the initialization of the server, focusing on refactoring and improving the codebase. The most important changes include the removal of deprecated dependencies, the addition of new authentication methods, and the restructuring of the server initialization process.

  • Added new authentication middleware to handle user authentication via API keys and access tokens, including methods to extract tokens from requests and validate them.
  • Refactored the dep_current_user and dep_current_user_optional functions to use the new authentication middleware, removing redundant code and improving clarity.
  • Introduced a new lifespan management module to handle server startup and shutdown processes, including loading access groups, starting background tasks, and initializing addon endpoints.
  • Updated the server initialization to use the new lifespan module and added the new authentication middleware, removing the old logging middleware.

Improved logging

The new authentication middleware updates the log context, so all log messages produced by calling endpoints now contain information about the current user and the response status and can be matched by request_id

In the following example, users changes the status of an entity. example addon that listens to status_changed events processes the emitted event after the request ended, but logging messages triggered still contain the original context.

image

@martastain martastain self-assigned this Feb 25, 2025
@martastain martastain added the type: enhancement Improvement of existing functionality or minor addition label Feb 25, 2025
@martastain martastain changed the title refactor: auth middleware (w.i.p.) API: Unified authentication and logging middleware Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improvement of existing functionality or minor addition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant