Generate Recovery Codes API

On this page

This API is used to generate a list of Recovery Codes. When creating new codes, any existing Recovery Codes will be cleared and the new set will become the current values.

Request#

Generate a new set of Recovery Codes for a User by their Id, replacing any existing codes.

API Key Authentication
Create Recovery Codes
POST/api/user/two-factor/recovery-code/{userId}
OpenAPI Spec

Path Parameters#

userId
  • Type: UUID
  • Required

The unique Id of the user to assign the generated Recovery Codes to.

Response#

The response for this API contains an array of Recovery Codes that were created. In both standard and FIPS modes, 10 codes are returned. In standard mode, codes use the format XXXXX-XXXXX. In FIPS mode, codes use the format XXXXXXX-XXXXXXX.

Note

The returned codes are the only time they are available in plaintext — they are hashed at rest and cannot be retrieved afterward. Store them securely and provide them to the user immediately. Since 1.68.0.

Response Codes
CodeDescription
200The request succeeded. The response contains a JSON body.
400The request was invalid or malformed. The response contains an Errors JSON object with the specific errors. FusionAuth also returns a 400 when the request needs a paid FusionAuth license and no license is present.
401The request has no valid Authorization header. The header is missing, or the API key isn't valid. The response is empty. For more information, see Authentication.
500FusionAuth had an internal error and logged a stack trace in the FusionAuth log files. The response is empty.

Response Body#

recoveryCodes
  • Type: Array<String>

The array of Recovery Codes.

Example Response JSON
{
  "code": "752185",
  "recoveryCodes": [
    "QJD73-L6GR5",
    "R7RJH-GB7H3",
    "JJ5YZ-KS4C3",
    "CRDHP-7L355",
    "928QS-P9HMJ",
    "8VLFT-Z2WMM",
    "PQZX9-YV5VR",
    "TK9TB-7BT6H",
    "6QYPL-ZPQJV",
    "VJ35W-98RW4"
  ]
}