Repository navigation
Let management assert a member's app identity to connectors - #246
Merged
tnkuehne merged 1 commit intoNov 20, 2026
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | bc81f07 | Nov 20 2026, 06:20 PM |
tnkuehne
force-pushed
the
feat/user-connection-identity
branch
2 times, most recently
from
November 20, 2026 17:43
2100d48 to
06fd28b
Compare
tnkuehne
added a commit
that referenced
this pull request
Nov 20, 2026
Better Auth stores OAuth access and refresh tokens in plain text unless `account.encryptOAuthTokens` is set; its option documentation calls plain storage "a security risk if your database is compromised". Management saves them for company SSO and social sign-in but never reads them, so a database copy would carry usable grants to people's company and social accounts. ## What changes - Management sets `account.encryptOAuthTokens: true`. Better Auth encrypts access and refresh tokens with the authentication secret (XChaCha20-Poly1305) and decrypts them where it reads them. - Tokens saved before stay readable (Better Auth recognizes plain values) and are replaced with encrypted ones at the next sign-in. - Better Auth keeps ID tokens unencrypted. The Entra migration in #246 reads them, so this PR does not depend on the merge order. ## Tests - The Entra login edge test checks that the saved access token differs from the issued one and decrypts to it with the authentication secret. - All Vitest suites pass, as do the edge, installation and Entra suites. <!-- greptile_comment --> <!-- greptile_summary --> <h2><a href="https://app.greptile.com/api/retrigger?id=114375365&sig=ca646197c96ad091136eb9197185750bd193c6790d8caff5dd10834820a44341"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a><a href="https://app.greptile.com/-/switch-tenant?tenant=mendra&next=%2Fwidefleet%2Fwidefleet%2Fpull%2F252&utm_source=greptile_review&utm_medium=github&utm_campaign=view_in_greptile"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img alt="View in Greptile" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2" align="right"></picture></a>Confidence Score: 5/5</h2> <!-- greptile-impact-verdict --> The PR appears safe to merge; no actionable issues were found. <details open><summary><h3>Summary</h3></summary> Management enables Better Auth’s encryption for saved provider access and refresh tokens. - Company and social sign-ins save provider access and refresh tokens encrypted. </details> <!-- greptile_confidence_score:5 --> <sub>Reviews (1) · Last reviewed commit: ["Encrypt provider tokens that management ..."](44196e3) · [Reviewed by Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub> <!-- /greptile_comment -->
Connectors store each user's account under the app identity that app sign-in issues: the company issuer and subject, or the Widefleet account when apps sign in through Widefleet. My connections needs management to name that identity for the signed-in member. Management already knows it. With required company SSO the member's SSO account links them to their company identity, and both sign-ins use the same registration. Only Entra differed: app sign-in identifies users by object ID, while Better Auth's SSO plugin keys accounts by the registration's pairwise `sub`. - A patch adds an `accountSubject` option to `@better-auth/sso`, as Better Auth's own Microsoft provider moved to `oid` in 1.7.0. Management sets it for Entra providers, checking the tenant; other providers keep `sub`. - Migration 0034 rekeys existing Entra accounts from the ID token saved at their last sign-in. - The MCP CLI login finds the account by the app identity's subject; the separate account subject is gone. The runtime accepts `UserConnection` calls only through authenticated management. It checks that the identity's issuer is the one app sign-in publishes, finds the organization's app and passes the connector a caller proof valid for five minutes. App access groups do not apply: a member manages only their own account, while using the app still requires them. It allows only `status`, `prepare` and `disconnect`, checks their results, keeps launch links on the connector's origin and does not relay connector errors.
tnkuehne
force-pushed
the
feat/user-connection-identity
branch
from
November 20, 2026 18:19
06fd28b to
bc81f07
Compare
Comment on lines
+19
to
+23
| )::jsonb ->> 'oid' AS oid | ||
| FROM account | ||
| JOIN sso_provider ON sso_provider.provider_id = account.provider_id | ||
| WHERE sso_provider.app_identity_type = 'entra' | ||
| AND account.id_token ~ '^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.' |
There was a problem hiding this comment.
Unreadable tokens stop upgrades
If a saved Entra id_token contains a dotted but unreadable value such as e30.eA.signature, it passes this filter but decodes to x. The ::jsonb cast then throws instead of skipping the row. Migration 0034 fails, preventing management from starting.
Catch decoding and parsing failures per row, and add a dotted unreadable token to the migration test.
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.
Second layer of the personal connections stack. Management names a member's app identity from what it already knows, and the runtime accepts
UserConnectioncalls only from management.Background
Connectors store each user's account under the app identity that app sign-in issues: issuer plus subject. My connections runs in management, so management must name that identity for the signed-in member.
(PLATFORM_URL/api/auth, user ID): apps sign in through Widefleet(issuer, sub)accountrow; management and app sign-in use the same registration, so thesubis the same(issuer, oid)accountrow, but keyed by the registration's pairwisesubOnly Entra differed. Entra's
subis pairwise per app registration; app sign-in uses the stable object ID, as Better Auth's own Microsoft provider does since 1.7.0 (#10204).@better-auth/ssostill keys every OIDC account bysub, and 1.7.0 removed itsmapping.id.What changes
Management keys Entra accounts by object ID
patches/@[email protected]adds anaccountSubjectoption, like Generic OAuth's: the account identifier of a verified OIDC sign-in, defaulting tosub.oidfor Entra providers and rejects tokens from another tenant. Other providers keepsub.0034rekeys existing Entra SSO accounts from the ID token saved at their last sign-in. An ID token that is not a readable JWT leaves its account unchanged.createAppUserIdentityreturns(issuer, subject, name):403.Runtime endpoint
/.well-known/widefleet/user-connections, reachable only through authenticated runtime management:409).UserConnection(404otherwise). App access groups do not apply: a member manages only their own account, while using the app still requires them.status,prepareanddisconnect, checks their results, keeps launch links on the connector's origin and does not relay connector errors.Tests
app-user-identity.integration.test.ts, real SSO callback against an Entra fixture whoseoiddiffers fromsub:submanaged-oauth-runtime.test.ts, real loader: unauthenticated and malformed requests, a foreign issuer, a foreign app, access groups, isolation between users, and disconnection.mcp-cli-login.integration.test.tsand the Entra login edge test now expect the object ID.Fix the unreadable-token migration path before merging; one affected row can prevent management from starting.
Findings
Summary
Management can name a member's app identity and call personal connector controls through authenticated runtime management.
Diagram
Reviews (6) · Last reviewed commit: "Let management assert a member's app ide..." · Reviewed by Greptile