Skip to main content
Header auth is a simple way to authenticate users using a header. It is typically used to delegate authentication to a reverse proxy. The header_auth_callback function is called with the headers of the request. It should return a User object if the user is authenticated, or None if the user is not authenticated. The callback function (defined by the user) is responsible for managing the authentication logic.

Example

from typing import Optional  import chainlit as cl   @cl.header_auth_callback def header_auth_callback(headers: Dict) -> Optional[cl.User]:  # Verify the signature of a token in the header (ex: jwt token)  # or check that the value is matching a row from your database  if headers.get("test-header") == "test-value":  return cl.User(identifier="admin", metadata={"role": "admin", "provider": "header"})  else:  return None 
Using this code, you will not be able to access the app unless the header test-header is set to test-value when sending any request to the app.