If you are using EasyRepro to perform automated tests against your Dynamics 365 instance and the account you are using is protected with Multi-Factor Authentication (MFA) you will need to generate an MFA Secret Key in order for your tests to be able to log in.
User accounts which are MFA protected will be met by a screen like this in which they must enter a code which will be generated by Microsoft and either sent to the user by email or SMS, or through the Microsoft Authenticator phone app.
Using the method described in this post it is possible to programatically generate the OTP (One TIme Password) needed to sign in and for your tests to use this to connect to the Power Platform as part of your tests. You can use the Otp.Net library to generate the OTP you need to log in.
The sample code in the EasyRepro solution already references this library, so in this article I will just show you how to generate the MFA 'secret key' which you will need to use in order to generate the OTP used in your tests.
You can obtain an MFA secret key for your account using these instructions - you will need Microsoft's Authenticator App to get this working:
1. Go to your Office365 'My account' page. This is available at: https://portal.office.com/account/ or by clicking on the 'cog' icon in Dynamics 365 and selecting 'Privacy and Cookies':
or by clicking 'My Account' from the top right menu in Outlook.com.
2. Click on 'Manage security & privacy'
3. Click on 'Create and manage app passwords'
4. On the page which opens, there are two tabs which don't look like tabs. Click on the first of these: 'Additional security verification'
5. Click on 'Set up Authenticator app'
6. Click on 'Configure app without notifications'
8. Make a note of the 'Secret Key' which is displayed
9. In the authenticator app on you phone, Click the '+' to add an account and select 'work or school account'
10. Scan the QR code displayed on the web page
11. If the App displays a six-digit code, click 'Next' on the web page
12. Click Verify Now on the web page
13. Enter the six-digit verification code from the app into the web page
14. Add your MFA Secret key from step 8 with the spaces removed to your app.config as shown below, in the same section that you add your username and password:
<add key="MfaSecretKey" value="MfaSecretKeyWithSpacesRemoved" />
If you follow the examples in the EasyRepro repository your tests will now automatically generate and enter the one time password whenever the login dialogue box appears.