Obtaining a Bearer Token
OAuth 2.0 Client Credential Flow
Step 1: Token Request
POST {OAUTH2_TOKEN_ENDPOINT}
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&
client_id={your_client_id}&
client_secret={your_client_secret}
Step 2: Token Response
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "api"
}
Step 3: JWT Token Structure
The returned JWT token contains the following claims:
{
"iss": "authorization-server",
"aud": "billie-connect-api",
"sub": "service-account-id",
"client_no": "7000213",
"account_no": "12345",
"exp": 1640995200,
"iat": 1640991600
}
Implementation Example
# Example token acquisition (reference implementation)
def get_bearer_token(client_id: str, client_secret: str) -> str:
token_url = os.getenv("OAUTH2_TOKEN_ENDPOINT")
payload = {
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret
}
response = requests.post(
token_url,
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=payload
)
response.raise_for_status()
return response.json()["access_token"]