Skip to main content

OTP Policy Settings

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

A realm's OTP policy decides what a one-time password (OTP) looks like in it: how long a code lasts, how many digits it has, and how much clock difference Keycloak forgives. In the admin console, it's under Authentication > Policies > OTP Policy.

The OTP Policy tab of a new realm, with its default values
A new realm's OTP policy in Keycloak 26.8.2. Open full size

Settings​

The defaults are those of a new realm in Keycloak 26.8.2.

SettingDefaultWhat it decides
OTP typeTime basedA time-based code changes every period. A counter-based code changes each time the user asks the app for one.
OTP hash algorithmSHA1The algorithm the app and Keycloak use to compute a code.
Number of digits6The length of a code: 6 or 8.
Look around window1How many periods before and after the current one Keycloak also accepts.
OTP Token period30 secondsHow long a time-based code lasts.
Supported applicationsFreeOTP, Google Authenticator, Microsoft AuthenticatorThe apps that Mobile Authenticator Setup lists for users to install.
Reusable tokenOffWhether a code that has signed someone in works again before it expires.

Admin REST API Fields​

Each setting is a field of the realm representation, at GET /admin/realms/{realm}.

FieldDefault
otpPolicyTypetotp
otpPolicyAlgorithmHmacSHA1
otpPolicyDigits6
otpPolicyLookAheadWindow1
otpPolicyPeriod30
otpPolicyCodeReusablefalse
otpPolicyInitialCounter0, used only by counter-based codes

Before You Change a Setting​

A change applies only to authenticators set up after it. Each OTP credential keeps the type, digits, period and algorithm it was set up with: after a change from 6 to 8 digits, a phone set up before the change still signed in with 6-digit codes. To move a user to the new policy, reset their one-time password. To move many users, reset them with the admin REST API.