Skip to content

🔧 Refactor token retrieval methods in AuthX class#780

Merged
yezz123 merged 3 commits intomainfrom
type-error
Jan 4, 2026
Merged

🔧 Refactor token retrieval methods in AuthX class#780
yezz123 merged 3 commits intomainfrom
type-error

Conversation

@yezz123
Copy link
Copy Markdown
Owner

@yezz123 yezz123 commented Jan 4, 2026

Fixes: #745

Now you can use it like this

# Direct usage (what users expect)
token = await auth.get_token_from_request(request)
token = await auth.get_token_from_request(request, type="refresh")
token = await auth.get_token_from_request(request, optional=False)

# Then verify the token
payload = auth.verify_token(token)

Note

Refactors token retrieval API and dependencies

  • get_token_from_request is now an awaitable async method with type-safe overloads and optional locations, returning Optional[RequestToken] when optional=True or raising on missing token
  • ACCESS_TOKEN/REFRESH_TOKEN FastAPI dependencies updated to wrap _get_token_from_request via local async functions instead of returning a callable from get_token_from_request
  • _get_token_from_request now defaults locations to configured JWT_TOKEN_LOCATION and cleanly handles optional
  • Tests added/updated to cover direct async usage (access/refresh), optional behavior, missing-token error, and refresh token retrieval from headers; utils adjusted to depend on small async wrappers for route tokens

Written by Cursor Bugbot for commit 057a858. This will update automatically on new commits. Configure here.

- Updated ACCESS_TOKEN and REFRESH_TOKEN properties to use async functions for token retrieval.
- Modified get_token_from_request method to accept a Request object and handle token locations more flexibly.
- Enhanced documentation for better clarity on token retrieval behavior and usage examples.
- Introduced new async tests for `get_token_from_request` to validate direct access and refresh token retrieval.
- Added tests to ensure correct behavior when optional tokens are not provided, including raising appropriate errors.
- Refactored token retrieval routes in the FastAPI application to utilize async functions for better performance and clarity.
@yezz123 yezz123 added the bug Something isn't working label Jan 4, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
authx Ready Ready Preview, Comment Jan 4, 2026 11:05am

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.67%. Comparing base (38ed295) to head (057a858).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #780      +/-   ##
==========================================
+ Coverage   96.65%   96.67%   +0.01%     
==========================================
  Files          15       15              
  Lines         778      781       +3     
  Branches       76       77       +1     
==========================================
+ Hits          752      755       +3     
  Misses         20       20              
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…okens

- Added method overloads to `get_token_from_request` for better type handling of optional tokens.
- Refactored the method implementation to streamline the retrieval process based on the optional flag.
- Improved clarity and flexibility in token retrieval logic, ensuring consistent behavior for both required and optional tokens.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jan 4, 2026

@yezz123 yezz123 merged commit 1c78ea2 into main Jan 4, 2026
30 checks passed
@yezz123 yezz123 deleted the type-error branch January 4, 2026 11:06
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.

🐛 TypeError with await when using auth.get_token_from_request()

1 participant