# Enabling MFA for specific user

**URL:** <https://community.auth0.com/t/enabling-mfa-for-specific-user/110157>\
**Category:** Get Help\
**Tags:** account-linking, user-management\
**Created:** [June 28, 2023, 11:48am UTC](https://community.auth0.com/t/enabling-mfa-for-specific-user/110157 "2023-06-28T11:48:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ybansiwal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ybansiwal/32/48385_2.png) [@ybansiwal](https://community.auth0.com/u/ybansiwal)\
**Post date:** [June 28, 2023, 11:48am UTC](https://community.auth0.com/t/enabling-mfa-for-specific-user/110157/1 "2023-06-28T11:48:03Z")

</div>

I have followed the steps in some of the post and documentations provided to enable MFA for specific users. I have done below thought its not working.

1. Require Multi-factor Auth is set to “Never”
2. Created a new user
3. Added “user.user\_metadata.use\_mfa” to true
4. I can see the `MFA is enabled for this user` is enable for this in User information page

When I am trying to get the `oauth/token` its not giving me the `mfa_token`, its returning me the access and id token in the API response.

I have also tried creating Action for this as ‘Pre-registeration’ and still no luck.

I have followed the steps mentioned in the blog post too [How To Enable MFA For A Subset of Users](https://community.auth0.com/t/how-to-enable-mfa-for-a-subset-of-users/87505)

All I want is to enable MFA and get the `mfa_token` so I can associate with the user.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [June 30, 2023, 2:52pm UTC](https://community.auth0.com/t/enabling-mfa-for-specific-user/110157/3 "2023-06-30T14:52:28Z")

</div>

Hi @ybansiwal,

Welcome to the Auth0 Community!

> [@ybansiwal](#):
>
> I have also tried creating Action for this as ‘Pre-registeration’ and still no luck.

This should be a Post Login Action if you want to trigger MFA during a certain user’s login.

---

<div class="post-metadata">

**Author:** ![ybansiwal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ybansiwal/32/48385_2.png) [@ybansiwal](https://community.auth0.com/u/ybansiwal)\
**Post date:** [July 7, 2023, 8:03am UTC](https://community.auth0.com/t/enabling-mfa-for-specific-user/110157/4 "2023-07-07T08:03:03Z")

</div>

Thanks @dan.woda , I have also tried Post Login action and didn’t work. I did below steps

1. Created new custom actions and added to the flow
2. Created new user and it says MFA enabled for this user
3. When I tried to get the access token instead of giving `mfa_token` for MFA associate it gave me id\_token

Below is the code for action

```auto
exports.onExecutePostLogin = async (event, api) => {

if (event.user.user_metadata && event.user.user_metadata.use_mfa){
api.multifactor.enable('any', {allowRememberBrowser: false});
}
};

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [July 7, 2023, 12:42pm UTC](https://community.auth0.com/t/enabling-mfa-for-specific-user/110157/5 "2023-07-07T12:42:32Z")

</div>

Did you follow step #1?

> 1. set the user.user\_metadata.use\_mfa attribute in the respective users profile to true or false using the Auth0 Management API: [Auth0 Management API v2](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id) endpoint

---

<div class="post-metadata">

**Author:** ![ybansiwal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ybansiwal/32/48385_2.png) [@ybansiwal](https://community.auth0.com/u/ybansiwal)\
**Post date:** [July 7, 2023, 12:50pm UTC](https://community.auth0.com/t/enabling-mfa-for-specific-user/110157/6 "2023-07-07T12:50:09Z")

</div>

Yes, I did that at time of creating user

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [July 7, 2023, 1:03pm UTC](https://community.auth0.com/t/enabling-mfa-for-specific-user/110157/7 "2023-07-07T13:03:34Z")

</div>

Can you confirm that the conditional is firing by adding a console.log statement?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 26, 2023, 3:21pm UTC](https://community.auth0.com/t/enabling-mfa-for-specific-user/110157/8 "2023-07-26T15:21:53Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
