Skip to content

fix(auth): 🐛 Fix auth mechanism after testing and integration#5

Merged
faizanazim11 merged 1 commit intomasterfrom
fix/auth-mechanism
Oct 4, 2025
Merged

fix(auth): 🐛 Fix auth mechanism after testing and integration#5
faizanazim11 merged 1 commit intomasterfrom
fix/auth-mechanism

Conversation

@faizanazim11
Copy link
Copy Markdown
Contributor

This pull request introduces several improvements and refactors to the authentication server, focusing on upgrading Python compatibility, enhancing token handling, modernizing the gRPC refresh service, and improving configuration and dependency management. The changes streamline async operations, improve error handling and logging, and update dependencies for better maintainability and performance.

Python and Dependency Upgrades

  • Updated Python version requirement from 3.12 to 3.13 in .python-version and pyproject.toml, and bumped project version to 0.1.3. Added new dependencies (grpcio-tools, jetpack) and moved grpcio-tools out of the dev group. [1] [2] [3]

Authentication and Token Handling

  • Introduced CustomOAuth2PasswordBearer to extract tokens from cookies, replacing the default scheme throughout the codebase for improved authentication flexibility. [1] [2] [3]
  • Fixed usage of Annotated for Cookie and Header parameters in auth_validator.py to use correct FastAPI syntax.

gRPC Refresh Service Modernization

  • Refactored the gRPC refresh service to use async lifecycle management: server startup and shutdown are now handled asynchronously within FastAPI's lifespan context, ensuring proper resource cleanup and background task management. [1] [2] [3] [4] [5] [6]
  • Updated the refresh handler to use async/await, improved error handling, and added logging for better observability. The refresh response now consistently returns an empty protobuf message. [1] [2]

Redis and Token Storage Improvements

  • Refactored Redis connector initialization to use async connection and improved token storage/retrieval by serializing data with orjson. Also, updated expiration logic for tokens. [1] [2] [3]
  • Added logging to refresh restriction logic for better debugging and monitoring.

Protobuf and gRPC Version Updates

  • Added the standard google/protobuf/empty.proto file for compatibility with gRPC services. Updated generated gRPC version to 1.75.1 for protocol buffer files. [1] [2]

Copilot AI review requested due to automatic review settings October 4, 2025 21:58
@faizanazim11 faizanazim11 self-assigned this Oct 4, 2025
@faizanazim11 faizanazim11 added the bug Something isn't working label Oct 4, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR upgrades Python compatibility to 3.13, modernizes the gRPC refresh service with async lifecycle management, and refactors token handling to use cookies and async Redis operations with orjson serialization.

  • Introduces a custom OAuth2 scheme to read tokens from cookies and updates configuration handling.
  • Converts gRPC refresh server startup/shutdown to async within FastAPI lifespan and refactors the refresh handler to async with improved logging.
  • Refactors Redis connectors and token storage to async patterns and orjson-based serialization.

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/tp_auth_serverside/pb/refresh_pb2_grpc.py Bumps generated gRPC version string to 1.75.1.
src/tp_auth_serverside/db/memorydb/refresh.py Adds logging and clarifies exists() check result usage.
src/tp_auth_serverside/db/memorydb/login.py Switches hash value serialization to orjson and adjusts expiration call.
src/tp_auth_serverside/db/memorydb/init.py Moves to async MemDBConnector and initializes connections with asyncio.run at import time.
src/tp_auth_serverside/core/handler/refresh_handler.py Makes refresh RPC handler async, adds logging, and returns Empty responses.
src/tp_auth_serverside/core/fastapi_configurer.py Adds async lifespan for gRPC server, optional dependency injection to token route, and correlation ID middleware.
src/tp_auth_serverside/config.py Replaces OAuth2PasswordBearer with custom scheme, tweaks settings parsing for algorithm/scopes.
src/tp_auth_serverside/auth/custom_auth_scheme.py Introduces cookie-based OAuth2PasswordBearer override.
protos/google/protobuf/empty.proto Adds well-known Empty proto source.
.python-version Updates Python version to 3.13.
pyproject.toml Bumps project version and updates dependencies (Python 3.13, grpcio-tools, jetpack).

@faizanazim11 faizanazim11 merged commit a3ccd30 into master Oct 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants