Skip to content

Instantly share code, notes, and snippets.

@sts
Last active January 16, 2025 03:55
Show Gist options
  • Save sts/4c6f8fa759cec88197ca6dfcf306c391 to your computer and use it in GitHub Desktop.
Save sts/4c6f8fa759cec88197ca6dfcf306c391 to your computer and use it in GitHub Desktop.
Keycloak OTP Validation API
BASE_URL=https://localhost:8081/auth
CLIENT_ID=curl-test
CLIENT_SECRET=
USERNAME=
PASSWORD=
REALM=validation-test
OTP_CODE=027253
# OpenID Access Token via "Resource Owner Password Credentials Grant"
# https://tools.ietf.org/html/rfc6749#section-4.3
ACCESS_TOKEN=$(curl -s scope=openid \
--data-urlencode client_id=$CLIENT_ID \
--data-urlencode client_secret=$CLIENT_SECRET \
-d grant_type=password \
--data-urlencode username=$USERNAME\
--data-urlencode password=$PASSWORD \
$BASE_URL/realms/$REALM/protocol/openid-connect/token \
| python -c 'import sys, json; print json.load(sys.stdin)["access_token"]')
## Validate otp token with custom credential validation endpoint
curl -v \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d "[{"\""type"\"":"\""totp"\"","\""value"\"":"\""$OTP_CODE"\""}]" \
$BASE_URL/realms/$REALM/credential-validation
@akalana
Copy link

akalana commented Jan 16, 2025

Hey,

Could you let me know how we initially registered the device for TOTP through the API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment