Commit f84be25
committed
fix(auth): update API token last_used for MCP Streamable HTTP requests
The MCP-specific auth handler (_StreamableHttpAuthHandler._auth_jwt)
performs its own JWT verification via verify_credentials() but did not
call _update_api_token_last_used_sync(), causing API token last_used
timestamps to remain stale when accessing virtual servers via
/servers/{id}/mcp.
Additionally, auth_method was hardcoded to "jwt" regardless of token
type, preventing TokenUsageMiddleware from recognising and logging
API token requests on MCP transport paths.
Changes:
- Detect API tokens (auth_provider == "api_token") and legacy tokens
(DB JTI lookup) in _auth_jwt()
- Call _update_api_token_last_used_sync() for API tokens (rate-limited)
- Set auth_method dynamically ("api_token" vs "jwt")
- Propagate auth_method, jti, and user_email to ASGI scope state for
TokenUsageMiddleware
Signed-off-by: kimsehwan96 <sktpghks138@gmail.com>1 parent 8577b4f commit f84be25
3 files changed
Lines changed: 389 additions & 2 deletions
File tree
- mcpgateway/transports
- tests
- playwright/security
- unit/mcpgateway/transports
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3642 | 3642 | | |
3643 | 3643 | | |
3644 | 3644 | | |
| 3645 | + | |
| 3646 | + | |
| 3647 | + | |
| 3648 | + | |
| 3649 | + | |
| 3650 | + | |
| 3651 | + | |
| 3652 | + | |
| 3653 | + | |
| 3654 | + | |
| 3655 | + | |
| 3656 | + | |
| 3657 | + | |
| 3658 | + | |
| 3659 | + | |
| 3660 | + | |
| 3661 | + | |
| 3662 | + | |
| 3663 | + | |
| 3664 | + | |
| 3665 | + | |
| 3666 | + | |
| 3667 | + | |
| 3668 | + | |
| 3669 | + | |
| 3670 | + | |
| 3671 | + | |
| 3672 | + | |
| 3673 | + | |
| 3674 | + | |
| 3675 | + | |
| 3676 | + | |
| 3677 | + | |
| 3678 | + | |
| 3679 | + | |
| 3680 | + | |
| 3681 | + | |
| 3682 | + | |
| 3683 | + | |
3645 | 3684 | | |
3646 | 3685 | | |
3647 | 3686 | | |
3648 | 3687 | | |
3649 | 3688 | | |
3650 | | - | |
| 3689 | + | |
3651 | 3690 | | |
3652 | 3691 | | |
3653 | 3692 | | |
| |||
3667 | 3706 | | |
3668 | 3707 | | |
3669 | 3708 | | |
3670 | | - | |
| 3709 | + | |
3671 | 3710 | | |
3672 | 3711 | | |
3673 | 3712 | | |
| |||
Lines changed: 77 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
0 commit comments