Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created December 26, 2025 00:26
Show Gist options
  • Select an option

  • Save cheeyeo/777892ae9cfda78a2c237ff6a2a79317 to your computer and use it in GitHub Desktop.

Select an option

Save cheeyeo/777892ae9cfda78a2c237ff6a2a79317 to your computer and use it in GitHub Desktop.
Calling Cognito Token endpoint
token_url="https://myapp.auth.us-east-1.amazoncognito.com/oauth2/token"
message = bytes(f"{client_id}:{client_secret}",'utf-8')
secret_hash = base64.b64encode(message).decode()
payload = {
"grant_type": 'authorization_code',
"client_id": client_id,
"code": code,
"redirect_uri": redirect_uri
}
headers = {"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"Basic {secret_hash}"}
resp = requests.post(token_url, params=payload, headers=headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment