Repository navigation
fix(api): Fix JWT authentication for /api/v1/me endpoints - #36410
Conversation
Add @Protect() and @permission_name decorators to CurrentUserRestApi endpoints to properly handle JWT authentication. This fixes a longstanding issue where JWT tokens were not properly setting the user context, causing 401 errors. - Add @Protect() decorator to handle both session and JWT auth - Add @permission_name decorators for proper permission management - Remove redundant authentication checks now handled by @Protect() - Add allow_browser_login = True for consistency with other APIs Fixes: #19525 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
CodeAnt AI is reviewing your PR. |
Code Review Agent Run #40fa9fActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Nitpicks 🔍
|
|
CodeAnt AI finished reviewing your PR. |
Co-authored-by: Claude <[email protected]> (cherry picked from commit 1f5df74)
I checked out the code that contains your modifications. My project uses guest tokens to access Superset. When invoking /api/v1/me/roles/, it returns 403 Forbidden. However, when I comment out @Protect() and @permission_name("read"), everything works fine. How can I fix this problem properly? |
Co-authored-by: Claude <[email protected]> (cherry picked from commit 1f5df74)
Co-authored-by: Claude <[email protected]>



User description
Summary
This PR fixes a longstanding issue where JWT authentication didn't work with the
/api/v1/meendpoints, causing 401 errors even with valid JWT tokens.The root cause was that the endpoints relied on Flask's
g.userbeing set, but there was no mechanism to populate it from JWT tokens in API requests. The@protect()decorator from Flask-AppBuilder properly handles both session-based and JWT-based authentication.Changes
@protect()decorator to handle both session and JWT authentication@permission_name()decorators for proper permission management@protect()allow_browser_login = Truefor consistency with other APIsTesting Instructions
/api/v1/security/loginBearer <token>/api/v1/me- should now return user info (previously returned 401)/api/v1/me/roles/- should now return user roles (previously returned 401)Fixes
Fixes: #19525
Additional Information
🤖 Generated with Claude Code
CodeAnt-AI Description
Restore JWT access to current-user APIs (/api/v1/me)
What Changed
Impact
✅ Fewer 401s for JWT-authenticated requests✅ Current-user endpoints accept both JWT and session authentication✅ Profile updates via API enforce write permission💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.