"""Handles security for the API.Entrypoint of token validations."""fromtypingimportAnyfrompoiesis.api.auth.auth_factoryimportget_auth_providerfrompoiesis.api.exceptionsimportUnauthorizedException
[docs]defvalidate_bearer_token(token:str)->dict[str,Any]:"""Validate bearer token. This function validates a bearer token and returns the token info. This info is then added to the context for use in the API handlers. Args: token: The bearer token. Returns: dict[str, Any]: The token info. """auth_provider=get_auth_provider()try:token_info=auth_provider.validate_token(token)exceptExceptionase:raiseUnauthorizedException("Invalid or expired token")fromereturntoken_info