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

🔒 Easier Auth -- I'd like to pass a fastapi dependency to the add_routes method to secure them #354

Open
randypitcherii opened this issue Dec 30, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@randypitcherii
Copy link

  • right now I have to add my auth on langserve through middleware
  • this works in prod, so that's great!
  • in dev, it makes it so I have limited use of the swagger UI. That UI does not realize it needs to include auth headers in langserv endpoints as the dependency is not part of the route.

This is related to #294 -- fastapi dependency support lets me use swagger, but I'd still be blocked from securely accessing the playground until playground code supports auth headers.

Thanks! 🙏

@eyurtsev eyurtsev added the enhancement New feature or request label Jan 1, 2024
@eyurtsev
Copy link
Collaborator

eyurtsev commented Jan 1, 2024

@randypitcherii thanks for reporting! This makes sense.

For now, if you should be able to achieve that using the APIHandler object. See example here: https://github.com/langchain-ai/langserve/blob/main/examples/api_handler_examples/server.py

@randypitcherii
Copy link
Author

This helps a ton!! Thank you : )

@eyurtsev
Copy link
Collaborator

eyurtsev commented Jan 3, 2024

Added an ability to pass path dependencies to add_routes.

Examples using global dependencies and path dependencies have been added here: https://github.com/langchain-ai/langserve/tree/main/examples/auth

Neither of these options allows to do anything with the return value from the dependency as might be required to do implement logic specific to a particular user.

For those use cases, the best way right now is either using:

  1. APIHandler primtiives
  2. per request modifier function in add_routes

@eyurtsev eyurtsev self-assigned this Jan 4, 2024
eyurtsev added a commit that referenced this issue Jan 5, 2024
This PR adds an example that shows how to implement per user logic with sample Auth using the APIHandler primitive.

Another example for:
#354
@eyurtsev
Copy link
Collaborator

eyurtsev commented Jan 5, 2024

Path dependencies are available here: https://github.com/langchain-ai/langserve/releases/tag/v0.0.38

@eyurtsev
Copy link
Collaborator

eyurtsev commented Jan 5, 2024

Added some examples to the README for Auth: https://github.com/langchain-ai/langserve?tab=readme-ov-file#advanced

@randypitcherii Could you let me know if you encounter any issues on existing endpoints (except for playground)?

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

2 participants