|
1
|
{"slug":"/references/auth/recovery-code-mfa-module-provider","title":"How to Create a Recovery Code Multi-Factor Authentication (MFA) Module Provider","frontmatter":{"slug":"/references/auth/recovery-code-mfa-module-provider","tags":["auth","server","how to"],"sidebar_label":"Create Recovery Code MFA Provider","keywords":["mfa","provider","integration","recovery code"]},"toc":[{"title":"What is a Recovery Code MFA Module Provider?","id":"what-is-a-recovery-code-mfa-module-provider","level":2},{"title":"Implementation Example","id":"implementation-example","level":2},{"title":"1. Create Module Provider Directory","id":"1-create-module-provider-directory","level":2},{"title":"2. Create the Recovery Code MFA Module Provider Service","id":"2-create-the-recovery-code-mfa-module-provider-service","level":2},{"title":"constructor","id":"constructor","level":3},{"title":"Example","id":"example","level":4},{"title":"Identifier","id":"identifier","level":3},{"title":"method","id":"method","level":3},{"title":"canVerifyForAuthIdentity","id":"canverifyforauthidentity","level":3},{"title":"Example","id":"example-1","level":4},{"title":"Parameters","id":"canverifyforauthidentity-parameters","level":4},{"title":"Returns","id":"canverifyforauthidentity-returns","level":4},{"title":"generateCodes","id":"generatecodes","level":3},{"title":"Example","id":"example-2","level":4},{"title":"Parameters","id":"generatecodes-parameters","level":4},{"title":"Returns","id":"generatecodes-returns","level":4},{"title":"verify","id":"verify","level":3},{"title":"Example","id":"example-3","level":4},{"title":"Parameters","id":"verify-parameters","level":4},{"title":"Returns","id":"verify-returns","level":4},{"title":"3. Create Module Definition File","id":"3-create-module-definition-file","level":2},{"title":"4. Use Module Provider","id":"4-use-module-provider","level":2},{"title":"5. Test it Out","id":"5-test-it-out","level":2}],"blocks":[{"kind":"markdown","html":"In this guide, you’ll learn how to create a Recovery Code Multi-Factor Authentication (MFA) Auth Module Provider and the methods you must implement in its main service."},{"kind":"markdown","html":"---"},{"kind":"heading","level":2,"text":"What is a Recovery Code MFA Module Provider?","id":"what-is-a-recovery-code-mfa-module-provider"},{"kind":"markdown","html":"A Recovery Code MFA Module Provider is a specialized MFA provider that, in addition to\nverifying codes, can generate a fresh batch of one-time recovery codes for an auth identity.\nRecovery codes are typically used as a fallback when the user loses access to their primary\nMFA factor (such as their TOTP authenticator).\n\nEach generated code should be returned to the user only once (in plain text), stored as a\nhash on the server using the injected `authMfaRecoveryCodeService`, and invalidated after a\nsuccessful verification.\n\nMedusa provides a built-in Recovery Code MFA Module Provider that you can use out-of-the-box. You can also\noverride it by following the instructions in this guide.\n\n---"},{"kind":"heading","level":2,"text":"Implementation Example","id":"implementation-example"},{"kind":"markdown","html":"As you implement your Recovery Code MFA Auth Module Provider, it can be useful to refer to an existing provider and how it's implemeted.\n\nIf you need to refer to an existing implementation as an example, check the [Recovery Code MFA Module Provider in the Medusa repository](https://github.com/medusajs/medusa/blob/develop/packages/modules/auth/src/providers/mfa/recovery-code.ts).\n\n---"},{"kind":"heading","level":2,"text":"1. Create Module Provider Directory","id":"1-create-module-provider-directory"},{"kind":"markdown","html":"Start by creating a new directory for your module provider.\n\nIf you're creating the module provider in a Medusa application, create it under the `src/modules` directory. For example, `src/modules/my-recovery-code`.\n\nIf you're creating the module provider in a plugin, create it under the `src/providers` directory. For example, `src/providers/my-recovery-code`."},{"kind":"note","variant":"note","html":"The rest of this guide always uses the `src/modules/my-recovery-code` directory as an example."},{"kind":"markdown","html":"---"},{"kind":"heading","level":2,"text":"2. Create the Recovery Code MFA Module Provider Service","id":"2-create-the-recovery-code-mfa-module-provider-service"},{"kind":"markdown","html":"Create the file `src/modules/my-recovery-code/service.ts` that holds the module provider's main service. It must implement the `RecoveryCodeAuthMfaProvider` interface imported from `@medusajs/framework/types`:\n\n```ts title=\"src/modules/my-recovery-code/service.ts\"\nimport { RecoveryCodeAuthMfaProvider } from \"@medusajs/framework/types\"\n\ntype Options = {\n // define any options your provider needs here\n}\n\nclass MyRecoveryCodeProviderService implements RecoveryCodeAuthMfaProvider {\n // TODO implement methods\n}\n\nexport default MyRecoveryCodeProviderService\n```"},{"kind":"heading","level":3,"text":"constructor","id":"constructor"},{"kind":"markdown","html":"The constructor allows you to access resources from the module's container using the first parameter,\nand the provider's options using the second parameter.\n\nIf you're creating a client or establishing a connection with a third-party service, do it in the constructor."},{"kind":"heading","level":4,"text":"Example","id":"example"},{"kind":"markdown","html":"The Auth Module injects `authMfaRecoveryCodeService` into your provider's container. This\nis the data service for the `AuthMfaRecoveryCode` model, and you should store it as a class\nproperty so the rest of the provider's methods can use it to retrieve and manage the\nstored recovery codes for an auth identity (for example, when generating, verifying, or\ninvalidating codes).\n\n```ts\nimport { RecoveryCodeAuthMfaProvider } from \"@medusajs/framework/types\"\nimport { Logger, ModulesSdkTypes } from \"@medusajs/framework/types\"\n\ntype InjectedDependencies = {\n logger: Logger\n authMfaRecoveryCodeService: ModulesSdkTypes.IMedusaInternalService<any>\n}\n\nclass MyRecoveryCodeProviderService implements RecoveryCodeAuthMfaProvider {\n static identifier = \"recovery_code\"\n readonly method = \"recovery_code\" as const\n\n protected logger_: Logger\n protected authMfaRecoveryCodeService_: ModulesSdkTypes.IMedusaInternalService<any>\n\n constructor ({\n logger,\n authMfaRecoveryCodeService,\n }: InjectedDependencies) {\n this.logger_ = logger\n this.authMfaRecoveryCodeService_ = authMfaRecoveryCodeService\n }\n\n // ...\n}\n\nexport default MyRecoveryCodeProviderService\n```"},{"kind":"heading","level":3,"text":"Identifier","id":"identifier"},{"kind":"markdown","html":"Every Recovery Code MFA auth module provider must have an `identifier` static property set to `recovery_code`.\nThe provider's ID will be stored as `mfa_{identifier}`.\n\nFor example:\n\n```ts\nclass MyRecoveryCodeProviderService implements RecoveryCodeAuthMfaProvider {\n static identifier = \"recovery_code\"\n // ...\n}\n```"},{"kind":"heading","level":3,"text":"method","id":"method"},{"kind":"markdown","html":"The identifier of the MFA method that the provider implements. For recovery code providers,\nthis is always `recovery_code`."},{"kind":"heading","level":3,"text":"canVerifyForAuthIdentity","id":"canverifyforauthidentity"},{"kind":"markdown","html":"This method checks whether the auth identity has any recovery codes stored with this\nprovider. The Auth Module uses it to determine whether the auth identity can fall back\nto recovery code verification.\n\nUse the injected `authMfaRecoveryCodeService` to look up stored recovery codes for the\nauth identity. Alternatively, you can check with third-party services if the provider manages \nrecovery codes remotely."},{"kind":"heading","level":4,"text":"Example","id":"example-1"},{"kind":"markdown","html":"```ts\nclass MyRecoveryCodeProvider implements RecoveryCodeAuthMfaProvider {\n // ...\n async canVerifyForAuthIdentity(\n data: { auth_identity_id: string },\n sharedContext?: Context\n ): Promise<boolean> {\n const [code] = await this.authMfaRecoveryCodeService_.list(\n { auth_identity_id: data.auth_identity_id },\n { select: [\"id\"] },\n sharedContext\n )\n\n return !!code\n }\n}\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"canverifyforauthidentity-parameters"},{"kind":"typeList","sectionTitle":"canVerifyForAuthIdentity","types":[{"name":"data","type":"`object`","description":"The auth identity to check.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"auth_identity_id","type":"`string`","description":"The ID of the auth identity to check.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"canverifyforauthidentity-returns"},{"kind":"typeList","sectionTitle":"canVerifyForAuthIdentity","types":[{"name":"Promise","type":"Promise<boolean>","optional":false,"defaultValue":"","description":"Whether the auth identity has at least one recovery code stored.","expandable":false,"children":[{"name":"boolean","type":"`boolean`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"generateCodes","id":"generatecodes"},{"kind":"markdown","html":"This method generates a new batch of recovery codes for the given auth identity. Any\npreviously generated codes for the auth identity should be invalidated, so that only the\nlatest batch can be used.\n\nThe Auth Module uses this method when an auth identity enrolls into recovery codes, or when\nthe user requests a fresh set of codes.\n\nYou can use the injected `authMfaRecoveryCodeService` to store the generated codes as hashes, and \nto invalidate existing codes by deleting them. Alternatively, you can manage recovery codes remotely."},{"kind":"heading","level":4,"text":"Example","id":"example-2"},{"kind":"markdown","html":"```ts\nclass MyRecoveryCodeProvider implements RecoveryCodeAuthMfaProvider {\n // ...\n async generateCodes(\n data: { auth_identity_id: string; count: number },\n sharedContext?: Context\n ): Promise<string[]> {\n // invalidate any previously generated codes\n const existing = await this.authMfaRecoveryCodeService_.list(\n { auth_identity_id: data.auth_identity_id },\n { select: [\"id\"] },\n sharedContext\n )\n\n if (existing.length) {\n await this.authMfaRecoveryCodeService_.delete(\n existing.map((c) => c.id),\n sharedContext\n )\n }\n\n const codes = Array.from({ length: data.count }, () => this.generateCode_())\n\n await this.authMfaRecoveryCodeService_.create(\n await Promise.all(\n codes.map(async (code) => ({\n auth_identity_id: data.auth_identity_id,\n code_hash: await this.hashCode_(code),\n }))\n ),\n sharedContext\n )\n\n return codes\n }\n}\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"generatecodes-parameters"},{"kind":"typeList","sectionTitle":"generateCodes","types":[{"name":"data","type":"`object`","description":"The auth identity and the number of codes to generate.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"auth_identity_id","type":"`string`","description":"The ID of the auth identity to generate the codes for.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The number of recovery codes to generate.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"generatecodes-returns"},{"kind":"typeList","sectionTitle":"generateCodes","types":[{"name":"Promise","type":"Promise<string[]>","optional":false,"defaultValue":"","description":"The generated recovery codes in plain text. These should be shown to the user only once.","expandable":false,"children":[{"name":"string[]","type":"`string`[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":3,"text":"verify","id":"verify"},{"kind":"markdown","html":"This method verifies a recovery code submitted by the user. It looks up the stored hashes\nfor the auth identity, finds the one matching the submitted code, and consumes that code\nby deleting it so it can only be used once.\n\nUse the injected `authMfaRecoveryCodeService` to retrieve and delete the matching recovery\ncode. Alternatively, you can verify and consume the code with third-party services if the provider manages\nrecovery codes remotely."},{"kind":"heading","level":4,"text":"Example","id":"example-3"},{"kind":"markdown","html":"```ts\nclass MyRecoveryCodeProvider implements RecoveryCodeAuthMfaProvider {\n // ...\n async verify(\n data: { auth_identity_id: string; code: string },\n sharedContext?: Context\n ): Promise<boolean> {\n const recoveryCodes = await this.authMfaRecoveryCodeService_.list(\n { auth_identity_id: data.auth_identity_id },\n { select: [\"id\", \"code_hash\"] },\n sharedContext\n )\n\n let match: (typeof recoveryCodes)[number] | undefined\n\n for (const candidate of recoveryCodes) {\n if (await this.verifyHash_(candidate.code_hash, data.code)) {\n match = candidate\n break\n }\n }\n\n if (!match) {\n return false\n }\n\n // consume the code so it can't be reused\n await this.authMfaRecoveryCodeService_.delete(match.id, sharedContext)\n\n return true\n }\n}\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"verify-parameters"},{"kind":"typeList","sectionTitle":"verify","types":[{"name":"data","type":"`object`","description":"The auth identity and recovery code to verify.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"auth_identity_id","type":"`string`","description":"The ID of the auth identity to verify the code for.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"The recovery code submitted by the user.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"verify-returns"},{"kind":"typeList","sectionTitle":"verify","types":[{"name":"Promise","type":"Promise<boolean>","optional":false,"defaultValue":"","description":"Whether the recovery code was matched and consumed.","expandable":false,"children":[{"name":"boolean","type":"`boolean`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]},{"kind":"markdown","html":"---"},{"kind":"heading","level":2,"text":"3. Create Module Definition File","id":"3-create-module-definition-file"},{"kind":"markdown","html":"Create the file `src/modules/my-recovery-code/index.ts` with the following content:\n\n```ts title=\"src/modules/my-recovery-code/index.ts\"\nimport { ModuleProvider, Modules } from \"@medusajs/framework/utils\"\nimport MyRecoveryCodeProviderService from \"./service\"\n\nexport default ModuleProvider(Modules.AUTH, {\n services: [MyRecoveryCodeProviderService],\n})\n```\n\nThis exports the module provider's definition, indicating that the `MyRecoveryCodeProviderService` is the module provider's service.\n\n---"},{"kind":"heading","level":2,"text":"4. Use Module Provider","id":"4-use-module-provider"},{"kind":"markdown","html":"To use your Recovery Code MFA Module Provider, add it to the `mfa.providers` array of the Auth Module in `medusa-config.ts`:\n\n```ts title=\"medusa-config.ts\"\nmodule.exports = defineConfig({\n // ...\n modules: [\n {\n resolve: \"@medusajs/medusa/auth\",\n dependencies: [Modules.CACHE, ContainerRegistrationKeys.LOGGER],\n options: {\n mfa: {\n encryption_key: process.env.AUTH_MFA_ENCRYPTION_KEY,\n providers: [\n {\n // if module provider is in a plugin, use `plugin-name/providers/my-recovery-code`\n resolve: \"./src/modules/my-recovery-code\",\n id: \"recovery-code\",\n options: {\n // provider options...\n }\n }\n ]\n },\n providers: [\n {\n resolve: \"@medusajs/medusa/auth-emailpass\",\n id: \"emailpass\",\n },\n ],\n },\n },\n ]\n})\n```\n\n\n---"},{"kind":"heading","level":2,"text":"5. Test it Out","id":"5-test-it-out"},{"kind":"markdown","html":"To test out your Recovery Code MFA Module Provider, you can [manage two-factor authentication settings in the admin dashboard][two-factor authentication settings from the admin dashboard](!user-guide!/settings/profile#manage-two-factor-authentication). You can enable 2FA, which will show you the recovery codes generated by your provider.\n\nYou can also refer to the [MFA guide](/commerce-modules/auth/mfa) for more details on how to use MFA providers with the API routes."}]} |