Skip to main content

When a User Can't Sign In with a One-Time Password

Type
Troubleshooting
For
Keycloak administrators
Checked against
Keycloak 26.8.2
Owner
Karan Deshmukh
Last review
2026-11-27

Find what the user sees in the table, then go to its section.

The user seesSection
Invalid authenticator code. after typing a codeKeycloak refuses the code
No code to type: the phone is lostThe user lost the phone
No request for a code at allKeycloak doesn't ask for a code

Keycloak Refuses the Code​

Cause. The code is from an earlier period, or the phone's clock is wrong. A code is valid for one period of the realm's OTP policy, 30 seconds by default. With the default look around window of 1, Keycloak also accepts the code of the period before and the period after, and refuses a code from two periods back.

Mobile Authenticator Setup after a refused code. The message Invalid authenticator code. is outlined in green, and the key is covered.
Keycloak's message for a refused code. Open full size

Fix.

  1. Ask the user to type the code that the app shows now, before its timer runs out.
  2. If every code fails, ask the user to set the phone's date and time to update automatically. An authenticator computes each code from the time, so a phone that's a minute off produces codes Keycloak refuses.
  3. If many users' codes fail, check the server's clock before you widen the look around window in the OTP policy. A wider window accepts older codes, for everyone.

The User Lost the Phone​

Cause. The authenticator went with the phone, and Keycloak keeps no copy within the user's reach.

Fix.

Confirm who is asking

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 the user out, require a new authenticator and delete the lost phone's OTP credential, as Reset a User's OTP Credential describes.

Keycloak Doesn't Ask for a Code​

Cause. An administrator deleted the user's OTP credential, and nothing asked the user to set up a new one. Keycloak's default sign-in flow asks for a second factor only from a user who has one configured.

The Personal info page of the account console, open after a sign-in with the password alone
Signed in with the password alone. Open full size

Fix. On the user's Details tab, in Required user actions, select Configure OTP, and then select Save. At the next sign-in, Keycloak asks the user to set up an authenticator before they get in.