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

New APIs Part 1 #2

Merged
merged 8 commits into from
Jan 21, 2025
Merged

New APIs Part 1 #2

merged 8 commits into from
Jan 21, 2025

Conversation

michel4j
Copy link
Collaborator

This pull request includes several significant changes to focusing on refactoring middleware, updating URL patterns, and improving authentication mechanisms for API calls. The most significant changes involve updating middleware to derive from MiddlewareMixin, and refactoring URL patterns to use path instead of re_path.

Middleware Refactoring:

  • Updated PermissionsMiddleware, TrustedAccessMiddleware, and other middleware classes to inherit from MiddlewareMixin for better compatibility with Django's middleware system. [1] [2]
  • Added new middleware APIAuthenticationMiddleware for handling API authentication using JWT tokens.

URL Patterns Update:

  • Refactored URL patterns in mxlive/remote/urls.py to use path instead of re_path and added JWT authentication views.
  • Moved version 2 API patterns to a new file mxlive/remote/urls_v2.py to separate versioned API endpoints.

Authentication Improvements:

  • Replaced VerificationMixin with AuthenticationRequiredMixin in view classes to ensure that only authenticated users can access certain endpoints without requiring URL signatures. [1] [2] [3]
  • Implemented helper functions get_v2_user and get_v3_user to handle user authentication for different API versions.

Code Cleanup:

  • Removed the make_table function from mxlive/lims/stats.py and replaced it with an import from mxlive.utils.stats.
  • Cleaned up imports and fixed variable naming inconsistencies in various view methods. [1] [2]

View Enhancements:

  • Updated Authenticated API view methods to use the authenticated request.user directly instead of fetching the user from URL parameters, aligning with the new authentication approach. [1] [2] [3]

- Add Django REST Framework, and the SimpleJWT plugin for REST framework dependencies
- Add API authentication middle ware which transparently checks API keys and sets `request.user`. Remote API views no longer have to independently authenticate each access.
- Add v3 URLs
- Add AuthenticationRequiredMixin for restricting access to authenticated APIs
- Refactor Remote Views
- Shifts calculation now returns IntegerField
- Refactored `make_table` function and moved it to mxlive.utils instead of duplicating code in `schedule.stats`
- Add False parameter to ipaddress.ip_network calls in middleware.
@michel4j michel4j merged commit 42de6fe into master Jan 21, 2025
@michel4j michel4j deleted the new-apis branch January 21, 2025 14:36
@michel4j michel4j restored the new-apis branch January 21, 2025 14:37
@michel4j michel4j deleted the new-apis branch January 21, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant