Windows: login succeeds but token storage fails — bundle exceeds Credential Manager's 2560-char blob limit
Summary
On Windows, teams auth login completes the OAuth flow successfully but fails at the token-persistence step. The whole token bundle is written to Windows Credential Manager as a single credential blob, and Entra token bundles routinely exceed the platform's blob-size limit.
{
"success": false,
"error": {
"code": "KEYRING_ERROR",
"message": "Keyring error: Failed to store token: Attribute 'password encoded as UTF-16' is longer than platform limit of 2560 chars"
}
}
The result: authentication genuinely succeeded in Entra, but the CLI is left unauthenticated. teams auth status reports authenticated: false and no entry appears in Credential Manager. The CLI is unusable on this machine — every login is discarded.
Environment
- teams-cli 0.4.0,
x86_64-pc-windows-msvc(release zip) - Windows 11 Pro 26200
- BYO app registration (
auth_app = "byo"), device-code flow - Non-admin user, per-user install
Measurements
I ran the device-code flow manually against the same tenant and app registration with the CLI's exact default_delegated_scopes, and measured the returned tokens:
| Component | Size |
|---|---|
access_token |
2931 chars |
refresh_token |
1524 chars |
| Serialised JSON bundle as stored | 4875 chars |
| Credential Manager limit | 2560 chars |
The access token alone (2931) already exceeds the limit, before the refresh token is concatenated.
Why reducing scopes does not help
The obvious mitigation — request fewer scopes to shrink the scp claim — does not work. Entra issues an access token covering all consented scopes for the resource, not just those requested. Requesting the 10 default delegated scopes returned a token whose scp claim also contained Files.ReadWrite.All, OnlineMeetings.Read, People.Read and others consented on the app registration. Token size is therefore a property of the tenant's consent grant, not of what the CLI asks for, and is not controllable from the client side.
Any Windows user in a tenant with a moderately broad consent grant will hit this. It is not an edge case.
Repro
- Windows, BYO app registration with several consented delegated Graph permissions.
teams auth login --device-code --client-id <id> --tenant-id <id>- Complete the browser sign-in.
- Observe
KEYRING_ERROR; thenteams auth status→authenticated: false.
Notes on the fix
docs/teams-cli-prd.md:172 and :894 both specify an encrypted-file fallback for exactly this situation:
Encrypted local cache: Tokens stored via OS keyring (macOS Keychain, Windows Credential Manager, Linux Secret Service/libsecret) with fallback to encrypted file (
~/.config/teams-cli/tokens.enc).
but the Phase 1 checklist item "Token caching with keyring + encrypted file fallback" is unchecked and the fallback does not appear to exist in the shipped binary.
Two approaches that would resolve it:
- Chunk the blob across multiple Credential Manager entries (
teams-cli:<profile>:0,:1, …), reassembling on read. Keeps everything in the OS credential store. Note thatstore_tokencurrently writes one item; chunking needs matching cleanup inauth logoutso stale chunks are not orphaned. - Implement the specced fallback, using DPAPI (
CryptProtectData,CurrentUserscope) on Windows so the file is bound to the user account rather than relying on a hand-rolled key derivation.
Chunking is probably the smaller change and keeps the existing security properties.
A narrower interim improvement regardless of which path is taken: the error currently surfaces as a generic KEYRING_ERROR after a successful sign-in, which makes it look like the login failed. Detecting the size overflow specifically and saying so — ideally alongside the TEAMS_CLI_ACCESS_TOKEN escape hatch — would save the next person the investigation.