Skip to content

Commit 374a0b4

Browse files
committed
Rename AuthInfo to AccessToken
1 parent 60da682 commit 374a0b4

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

src/mcp/server/auth/handlers/revoke.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
AuthenticationError,
1515
ClientAuthenticator,
1616
)
17-
from mcp.server.auth.provider import AuthInfo, OAuthServerProvider, RefreshToken
17+
from mcp.server.auth.provider import AccessToken, OAuthServerProvider, RefreshToken
1818

1919

2020
class RevocationRequest(BaseModel):
@@ -75,7 +75,7 @@ async def handle(self, request: Request) -> Response:
7575
if revocation_request.token_type_hint == "refresh_token":
7676
loaders = reversed(loaders)
7777

78-
token: None | AuthInfo | RefreshToken = None
78+
token: None | AccessToken | RefreshToken = None
7979
for loader in loaders:
8080
token = await loader(revocation_request.token)
8181
if token is not None:

src/mcp/server/auth/middleware/auth_context.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from starlette.responses import Response
66

77
from mcp.server.auth.middleware.bearer_auth import AuthenticatedUser
8-
from mcp.server.auth.provider import AuthInfo
8+
from mcp.server.auth.provider import AccessToken
99

1010
# Create a contextvar to store the authenticated user
1111
# The default is None, indicating no authenticated user is present
@@ -14,15 +14,15 @@
1414
)
1515

1616

17-
def get_current_auth_info() -> AuthInfo | None:
17+
def get_access_token() -> AccessToken | None:
1818
"""
19-
Get the auth info from the current context.
19+
Get the access token from the current context.
2020
2121
Returns:
22-
The auth info if an authenticated user is available, None otherwise.
22+
The access token if an authenticated user is available, None otherwise.
2323
"""
2424
auth_user = auth_context_var.get()
25-
return auth_user.auth_info if auth_user else None
25+
return auth_user.access_token if auth_user else None
2626

2727

2828
class AuthContextMiddleware(BaseHTTPMiddleware):

src/mcp/server/auth/middleware/bearer_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
from starlette.requests import HTTPConnection
1111
from starlette.types import Scope
1212

13-
from mcp.server.auth.provider import AuthInfo, OAuthServerProvider
13+
from mcp.server.auth.provider import AccessToken, OAuthServerProvider
1414

1515

1616
class AuthenticatedUser(SimpleUser):
1717
"""User with authentication info."""
1818

19-
def __init__(self, auth_info: AuthInfo):
19+
def __init__(self, auth_info: AccessToken):
2020
super().__init__(auth_info.client_id)
21-
self.auth_info = auth_info
21+
self.access_token = auth_info
2222
self.scopes = auth_info.scopes
2323

2424

src/mcp/server/auth/provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RefreshToken(BaseModel):
3333
expires_at: int | None = None
3434

3535

36-
class AuthInfo(BaseModel):
36+
class AccessToken(BaseModel):
3737
token: str
3838
client_id: str
3939
scopes: list[str]
@@ -91,7 +91,7 @@ class TokenError(Exception):
9191
# OK to add fields to subclasses which should not be exposed externally.
9292
AuthorizationCodeT = TypeVar("AuthorizationCodeT", bound=AuthorizationCode)
9393
RefreshTokenT = TypeVar("RefreshTokenT", bound=RefreshToken)
94-
AuthInfoT = TypeVar("AuthInfoT", bound=AuthInfo)
94+
AuthInfoT = TypeVar("AuthInfoT", bound=AccessToken)
9595

9696

9797
class OAuthServerProvider(

tests/server/fastmcp/auth/test_auth_integration.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from starlette.applications import Starlette
1919

2020
from mcp.server.auth.provider import (
21-
AuthInfo,
21+
AccessToken,
2222
AuthorizationCode,
2323
AuthorizationParams,
2424
OAuthServerProvider,
@@ -88,7 +88,7 @@ async def exchange_authorization_code(
8888
refresh_token = f"refresh_{secrets.token_hex(32)}"
8989

9090
# Store the tokens
91-
self.tokens[access_token] = AuthInfo(
91+
self.tokens[access_token] = AccessToken(
9292
token=access_token,
9393
client_id=client.client_id,
9494
scopes=authorization_code.scopes,
@@ -151,7 +151,7 @@ async def exchange_refresh_token(
151151
new_refresh_token = f"refresh_{secrets.token_hex(32)}"
152152

153153
# Store the new tokens
154-
self.tokens[new_access_token] = AuthInfo(
154+
self.tokens[new_access_token] = AccessToken(
155155
token=new_access_token,
156156
client_id=client.client_id,
157157
scopes=scopes or token_info.scopes,
@@ -172,27 +172,27 @@ async def exchange_refresh_token(
172172
refresh_token=new_refresh_token,
173173
)
174174

175-
async def load_access_token(self, token: str) -> AuthInfo | None:
175+
async def load_access_token(self, token: str) -> AccessToken | None:
176176
token_info = self.tokens.get(token)
177177

178178
# Check if token is expired
179179
# if token_info.expires_at < int(time.time()):
180180
# raise InvalidTokenError("Access token has expired")
181181

182-
return token_info and AuthInfo(
182+
return token_info and AccessToken(
183183
token=token,
184184
client_id=token_info.client_id,
185185
scopes=token_info.scopes,
186186
expires_at=token_info.expires_at,
187187
)
188188

189-
async def revoke_token(self, token: AuthInfo | RefreshToken) -> None:
189+
async def revoke_token(self, token: AccessToken | RefreshToken) -> None:
190190
match token:
191191
case RefreshToken():
192192
# Remove the refresh token
193193
del self.refresh_tokens[token.token]
194194

195-
case AuthInfo():
195+
case AccessToken():
196196
# Remove the access token
197197
del self.tokens[token.token]
198198

0 commit comments

Comments
 (0)