Skip to content

feat(users): Microsoft sign-in over OpenID Connect with PKCE and nonce (#876) - #920

Merged
antosubash merged 6 commits into
mainfrom
feat/issue-876-microsoft-oidc
Nov 11, 2026
Merged

antosubash merged 6 commits into
mainfrom
feat/issue-876-microsoft-oidc

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

  • Microsoft sign-in now uses OpenID Connect. It runs on the tenant's v2.0 endpoints with PKCE (S256) and a nonce, and takes the identity from the validated ID token instead of Graph /me. The token checks reuse auth.oidc_common.jwks.JWKSCache:
    • RS256 signature against Entra's JWKS;
    • the exact issuer …/<tid>/v2.0;
    • aud and azp, exp/iat, and the nonce.
  • Tenant rules: a tenant GUID requires the token's tid to match it. organizations refuses personal accounts, and consumers accepts only them. Nothing is fetched at boot.
  • Account id: stays Graph-compatible: the oid for work and school accounts, and for personal accounts the last 16 hex digits of oid. Existing links keep matching with no migration.
  • Email: the optional upn claim when present, else preferred_username. It must be an email address, so a phone-number username counts as no email. The users: Microsoft (Entra) OAuth cannot sign in pre-approved accounts; add a trusted single-tenant UPN policy #873 trusted-tenant policy now also treats an idp claim naming another issuer as a guest.
  • The callback, for every provider:
    • It compares the state before consuming anything, so a forged reply can't spoil a pending login.
    • It keeps a per-login PKCE verifier and nonce for providers that opt in, and passes the whole token response to OAuthProvider.get_identity(token, login).
    • It logs why a provider sign-in was refused.
  • Docs: the users README, a new "Microsoft sign-in" section in docs/modules/users.md, and the CHANGELOG.
  • Behaviour change:
    • The Entra app registration needs the openid, profile and email delegated permissions. Graph User.Read is no longer requested.
    • Code that calls get_identity with an access-token string must now pass the token response dict.
  • Design: docs/superpowers/specs/2026-11-11-microsoft-oidc-provider-design.md.

Closes #876

Verification

  • Tests:
    • ID-token unit tests with a locally generated RSA key and JWKS: wrong audience, issuer, nonce or signature, expired, missing or bad oid/tid, foreign azp, the tenant-segment rules, a signed tid that doesn't match the issuer, the trust rule (guests by idp or #EXT#, a home-tenant idp, a list-valued idp), the account-id mapping, and upn versus an alternate-login alias;
    • flow tests: the S256 challenge matches the verifier sent to the token endpoint, fresh secrets per login, a missing verifier is refused, a wrong nonce gives a provider error, and a forged reply leaves the pending login intact;
    • the existing Microsoft flow tests now run on real signed tokens.
  • Local CI: make lint passes, make test-py has 8397 passed and 28 skipped, make test-js has 906 passed.
  • Not run: a sign-in against a live Entra tenant, as none is available locally (users: development-only discovery override and test fixtures for Microsoft sign-in (local IdP such as Keycloak) #879 adds a local identity-provider path).
  • Reviews: Sonnet security and maintainability (2 passes) and Codex (2 passes). Codex caught that a home-tenant idp was wrongly treated as a guest, and that an alternate-login alias replaced the UPN. Both are fixed.
  • Verification report: https://claude.ai/artifact/TsxTfyZkjZ96Sd1GEa2WvS

Report links are Claude Artifacts and start private. The author can share them from claude.ai/code/artifacts if reviewers need access.

Test plan

  • CI is green
  • Against a real Entra app: sign in through common and through a pinned tenant GUID. An existing Graph-era link still signs in, and a token from another tenant is refused.

https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4

#876)

The Microsoft provider signs in from the validated ID token (RS256 against
Entra's JWKS, exact issuer, aud/azp, exp/iat, nonce) instead of Graph /me.
A GUID tenant requires a matching tid; common/organizations/consumers check
the token's own issuer. The account id stays Graph-compatible, so existing
links keep matching. The generic callback passes the whole token response to
get_identity and keeps a per-login PKCE verifier and nonce in the session for
providers that opt in.

Claude-Session: https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4
Compare the OAuth state before spending the pending login; route identity by
client capability; a non-email preferred_username is no email; doc and
comment corrections from review.

Claude-Session: https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4
…876)

An idp naming the token's own tenant (v1 or v2 issuer) no longer blocks
trusted linking, and the optional upn claim wins over preferred_username so
alternate-login aliases keep matching invites by UPN.

Claude-Session: https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4
Non-string idp is a guest (no 500), log why a provider sign-in was refused,
docs say upn-first.

Claude-Session: https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-11T19:32:25.845991Z 1c6e585 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1c6e585
Status: ✅  Deploy successful!
Preview URL: https://baabb0ad.simple-module-python.pages.dev
Branch Preview URL: https://feat-issue-876-microsoft-oid.simple-module-python.pages.dev

View logs

@antosubash
antosubash merged commit 934bd74 into main Nov 11, 2026
17 checks passed
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.

users: make the Microsoft provider OIDC-based (validated ID-token claims oid/tid/sub) and pass the token response to get_identity

1 participant