> Source: https://docs.cyberelements.io/bastion/4.7/fi/Usage/Administration/AdminConsole/MainWorkPanel/AccessPolicies/OtpTokenGenerators/TotpGenerator/

# TOTP generator

**TOTP** produces a code from a shared secret and the current time. It is the mechanism used by Google Authenticator, FreeOTP, Microsoft Authenticator and similar applications.

It is the only channel that carries nothing: no message is sent at connection time, the phone computes the code on its own. There is therefore no per-message cost, no dependency on an operator, no delivery delay, and no data to intercept in transit.

![](https://docs.cyberelements.io/bastion/4.7/img/cyberelements/CYE_AdminConsole_OtpTokenGenerators_Totp_Edit.png)

## Origin of the secret

The **Key retrieval** field offers two origins, which are mutually exclusive:

- **read the key from an LDAP attribute** *(default)*: the secret is stored in the directory, under the attribute named in the next field (`secretKey` by default). The directory owns it; the platform only reads it.
- **generate new keys**: the platform produces the secret itself.

> **Consequences of the secret's origin**
>
> With the LDAP attribute, **the directory administrator fills in the secret**: the platform has read-only access and can neither create nor reset it. Resetting is done in the directory. With platform-side generation, enrolment and reset are handled by the platform, and that is the only case where [importing an empty key](https://docs.cyberelements.io/bastion/4.7/fi/Usage/Administration/AdminConsole/MainWorkPanel/AuthenticationDomains/ImportTotpKeys/) actually resets the secret.

## Application enrolment

Two enrolment routes exist, depending on the origin chosen:

- **QR code on the user portal**: the user photographs the code from their application. The simplest and most common route.
- **sending the key by email**: useful when the portal is not reachable before enrolment. This option unlocks the choice of SMTP server, the subject and the text of the message.

## Migration from another solution

Existing secrets are bulk-loaded through [Import TOTP keys](https://docs.cyberelements.io/bastion/4.7/fi/Usage/Administration/AdminConsole/MainWorkPanel/AuthenticationDomains/ImportTotpKeys/), which avoids re-enrolling all users: authenticator applications go on producing valid codes.

## Code settings

Expiry **30 seconds** by default, **6 digits** (the list offers only that value) and a key size of 64, 32 or 16 bits, 32 by default.

> **Compatibility with the application**
>
> These values must match what the user's application expects. Common applications follow 6 digits / 30 seconds; departing from that requires checking that the application in use supports it.

> **Mediation Controller time**
>
> A TOTP code is computed from the clock: it is produced by the user's phone and **verified by the Mediation Controller**. Both clocks must therefore agree. A drift on the server side causes valid codes to be rejected, for all users at once, and the message received is the same as for a wrong code, which directs the search for the cause to the wrong side. To set up a time server, see [Configuring an NTP server](https://docs.cyberelements.io/bastion/4.7/fi/Usage/Configuration/MediationController/ConfigureAnNTPServer/).

## Limits

- **No message is sent at connection**: that is the channel's advantage, but it assumes the user has their phone.
- The code depends on **time**: a phone whose clock drifts stops producing accepted codes. That is the first point to check when TOTP "stops working".
- In LDAP-attribute mode, the platform **cannot** enrol or reset.

## Implementation example

The [Google Authenticator](https://docs.cyberelements.io/bastion/4.7/fi/Integration/MFA/GoogleAuthenticatorIntegration/) integration describes both key origins, including the LDAP attribute case.

---

The details of the fields are described in the [module reference](https://docs.cyberelements.io/bastion/4.7/fi/Usage/Reference/AdminConsole/OtpTokenGenerators/).
