Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set user on the X-Ray segment from ASGI scope or framework's request #15

Open
garyd203 opened this issue Aug 19, 2020 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@garyd203
Copy link
Owner

garyd203 commented Aug 19, 2020

If the X-Ray middleware is called after any authentication/session middleware, then the ASGI scope will probably contain some sort of reference to the authenticated user, which we can use to automatically set the user field on the Segment.

Here's some examples of how different web frameworks set the user:

  • aiohttp has no built-in user concept.
  • aiohttp-jwt will store the decoded JWT in a configurable key on the request (default payload)
  • FastAPI does what Starlette does
  • Piccolo extends Starlette's AuthenticationMiddleware (see below), and also adds a secret_token_user key to the scope.
  • Starlette's builtin AuthenticationMiddleware adds a user key to the scope and a user attribute on the request. So any of scope["user"].display_name or request.user.display_name is correct (but also check user.is_authenticated)
@garyd203 garyd203 added the enhancement New feature or request label Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant