# OAuth2 错误：invalid_grant — 刷新令牌已过期或已被撤销

- **ID:** `api/oauth2-invalid-grant-refresh-token-expired`
- **领域:** api
- **类别:** auth_error
- **错误码:** `invalid_grant`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

用于获取新访问令牌的刷新令牌已被撤销、过期或超出轮换限制，导致授权服务器拒绝授权。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| OAuth 2.0 (RFC 6749) | active | — | — |
| Google OAuth 2.0 (2023+) | active | — | — |
| Auth0 OIDC (2024) | active | — | — |

## 解决方案

1. ```
   实现刷新令牌轮换：每次成功刷新令牌后，使旧刷新令牌失效并颁发新令牌。使用像 `oauthlib` 或 `google-auth` 这样的库自动处理轮换。示例：`credentials.refresh(request)` 配合 `google.oauth2.credentials`。
   ```
2. ```
   安全存储刷新令牌并监控其过期时间。如果出现此错误，提示用户通过完整的 OAuth 流程重新认证。示例：捕获 `RefreshError` 并重定向到授权端点。
   ```
3. ```
   通过检查授权服务器的令牌内省端点来验证刷新令牌是否被撤销。示例：`POST /introspect` 参数 `token=<refresh_token>` 和 `token_type_hint=refresh_token`。
   ```

## 无效尝试

- **** — The token is already expired or revoked; reusing it will still fail. (90% 失败率)
- **** — The underlying issue (e.g., token rotation limit or revocation) persists, causing the new refresh token to fail again. (70% 失败率)
- **** — The error is a permanent grant rejection, not a transient network issue; retries will not succeed. (80% 失败率)
