import httpx from config import AUTH0_URL from src.exceptions.auth0_token_exception import Auth0TokenException from src.models import ClientCredentials, OAuthToken OAUTH_TOKEN_ENDPOINT = "/oauth/token" def generate_auth_token(client_credentials: ClientCredentials) -> OAuthToken: """Generate an OAuth token using the provided client credentials.""" with httpx.Client(base_url=str(AUTH0_URL)) as client: response = client.post( OAUTH_TOKEN_ENDPOINT, json=client_credentials.model_dump() ) if response.status_code != 200: raise Auth0TokenException( "JWT Access Token could not be generated", response.text ) auth_token_value = response.json() return OAuthToken.model_validate(auth_token_value)