Ben Walker
  • Blog
  • Blog

Generating an MFA Secret Key for Dynamics 365 testing

9/3/2020

0 Comments

 
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.
Picture
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':
Picture
or by clicking 'My Account' from the top right menu in Outlook.com.
Picture
2. Click on 'Manage security & privacy'
Picture
3. Click on 'Create and manage app passwords'
Picture
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'
Picture
6. Click on 'Configure app without notifications'
Picture
8. Make a note of the 'Secret Key' which is displayed
Picture
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.

0 Comments



Leave a Reply.

    Archives

    July 2021
    June 2021
    May 2020
    March 2020
    December 2019
    October 2019
    June 2018
    February 2018
    October 2017
    September 2017
    August 2017
    May 2017
    April 2017

    Categories

    All
    Dynamics 365
    Dynamics CRM
    FakeXrmEasy
    LINQPad
    Testing

    RSS Feed

    Author

    Some stuff about me!

Proudly powered by Weebly