Skip to content

Development#93

Merged
michael-pisman merged 3 commits intomainfrom
development
Jul 30, 2025
Merged

Development#93
michael-pisman merged 3 commits intomainfrom
development

Conversation

@michael-pisman
Copy link
Member

This pull request introduces several updates to the authentication flow and code structure, focusing on improving token refresh functionality, refining exception handling, and enhancing code readability. The changes include modifications to the refresh_token_with_clientID function, updates to the authentication route, and various formatting improvements in the documents module.

Authentication Flow Updates:

  • Updated refresh_token_with_clientID to accept refresh_token as a direct parameter instead of parsing it from the body, simplifying the function's input handling (src/unipoll_api/actions/authentication.py).
  • Replaced exceptions with missing parentheses in InvalidAccessToken, InvalidClientID, and refreshTokenExpired to ensure proper exception instantiation (src/unipoll_api/actions/authentication.py) [1] [2].

Route Updates:

  • Modified the /jwt/postman_refresh endpoint to use Form parameters (refresh_token and grant_type) instead of a JSON body, aligning with OAuth2 standards (src/unipoll_api/routes/authentication.py) [1] [2].
  • Re-enabled the import of authentication schemas for better schema validation (src/unipoll_api/routes/authentication.py).

Code Formatting and Readability:

  • Reformatted multi-line function definitions and method calls for better readability in src/unipoll_api/documents.py [1] [2] [3] [4] [5] [6] [7].
  • Reorganized imports in src/unipoll_api/documents.py and src/unipoll_api/routes/authentication.py to follow PEP 8 import grouping standards [1] [2].

Copilot AI review requested due to automatic review settings July 30, 2025 06:39
Copy link

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 pull request improves the authentication flow by standardizing OAuth2 token refresh endpoints and enhances code readability through formatting improvements. The changes focus on simplifying the refresh token function interface and aligning with OAuth2 standards.

  • Updates the refresh token endpoint to use proper Form parameters instead of parsing request bodies
  • Fixes exception handling by adding missing parentheses to exception instantiations
  • Reformats code across multiple files for better readability and PEP 8 compliance

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/unipoll_api/routes/authentication.py Updates refresh token endpoint to use Form parameters and re-enables authentication schemas import
src/unipoll_api/actions/authentication.py Simplifies refresh_token_with_clientID function signature and fixes exception instantiation
src/unipoll_api/documents.py Reformats imports and function definitions for improved code readability

# Make sure the access token exists in the database
if token_data is None:
raise AuthExceptions.InvalidAccessToken()
raise AuthExceptions.InvalidAccessToken
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Exception class is not being instantiated. Should be raise AuthExceptions.InvalidAccessToken() to properly raise the exception.

Suggested change
raise AuthExceptions.InvalidAccessToken
raise AuthExceptions.InvalidAccessToken()

Copilot uses AI. Check for mistakes.
client_id = base64.b64decode(client_id)
if PydanticObjectId(str(client_id, "utf-8")[:-1]) != user.id:
raise AuthExceptions.InvalidClientID()
raise AuthExceptions.InvalidClientID
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Exception class is not being instantiated. Should be raise AuthExceptions.InvalidClientID() to properly raise the exception.

Suggested change
raise AuthExceptions.InvalidClientID
raise AuthExceptions.InvalidClientID()

Copilot uses AI. Check for mistakes.
# If not, delete all tokens associated with the user and return an error
await strategy.destroy_token_family(user)
raise AuthExceptions.refreshTokenExpired()
raise AuthExceptions.refreshTokenExpired
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Exception class is not being instantiated. Should be raise AuthExceptions.refreshTokenExpired() to properly raise the exception.

Suggested change
raise AuthExceptions.refreshTokenExpired
raise AuthExceptions.refreshTokenExpired()

Copilot uses AI. Check for mistakes.
if not parent:
ResourceNotFound(self.parent_resource.ref.collection,
self.parent_resource.ref.id)
ResourceNotFound(
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Exception class is not being instantiated properly. Should be raise ResourceNotFound(...) to properly raise the exception.

Copilot uses AI. Check for mistakes.
Signed-off-by: Michael Pisman <mpisman@ucmerced.edu>
@michael-pisman michael-pisman merged commit 6f98e21 into main Jul 30, 2025
1 check failed
@michael-pisman michael-pisman deleted the development branch July 30, 2025 06:46
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