-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Authentication for Custom API #1785
Comments
I found a similar issue that might be helpful:
To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
So it always fail right? It can't authenticate any user? What authentication is setup? Oauth? password? |
Yes the authentication for those custom endpoints is not working at all. I am using password authentication, here is the code for the same:
The login page and all other functionalities, such as the main page and resume, are working fine. However, only the custom endpoints are not receiving the required headers. When I remove the request from the input, it works, but it is not secure, as users can share the PDF links, which we would like to prevent. |
How do you call the custom endpoint? With fetch, I had to add credentials: include |
I am using the endpoint for pdf element, setting the endpoint URL as pdf URL. I figured out the authorization headers are not coming from frontend. How do I fix this? Any guidance on this would be helpful |
It is working on my end. Chainlit appimport chainlit as cl
@cl.password_auth_callback
def auth_callback(username: str, password: str):
if (username, password) == ("admin", "admin"):
return cl.User(
identifier="Admin", metadata={}
)
else:
return None
@cl.on_chat_start
async def main():
pdf = cl.Pdf(url="/app")
await cl.Message(content="Hello World", elements=[pdf]).send() Fast api appfrom fastapi import FastAPI, Depends
from chainlit.auth import get_current_user
from chainlit.utils import mount_chainlit
from chainlit.server import GenericUser
from typing_extensions import Annotated
app = FastAPI()
UserParam = Annotated[GenericUser, Depends(get_current_user)]
@app.get("/app")
def read_main(current_user: UserParam):
print(current_user)
return {"message": "Hello World from main app"}
mount_chainlit(app=app, target="my_cl_app.py", path="/chainlit") The chainlit app requires auth, then sends a message containing a pdf element. The src of the PDF is the /app endpoint protected by auth. It correctly prints the current user |
I implemented a custom endpoint and expected it to be protected, but seems like the request headers are not receiving the Bearer token from frontend. Here is the code that I've used to implement endpoints and mount it to the chainlit app:
How do I make the headers come along with the request here?
Any guidance on this would be appreciated!
The text was updated successfully, but these errors were encountered: