Repository navigation
Conversation
urskog84
force-pushed
the
entra-oauth-client
branch
from
August 16, 2026 15:17
8bea150 to
f1cf9c8
Compare
Closes AnswerDotAI#718. Entra needs two things beyond the usual client boilerplate. It normalises the scopes it grants, so they don't always match what was requested: asking for `https://graph.microsoft.com/User.Read`, the form Microsoft's samples use, comes back as plain `User.Read`, and oauthlib raises `Warning: Scope has changed` on the difference. `parse_request_body_response` skips that check, then restores the requested scope. And directory-level identity lives in the `id_token` rather than in Graph's userinfo, so `get_info` merges the two, making `oid` (immutable user id) and `tid` (tenant) available to `get_auth`. `tenant_id` is required rather than defaulting to 'common', so that the single-tenant case - where Entra itself turns away other directories - is what you get unless you ask for more. Verified against a live single-tenant app registration: login, token exchange, Graph userinfo and logout. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
urskog84
force-pushed
the
entra-oauth-client
branch
from
November 30, 2026 20:35
f1cf9c8 to
5d024b6
Compare
Author
|
Rebased on current CI is waiting for workflow approval since this comes from a fork. Could a maintainer approve the run and take a look when there's time? Happy to adjust the API or cut scope if that makes it easier to review. |
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.
Closes #718.
Adds
EntraAppClient(also exported asAzureAppClient) for Microsoft Entra ID, formerly Azure AD.Why it isn't just another endpoint triple
https://graph.microsoft.com/User.Read, the form Microsoft's own samples use, comes back asUser.Read, and oauthlib then raisesWarning: Scope has changedat the token exchange.parse_request_body_responseskips that check and restores the requested scope afterwards.oid(the user's immutable ID) andtid(the tenant they signed in from) are only in theid_token, soget_info/get_info_asyncmerge its claims into the userinfo. The payload is decoded with stdlib base64 and no signature check, since the token comes straight from the token endpoint over TLS.API choices worth a second opinion
tenant_idis required rather than defaulting to'common', so the default case is the one where Entra itself rejects other directories.'organizations'and'common'still work; the docs say those need atidcheck inget_auth.identstayssub, as for the other clients. Setclient.id_key = 'oid'for the directory-wide ID.logout_link()is included because/logoutalone leaves the user signed in to Microsoft.infoalso carries the id_token's metadata claims (aud,iss,exp, ...). Happy to filter those out if you'd rather keepinfolean.Testing
tests/test_oauth.pycovers the same paths offline against mocked endpoints: authorize URL and pass-through params, token exchange payload, scope restoration, sync and asyncretr_info,id_keyoverride, bothlogout_linkforms.nbs/api/08_oauth.ipynbis the edited source;fasthtml/oauth.pyand_modidx.pycome fromnbdev-export. Rebased on currentmain.🤖 Generated with Claude Code