Skip to main content
You can require a time-based one-time password (TOTP) as a second factor on top of whichever sign-in method the user chose. When it is on, completing a magic link or an OAuth sign-in is no longer enough on its own. The user also has to enter a six-digit code from an authenticator app such as Google Authenticator, 1Password, or Authy. The setting is per environment and applies to all sign-in methods at once. You cannot require a second factor for Google but not for magic links.

Turn it on

Step 1: In the dashboard, click Configure in the left sidebar, under Authentication, and select the environment. Step 2: In the TOTP section, turn on Require TOTP. Step 3: Set TOTP issuer to your product name. This is the label the user sees next to the code in their authenticator app, so make it recognizable.
TOTP section showing the Require TOTP toggle and the TOTP issuer field
Both settings are required. If Require TOTP is on but TOTP issuer is empty, Portal treats the environment as not requiring a second factor and completes sign-ins without one. Always set an issuer when you enable the toggle.

What changes in your sign-in code

With two-factor off, a validation response carries the Client Session Token and the sign-in is done. With it on, that same response comes back with clientSessionToken set to null and a userJwt instead. There are three possible shapes. Branch on clientSessionToken:
The sign-in is complete. Use clientSessionToken to initialize a Portal SDK.

Enrollment

totpLink is an otpauth:// URI, the standard format authenticator apps expect. Render it as a QR code. totpLink is returned only until the user’s first successful code entry. After that they are enrolled, and later sign-ins return userJwt with totpLink set to null. If a user abandons the sign-in before entering a code, they are still not enrolled and will get a totpLink again next time.

Validate the code

Send the userJwt as a Bearer token alongside your Auth Environment ID:
This is the only endpoint in the Authentication API that takes two credentials. The Auth Environment ID identifies the environment and the userJwt identifies the half-finished sign-in.

Reset a user’s authenticator

If a user loses their device, reset their enrollment from the dashboard. Go to Authentication > End Users, open the user, and reset their TOTP enrollment. Their next sign-in returns a fresh totpLink so they can set up a new authenticator. See End users.

Next steps

End users

Review who has signed in and reset two-factor enrollment.

API reference

Full reference for the TOTP validation endpoint.