Skip to content

Commit 3f318fc

Browse files
authored
Refresh expired access tokens using the stored refresh token
Refresh expired access tokens using the stored refresh token
2 parents 3f13cbb + 98e8cb5 commit 3f318fc

23 files changed

Lines changed: 449 additions & 43 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Added
6+
7+
- Automatic refresh-token redemption. When the stored access token is expired (or within a short skew window of expiring), the CLI now silently exchanges the persisted `refresh_token` for a fresh access token via the OAuth2 `refresh_token` grant and updates the keyring, instead of failing with `AUTH_TOKEN_EXPIRED` roughly an hour after login. The previous re-login behaviour remains as a fallback when no refresh token is stored or the refresh request is rejected. This resolves the standing "automatic refresh-token handling" known limitation (#16).
8+
39
## v0.2.4 - 2026-06-04
410

511
### Changed

docs/auth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Tokens are stored in the operating system keyring:
194194

195195
The config file stores profile settings, not access tokens.
196196

197-
Current known gap: automatic refresh-token handling is not yet release-grade. If a token expires and refresh does not happen, commands return `AUTH_TOKEN_EXPIRED` and the user must run `teams auth login` again.
197+
The CLI automatically redeems the stored refresh token when an access token is expired or near expiry, then updates the keyring with the refreshed token. If no refresh token is stored, or the identity platform rejects the refresh request, commands return `AUTH_TOKEN_EXPIRED` and the user must run `teams auth login` again.
198198

199199
## Diagnostics
200200

docs/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Teams/Graph can list chats that later fail message reads because the user is no
6363

6464
## Why did I get `AUTH_TOKEN_EXPIRED`?
6565

66-
The stored access token expired. The CLI requests `offline_access`, but automatic refresh-token handling is still a release-readiness gap. Run:
66+
The CLI automatically refreshes an expired access token using the stored refresh token (login requests `offline_access`), so this should be rare. You will still see `AUTH_TOKEN_EXPIRED` when no refresh token is stored or the refresh is rejected — for example the refresh token itself expired or was revoked. In that case, re-authenticate:
6767

6868
```bash
6969
teams auth login --device-code

docs/man/teams-auth.7

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ Tenant ID or tenant domain.
122122
Test-only switch used to avoid OS keyring access in automated tests. Do not use
123123
for real login sessions.
124124
.SH KNOWN GAPS
125-
Automatic refresh-token handling must be completed and validated before public
126-
commercial release. If a stored access token expires today, run:
125+
Stored access tokens are refreshed automatically when a refresh token is
126+
available. If the refresh token is missing, expired, revoked, or rejected by
127+
the identity platform, run:
127128
.PP
128129
.nf
129130
teams auth login --device-code

docs/release-readiness.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Live read-only validation passed against the OSO profile:
2929
Known live behavior:
3030

3131
- Some meeting chats can appear in `chat list` but reject message reads with `403` if the user is no longer in the roster.
32-
- Stored token expiry currently requires manual re-login.
32+
- Stored token expiry is handled through refresh-token redemption when a refresh token is available. `AUTH_TOKEN_EXPIRED` still means the refresh token is missing, expired, revoked, or rejected by the identity platform.
3333

3434
Entra app registration status as of 2026-05-27:
3535

@@ -120,15 +120,14 @@ Dependabot is configured to group GitHub Actions updates into one PR so the comp
120120
These must be resolved before marketing this as production-ready for external customers:
121121

122122
1. Publisher verification for the OSO Entra app.
123-
2. Automatic refresh-token handling and tests.
124-
3. Windows live validation using Windows Credential Manager.
125-
4. Controlled write/read smoke test in a dedicated Teams test channel.
126-
5. Documented admin-consent onboarding flow for customer tenants.
127-
6. Clear policy for unsupported Graph operations, tenant restrictions, and destructive commands.
128-
7. Security review of token storage, logs, and exported token behavior.
129-
8. Versioned release notes and upgrade guidance.
130-
9. Public website HTTPS fixed for `https://msteamscli.com/`; HTTP is live, but the current TLS certificate does not cover the hostname.
131-
10. Terms of service URL published and added to the Entra app branding.
123+
2. Windows live validation using Windows Credential Manager.
124+
3. Controlled write/read smoke test in a dedicated Teams test channel.
125+
4. Documented admin-consent onboarding flow for customer tenants.
126+
5. Clear policy for unsupported Graph operations, tenant restrictions, and destructive commands.
127+
6. Security review of token storage, logs, and exported token behavior.
128+
7. Versioned release notes and upgrade guidance.
129+
8. Public website HTTPS fixed for `https://msteamscli.com/`; HTTP is live, but the current TLS certificate does not cover the hostname.
130+
9. Terms of service URL published and added to the Entra app branding.
132131

133132
## Microsoft official trust checklist
134133

docs/troubleshooting.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ RUST_LOG=teams=debug teams chat list --output json
1818

1919
## `AUTH_TOKEN_EXPIRED`
2020

21-
Meaning: the keyring token is expired.
21+
Meaning: the keyring access token is expired and could not be refreshed automatically.
2222

23-
Current workaround:
23+
The CLI now silently redeems the stored refresh token when the access token is expired or about to expire, so this error normally only appears when no refresh token is stored or the refresh request is rejected (for example the refresh token expired or was revoked).
24+
25+
Resolution:
2426

2527
```bash
2628
teams auth login --device-code
2729
```
2830

29-
Release-readiness note: automatic refresh-token handling still needs to be completed and validated.
30-
3131
## `AUTH_FAILED` or login fails
3232

3333
Check:

0 commit comments

Comments
 (0)