---
title: "Generate 2FA account config (generateTwoFaAccountConfig)"
method: POST
path: "/api/2fa/account/config/generate"
tags: ["two-factor-auth-config-controller"]
---

# Generate 2FA account config (generateTwoFaAccountConfig)

`POST /api/2fa/account/config/generate`

Generate new 2FA account config template for specified provider type. 

For TOTP, this will return a corresponding account config template with a generated OTP auth URL (with new random secret key for each API call) that can be then converted to a QR code to scan with an authenticator app. Example:
```
{
  "providerType": "TOTP",
  "useByDefault": false,
  "authUrl": "otpauth://totp/TB%202FA:tenant@thingsboard.org?issuer=TB+2FA&secret=PNJDNWJVAK4ZTUYT7RFGPQLXA7XGU7PX"
}
```

For EMAIL, the generated config will contain email from user's account:
```
{
  "providerType": "EMAIL",
  "useByDefault": false,
  "email": "tenant@thingsboard.org"
}
```

For SMS 2FA this method will just return a config with empty/default values as there is nothing to generate/preset:
```
{
  "providerType": "SMS",
  "useByDefault": false,
  "phoneNumber": null
}
```

Will throw an error (Bad Request) if the provider is not configured for usage. 

Available for any authorized user.

## Query parameters

- `providerType` string, required

## Response `200`

OK

- union
  - BackupCodeTwoFaAccountConfig
    - `useByDefault` boolean
    - `providerType` string, required
    - `codes` string[], required
    - `codesLeft` integer
  - EmailTwoFaAccountConfig
    - `useByDefault` boolean
    - `providerType` string, required
    - `email` string, required
  - SmsTwoFaAccountConfig
    - `useByDefault` boolean
    - `providerType` string, required
    - `phoneNumber` string, required
  - TotpTwoFaAccountConfig
    - `useByDefault` boolean
    - `providerType` string, required
    - `authUrl` string, required

---

[API](https://skmtc.net/thingsboard/apis/thingsboard-rest-api.md) · [All operations](https://skmtc.net/thingsboard/apis/thingsboard-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/thingsboard/thingsboard-rest-api/revisions/40169ccdec5c/schema)
