What an otpauth URI is
When you scan a QR code to add an account to an authenticator app, the QR code contains a link that starts with otpauth://. The link tells the app everything it needs: the type of one-time password, the account name, the issuer, the shared secret and the settings for computing codes.
The format began as Google Authenticator’s Key Uri Format and became the common way to enroll any TOTP or HOTP app. It is a convention rather than an IETF standard, which is why apps differ in which parameters they honor.
This tool builds the URI from its parts, so you can check what a QR code should contain, test apps, or prepare test enrollments.
Anatomy of the URI
otpauth://totp/Example%20Corp:alice?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=Example%20Corp&algorithm=SHA1&digits=6&period=30| Part | Example | Meaning |
|---|---|---|
| Type | totp or hotp | Time-based or counter-based codes |
| Label | Example%20Corp:alice | Issuer and account, separated by a colon, each percent-encoded |
secret | Base32, no padding | The shared secret. Required. |
issuer | Example%20Corp | The service name. Should match the label’s issuer prefix. |
algorithm | SHA1, SHA256, SHA512 | The HMAC hash. Defaults to SHA1. |
digits | 6 or 8 | Code length. Defaults to 6. |
period | 30 | TOTP step in seconds. Defaults to 30. |
counter | 0 | HOTP starting counter. Required for HOTP. |
Issuer in two places
The issuer can appear as a prefix in the label and as the issuer parameter. Older apps read only the prefix; newer ones prefer the parameter. Putting the same value in both is the safest way to get the right name shown in every app.
Encoding the label
Spaces and special characters in the issuer or account must be percent-encoded, so Example Corp becomes Example%20Corp. The colon between issuer and account is the separator, so the issuer itself must not contain a colon. This tool refuses one.
App support for the parameters
Because the format is a convention, apps implement it differently. Many apps ignore algorithm, digits and period and always use SHA1, six digits and 30 seconds. When an app ignores a setting the server relies on, its codes are simply wrong, and the user cannot tell why.
The practical rule: use SHA1, six digits and 30 seconds unless you have tested every app your users might choose with something else. These are also Keycloak’s defaults.
What this tool does and does not do
- It builds
otpauth://totp/...orotpauth://hotp/...URIs with the label, secret, issuer, algorithm, digits and period or counter. - It accepts the secret in Base32 with any case, spaces or dashes, and writes it in canonical uppercase Base32 without padding.
- It can make a new random 160-bit secret.
- It checks the secret is valid Base32, that the issuer has no colon and that the counter and period are numbers.
- It does not draw a QR code. Use a QR generator you trust that runs locally, since the URI contains the secret.
- It does not send the URI or secret anywhere.
How to build a URI
- Choose TOTP for authenticator apps, or HOTP if your system uses counters.
- Enter the issuer, the name users should see in their app.
- Enter the account, usually the username or email.
- Paste the Base32 secret, or press New random secret for a test enrollment.
- Keep SHA1, 6 digits and 30 seconds unless you know the apps support more.
- Copy the URI. Turn it into a QR code locally, or open it on a phone with an authenticator installed.
Where this helps with Keycloak
Keycloak builds this URI and its QR code itself, so day to day you never need to. The tool helps around the edges.
Understanding the enrollment screen
During the Configure OTP required action, Keycloak shows a QR code and offers to show the secret for manual entry. The QR code holds an otpauth URI with the realm’s OTP policy settings. Building the same URI here shows what users’ apps receive.
Testing a new OTP policy
Before changing the realm’s OTP policy to SHA256 or eight digits, enroll test accounts with URIs built here in each app your users have, and compare the codes with the TOTP generator. If an app shows a different code, it ignores the setting.
Migrating users with existing secrets
When moving users from another system, you may have their OTP secrets. If you import them into Keycloak with the same settings, users keep their existing app entries. If you cannot, users re-enroll; a clear message beforehand saves support work.
Naming the issuer well
Users often have many entries in their authenticator. An issuer that names the service people know, not an internal system name, helps them pick the right code. When you migrate or build enrollments yourself, choose it with care, because changing it later means users re-enroll or live with the old name.
Common mistakes
- Putting a colon or unencoded spaces in the issuer, which splits the label in the wrong place.
- Giving the issuer only in the label or only as a parameter, so some apps show it and others do not.
- Including Base32 padding or lowercase letters, which a few apps reject.
- Using SHA256 or eight digits with apps that silently ignore them.
- Generating QR codes with an online service that receives the URI, and with it the secret.
- Reusing the same secret for several users or several devices.
Security notes
An otpauth URI is the secret in a convenient form. Anyone who sees it, or a photo of its QR code, can generate valid codes for that account. Show enrollment QR codes only to the user enrolling, only once, and never send them by email or chat.
Use a fresh random secret of at least 160 bits per enrollment. RFC 4226 requires at least 128 bits and recommends 160.
If a URI or QR code may have been exposed, delete the OTP credential and have the user enroll again with a new secret.
Best practices
- Keep TOTP with SHA1, six digits and 30 seconds for compatibility.
- Set the issuer both as the label prefix and as the parameter.
- Make QR codes locally and show them once.
- Confirm enrollment by asking the user for a code before saving the secret, as Keycloak does.
- Offer recovery codes or a second method so a lost phone is not a lockout.
HOTP URIs and the counter
For HOTP the URI carries counter instead of period. It is the counter value the app should start from. Each time the user asks the app for a code, the app moves its counter forward by one; the server moves its own counter when it accepts a code.
Because pressing the button without signing in moves only the app’s counter, the two drift apart. Servers handle this with a look-ahead window: they try several counters ahead and resynchronize when one matches. Keycloak’s OTP policy has an initial counter and a look-around window for HOTP for this reason.
Most people use TOTP. Choose HOTP only for hardware tokens or systems built around counters.
Making a QR code safely
An otpauth QR code is a picture of the secret. Treat it like a password on screen.
- Use a QR library or command-line tool that runs on your machine, such as
qrencode, rather than a website that receives the text. - Show the code only on the enrolling user’s screen, and remove it once enrollment is confirmed.
- Do not save QR images to shared drives, tickets or chat.
- For test enrollments, use test secrets that protect nothing.