Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 22984c6

Browse files
committedMay 28, 2025··
fix: Correctly adapt starlette BaseUser to A2A User
1 parent 3fa1d69 commit 22984c6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed
 

‎src/a2a/server/apps/starlette_app.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,20 @@
4545

4646
logger = logging.getLogger(__name__)
4747

48-
# Register Starlette User as an implementation of a2a.auth.user.User
49-
A2AUser.register(BaseUser)
48+
49+
class StarletteUserProxy(A2AUser):
50+
"""Adapts the Starlette User class to the A2A user representation."""
51+
52+
def __init__(self, user: BaseUser):
53+
self._user = user
54+
55+
@property
56+
def is_authenticated(self):
57+
return self._user.is_authenticated
58+
59+
@property
60+
def user_name(self):
61+
return self._user.display_name
5062

5163

5264
class CallContextBuilder(ABC):
@@ -64,7 +76,7 @@ def build(self, request: Request) -> ServerCallContext:
6476
user = UnauthenticatedUser()
6577
state = {}
6678
with contextlib.suppress(Exception):
67-
user = request.user
79+
user = StarletteUserProxy(request.user)
6880
state['auth'] = request.auth
6981
return ServerCallContext(user=user, state=state)
7082

0 commit comments

Comments
 (0)
Please sign in to comment.