Reset a User's OTP Credential
- Type
- How-to
- For
- Keycloak administrators
- Checked against
- Keycloak 26.8.2
- Owner
- Karan Deshmukh
- Last review
- 2026-11-28
When a user loses or replaces the phone that holds their authenticator app, sign the user out, delete the phone's one-time password (OTP) credential, and make the user set up a new one at their next sign-in.
This procedure resets the OTP credential only. It doesn't remove passkeys, security keys or other second factors that the user may also have.
Before You Start
Reset an authenticator only for the account's owner. Confirm the request through contact details the user gave before they lost the phone, not through details in the request. A reset for anyone else gives them the account.
- Sign in to the admin console with an account that can manage the users of the user's realm.
- Have the user's username or email address.
- Make sure that the user has the new phone, with an authenticator app such as FreeOTP, Google Authenticator, or Microsoft Authenticator.
- Check that the realm uses Keycloak's default browser flow, in which the OTP step is conditional. With a custom flow, Keycloak may ask for a code at a different point, or not at all.
Steps
- Sign the user out first: an open session reaches Mobile Authenticator Setup without asking for the password.
- Add the required action before you delete the credential: in the other order, the user can sign in with the password alone in between.
Both behaviors were tested on Keycloak 26.8.2.
-
In the admin console, check that the user's realm is the current realm: its name is at the top of the menu. Select Users, search for the user, and then select their username.

Step 1. Search for the user, and then select their username. Open full size -
On the Sessions tab, select Logout all sessions, and then select Confirm.
The dialog says that it signs out "active subjects in this realm." On a user's Sessions tab, it signs out that user only. In a test with a second user, the second user's session stayed open.

Step 2. Sign the user out of every open session. Open full size -
On the Details tab, in Required user actions, select Configure OTP, and then select Save.

Step 3. Configure OTP in the user's required actions, before anything is deleted. Open full size -
Select the Credentials tab, and find the Otp row of the lost phone: its User label names the device, such as Alex's phone. If the user has more than one Otp row, delete only the row of the lost phone.

Step 4. The Otp row of the lost phone. Leave the Password row. Open full size -
In that Otp row, open the menu at the end of the row, and then select Delete.

Step 5. Delete, in the menu of the Otp row. Open full size -
In the Delete credentials? dialog, select Delete. Check that the Otp row of the lost phone no longer appears on the Credentials tab.

Step 6. Confirm the deletion. Cancel leaves the credential in place. Open full size -
Ask the user to sign in. After the password, Keycloak shows Mobile Authenticator Setup. The user scans the QR code with the authenticator app on the new phone, enters the code that the app shows, names the device, and then selects Submit.

Step 7. What the user sees. The QR code is covered here because it contains the secret. Open full size
If the phone was stolen, or the password may be known to someone else, also select Update Password in step 3. The user then sets a new password before setting up the authenticator.
Check That It Worked
- On the Sessions tab, no session is listed.
- On the Credentials tab, a new Otp row shows the name that the user gave the new device, with today's date.

When the realm saves admin events, Events > Admin events lists the deletion as an ACTION on the user's credential, and the new required action as an UPDATE of the user.

On November 28, 2026, on a local test realm:
- The REST commands below ran as written on a user with an authenticator and an open session. Afterward, the user had no session, and the next sign-in went from the password to Mobile Authenticator Setup.
- Signing in between the steps showed why the order matters: an open session went to Mobile Authenticator Setup without the password, and with the credential deleted first, the password alone signed the user in.
- With two Otp rows, deleting one left the other working: Keycloak asked for a code and let the user choose the device.
The console screenshots date from November 19, 2026, except the Sessions tab, from November 28.
Reset Many Users with the Admin REST API
After a change to the OTP policy, every user's authenticator needs a reset, and the admin console does one user at a time. The admin REST API does the same things in the same order: it signs the user out, adds Configure OTP to the user's required actions, and then deletes every OTP credential, because after a policy change every device has to be set up again.
Reset an authenticator only for the account's owner. Confirm the request through contact details the user gave before they lost the phone, not through details in the request. A reset for anyone else gives them the account.
Set these variables first. Read the password from a password manager or a prompt, so that it stays out of your shell history.
KC_URL=https://keycloak.example.com # your Keycloak server
REALM=portfolio-demo # the user's realm
KC_ADMIN=sam.rivera # an administrator of the master realm
USERNAME=alex.morgan # the user to reset
read -rs -p "Password for $KC_ADMIN: " KC_ADMIN_PASSWORD; echo
-
Get an access token for the admin REST API, and find the user's ID.
TOKEN=$(curl -s "$KC_URL/realms/master/protocol/openid-connect/token" \-d grant_type=password -d client_id=admin-cli \--data-urlencode "username=$KC_ADMIN" --data-urlencode "password=$KC_ADMIN_PASSWORD" | jq -r .access_token)USER_ID=$(curl -s -H "Authorization: Bearer $TOKEN" \"$KC_URL/admin/realms/$REALM/users?username=$USERNAME&exact=true" | jq -r '.[0].id') -
Sign the user out of every session. Keycloak answers
204.curl -s -o /dev/null -w '%{http_code}\n' -X POST -H "Authorization: Bearer $TOKEN" \"$KC_URL/admin/realms/$REALM/users/$USER_ID/logout" -
Add
CONFIGURE_TOTPto the user's required actions, before deleting anything.Keep the actions already thereA
PUTreplaces the user's whole list of required actions. Sending{"requiredActions": ["CONFIGURE_TOTP"]}alone removes any action the user still has to do, such as updating their profile. Read the list first and add to it, as this command does.ACTIONS=$(curl -s -H "Authorization: Bearer $TOKEN" "$KC_URL/admin/realms/$REALM/users/$USER_ID" \| jq -c '.requiredActions + ["CONFIGURE_TOTP"] | unique')curl -s -o /dev/null -w '%{http_code}\n' -X PUT -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \-d "{\"requiredActions\": $ACTIONS}" "$KC_URL/admin/realms/$REALM/users/$USER_ID"Keycloak answers
204. -
Delete each of the user's OTP credentials. Keycloak answers each deletion with
204.for ID in $(curl -s -H "Authorization: Bearer $TOKEN" "$KC_URL/admin/realms/$REALM/users/$USER_ID/credentials" \| jq -r '.[] | select(.type == "otp") | .id'); docurl -s -o /dev/null -w '%{http_code}\n' -X DELETE -H "Authorization: Bearer $TOKEN" \"$KC_URL/admin/realms/$REALM/users/$USER_ID/credentials/$ID"done -
Check the result. No session is left, no credential of type
otpis left, and the required actions includeCONFIGURE_TOTP.curl -s -H "Authorization: Bearer $TOKEN" "$KC_URL/admin/realms/$REALM/users/$USER_ID/sessions" | jq lengthcurl -s -H "Authorization: Bearer $TOKEN" "$KC_URL/admin/realms/$REALM/users/$USER_ID/credentials" | jq -c '[.[] | .type]'curl -s -H "Authorization: Bearer $TOKEN" "$KC_URL/admin/realms/$REALM/users/$USER_ID" | jq -c '.requiredActions'Output0["password"]["CONFIGURE_TOTP"]
At their next sign-in, Keycloak runs the user's required actions one after another, and asks them to set up an authenticator before they get in.
Next Steps
- If the user sees Invalid authenticator code. during the setup, see When a User Can't Sign In with a One-Time Password.
- To see what the realm asks of an authenticator, see OTP Policy Settings.