Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Last active July 23, 2025 00:52
Show Gist options
  • Select an option

  • Save KyMidd/e7f98222fe09ea7c8bdf162fa0f1be1f to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/e7f98222fe09ea7c8bdf162fa0f1be1f to your computer and use it in GitHub Desktop.
def decrypt_user_auth_token(encrypted_token):
# Decode the base64
encrypted_token = base64.b64decode(encrypted_token)
# Initialize KMS client
kms = boto3.client('kms', region_name='us-east-1')
# Read the CMK key alias from the environment variable
cmk_key_alias = os.environ.get("CMK_ALIAS")
# Decrypt the token
response = kms.decrypt(
KeyId=cmk_key_alias,
CiphertextBlob=encrypted_token
)
# Store accessToken in variable
accessToken = response["Plaintext"].decode("utf-8")
# Send the accessToken back
return accessToken
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment