fix(auth): report a missing Azure AD access token as a 400 - #3048
Open
lihongyuan99 wants to merge 1 commit into
Open
lihongyuan99 wants to merge 1 commit into
lihongyuan99 wants to merge 1 commit into
Conversation
The two Azure AD providers read the token endpoint response with
`json["access_token"]`. An OAuth error body such as
`{"error": "invalid_grant"}` therefore raised an unhandled `KeyError` and
surfaced as a 500 instead of the 400 the `if not token` check right below
already intends.
The other ten `get_token` implementations read the field with `.get()` and
raise `HTTPException(400, ACCESS_TOKEN_MISSING)`. Match that.
Co-Authored-By: WorkBuddy AI <noreply@workbuddy.ai>
lihongyuan99
requested review from
asvishnyakov,
hayescode and
sandangel
as code owners
September 18, 2026 10:53
dokterbob
approved these changes
Sep 18, 2026
dokterbob
enabled auto-merge
September 18, 2026 15:31
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Sep 18, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The two Azure AD providers (
AzureADOAuthProvider.get_tokenandAzureADHybridOAuthProvider.get_token) read the token endpoint response withjson["access_token"]. When the token endpoint replies with an OAuth error body — for example{"error": "invalid_grant"}— this raises an unhandledKeyError, which surfaces to the user as a 500.The
if not token: raise HTTPException(400, ACCESS_TOKEN_MISSING)check immediately below never runs, because the subscript raises before it is reached.Every other provider in this file reads the field with
.get()and raisesHTTPException(400, ACCESS_TOKEN_MISSING). There are 12access_tokenreads in total; the other 10 all use.get(...), andACCESS_TOKEN_MISSINGis referenced 11 times in the file. This change brings the two Azure AD providers in line with that convention.Changes
backend/chainlit/oauth_providers.py: usejson.get("access_token")in both Azure AD providers.backend/tests/test_oauth_providers.py: add two regression tests (plain top-leveltest_*functions, per AGENTS.md).Tests
cd backend python -m pytest tests/test_oauth_providers.py -qKeyError: 'access_token'; the pre-existingTestGithubOAuthProvider::test_github_get_token_missing_access_tokencontrol passes.57 passed(55 pre-existing + 2 new).Checklist
ruff check/ruff format --checkpass.Summary by cubic
Reports a missing Azure AD access token as a 400 instead of an unhandled 500 when the token endpoint returns an OAuth error body. Both Azure AD providers now read
access_tokenwith.get()to match the other providers, and regression tests cover the two providers.Written for commit eab2482. Summary will update on new commits.