MFA

Enable of disable Multi-Factor Authentication (MFA) on the User account.

Endpoints

Enabling, confirming, and disabling MFA is all possible via this endpoint:

MethodPathAuthentication
POST
/account/mfa/jwtJSON Web Token
POST
/account/mfa/keyAPI Key & Secret

Setup MFA

Request body

PropertyTypeDescription
mfabooleanSet to true to enable MFA

Response status codes

Possible status codes for this endpoints are:

Status codeDescription
201
success
400
the request was malformed
401
authentication failed
403
access denied
500
server error
NOTE

If the status code is not

200
the error property in the response body should indicate the nature of the problem.

Response body

ValueTypeDescription
resultStringEither success or error
errorStringWill give info on the nature of the error. Only set if an error occurred.
mfa.secretStringThe shared secret for generating one-time password (OTP) tokens
mfa.otpauthStringThe OTP Auth URI that is encoded in the QR code
mfa.qrcodeStringSVG to display a QR code with the otpauth URI encoded
TIP
Styling the SVG

The SVG returned by the backend uses currentColor for the QR code, so you can style it with CSS if you embed it in the page.

Example request

Javascript
const mfa = await axios.post(
  'https://backend.freesewing.org/account/mfa/jwt',
  { mfa: true },
  {
    headers: {
      Authorization: `Bearer ${token}`
    }
  }
)

Example response

JSON
200
{
  "result": "success",
  "mfa": {
    "secret": "KBTSKUKRDJPEGCZK",
    "otpauth": "otpauth://totp/FreeSewing:user-294?secret=KBTSKUKRDJPEGCZK&period=30&digits=6&algorithm=SHA1&issuer=FreeSewing",
    "qrcode": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 53 53\" shape-rendering=\"crispEdges\"><path fill=\"none\" d=\"M0 0h53v53H0z\"/><path stroke=\"currentColor\" d=\"M4 4.5h7m1 0h1m3 0h1m1 0h3m2 0h1m1 0h1m1 0h1m1 0h2m1 0h5m3 0h1m1 0h7M4 5.5h1m5 0h1m1 0h4m1 0h2m4 0h1m2 0h3m3 0h1m2 0h2m2 0h1m2 0h1m5 0h1M4 6.5h1m1 0h3m1 0h1m1 0h2m1 0h3m4 0h2m1 0h2m3 0h4m2 0h1m2 0h1m2 0h1m1 0h3m1 0h1M4 7.5h1m1 0h3m1 0h1m7 0h1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m5 0h2M9 36.5h5m1 0h5m3 0h1m1 0h1m1 0h5m5 0h1m7 0h2M5 37.5h2m2 0h1m2 0h3m6 0h1m1 0h2m3 0h1m1 0h2m1 0h3m2 0h5m4 0h1M8 38.5h1m1 0h1m1 0h3m2 0h1m3 0h2m1 0h1m1 0h1m2 0h1m1 0h1m3 0h1m2 0h2m1 0h5M5 39.5h4m5 0h1m2 0h4m3 0h1m2 0h4m1 0h1m2 0h2m3 0h1m1 0h1m1 0h2M4 40.5h1m2 0h2m1 0h1m1 0h2m4 0h12m3 0h1m1 0h1m2 0h7m3 0h1M12 41.5h1m1 0h3m1 0h3m3 0h1m3 0h1m2 0h1m3 0h1m2 0h1m1 0h1m3 0h1m1 0h2M4 42.5h7m1 0h1m2 0h4m1 0h3m1 0h1m1 0h1m1 0h2m1 0h1m2 0h2m4 0h1m1 0h1m1 0h1m1 0h2M4 43.5h1m5 0h1m1 0h1m1 0h1m1 0h2m1 0h3m2 0h1m3 0h3m2 0h6m1 0h1m3 0h3M4 44.5h1m1 0h3m1 0h1m1 0h1m2 0h2m1 0h2m1 0h1m2 0h6m3 0h1m3 0h1m2 0h6m2 0h1M4 45.5h1m1 0h3m1 0h1m1 0h5m3 0h2m1 0h3m1 0h3m3 0h3m1 0h2m4 0h2m1 0h1m1 0h1M4 46.5h1m1 0h3m1 0h1m3 0h5m3 0h5m1 0h2m1 0h2m2 0h1m1 0h1m1 0h3m1 0h1m1 0h4M4 47.5h1m5 0h1m2 0h1m2 0h1m1 0h1m2 0h1m4 0h2m2 0h1m3 0h2m1 0h3m1 0h3m2 0h3M4 48.5h7m1 0h5m2 0h3m3 0h1m2 0h1m1 0h3m1 0h2m2 0h1m1 0h1m1 0h2m1 0h1\"/></svg>\n"
  }
}

Confirm MFA

To confirm the MFA, we need to provide an MFA token to ensure the user can generate them.

Request body

PropertyTypeDescription
mfabooleanMust be set to true to confirm MFA
secretbooleanThe secret returned when setting up MFA
tokenbooleanMust be set to true to confirm MFA

Response status codes

Possible status codes for this endpoints are:

Status codeDescription
201
success
400
the request was malformed
401
authentication failed
403
access denied
500
server error
NOTE

If the status code is not

200
the error property in the response body should indicate the nature of the problem.

Response body

ValueTypeDescription
resultStringEither success or error
errorStringWill give info on the nature of the error. Only set if an error occurred.

Example request

Javascript
import { authenticator } from '@otplib/preset-default'

const confirm = await axios.post(
  'https://backend.freesewing.org/account/mfa/jwt',
  {
    mfa: true,
    secret: mfa.secret,
    token: authenticator.generate(mfa.secret)
  },
  {
    headers: {
      Authorization: `Bearer ${token}`
    }
  }
)

Example response

JSON
200
{
  "result": "success",
}

Disable MFA

To disable MFA, you need to provide both the account password and a valid token.

Request body

PropertyTypeDescription
mfabooleanMust be set to false to disable MFA
passwordbooleanThe User’s password
tokenbooleanMust be set to true to confirm MFA

Response status codes

Possible status codes for this endpoints are:

Status codeDescription
201
success
400
the request was malformed
401
authentication failed
403
access denied
500
server error
NOTE

If the status code is not

200
the error property in the response body should indicate the nature of the problem.

Response body

ValueTypeDescription
resultStringEither success or error
errorStringWill give info on the nature of the error. Only set if an error occurred.

Example request

Javascript
import { authenticator } from '@otplib/preset-default'

const confirm = await axios.post(
  'https://backend.freesewing.org/account/mfa/jwt',
  {
    mfa: false,
    password: "I like big bewbs and I just can't lie",
    token: authenticator.generate(mfa.secret)
  },
  {
    headers: {
      Authorization: `Bearer ${token}`
    }
  }
)

Example response

JSON
200
{
  "result": "success",
}