Skip to content

Commit

Permalink
Allow Multi-Factor Authentication (Using Otp.NET)
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelRodriguez8008 committed Nov 6, 2019
1 parent a08fb39 commit 4a6d996
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public static class Elements
{ "Login_SignIn", "id(\"cred_sign_in_button\")"},
{ "Login_CrmMainPage", "//*[contains(@id,'crmTopBar')or contains(@data-id,'topBar')]"},
{ "Login_StaySignedIn", "//input[@id=\"idSIButton9\"]"},
{ "Login_OneTimeCode", "//input[@name='otc']"},


//Notification
{ "Notification_AppMessageBar", "id(\"crmAppMessageBar\")"},
Expand Down Expand Up @@ -724,6 +726,7 @@ public static class Login
public static string SignIn = "Login_SignIn";
public static string CrmMainPage = "Login_CrmMainPage";
public static string StaySignedIn = "Login_StaySignedIn";
public static string OneTimeCode = "Login_OneTimeCode";
}
public static class Report
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public OnlineLogin(WebClient client)
/// <param name="orgUrl">URL of the organization</param>
/// <param name="username">User name</param>
/// <param name="password">Password</param>
public void Login(Uri orgUrl, SecureString username, SecureString password)
/// <param name="mfaSecrectKey">SecrectKey for multi-factor authentication</param>
public void Login(Uri orgUrl, SecureString username, SecureString password, SecureString mfaSecrectKey = null)
{
_client.Login(orgUrl, username, password);
_client.Login(orgUrl, username, password, mfaSecrectKey);

if (_client.Browser.Options.UCITestMode)
{
Expand All @@ -37,10 +38,11 @@ public void Login(Uri orgUrl, SecureString username, SecureString password)
/// <param name="orgUrl">URL of the organization</param>
/// <param name="username">User name</param>
/// <param name="password">Password</param>
/// <param name="mfaSecrectKey">SecrectKey for multi-factor authentication</param>
/// <param name="redirectAction">Actions required during redirect</param>
public void Login(Uri orgUrl, SecureString username, SecureString password, Action<LoginRedirectEventArgs> redirectAction)
public void Login(Uri orgUrl, SecureString username, SecureString password, SecureString mfaSecrectKey, Action<LoginRedirectEventArgs> redirectAction)
{
_client.Login(orgUrl, username, password, redirectAction);
_client.Login(orgUrl, username, password, mfaSecrectKey, redirectAction);

if (_client.Browser.Options.UCITestMode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Otp.NET, Version=1.2.1.0, Culture=neutral, PublicKeyToken=38a48df817e173a6, processorArchitecture=MSIL">
<HintPath>..\packages\Otp.NET.1.2.1\lib\net45\Otp.NET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.19298.1349")]
[assembly: AssemblyFileVersion("1.0.19298.1349")]
[assembly: AssemblyVersion("1.0.19310.1254")]
[assembly: AssemblyFileVersion("1.0.19310.1254")]
265 changes: 162 additions & 103 deletions Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Microsoft.Dynamics365.UIAutomation.Api.UCI/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
<package id="Otp.NET" version="1.2.1" targetFramework="net46" />
<package id="Selenium.Chrome.WebDriver" version="76.0.0" targetFramework="net46" />
<package id="Selenium.Firefox.WebDriver" version="0.24.0" targetFramework="net46" />
<package id="Selenium.Support" version="3.141.0" targetFramework="net46" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public static class Elements
{ "Login_SignIn", "id(\"cred_sign_in_button\")"},
{ "Login_CrmMainPage", "id(\"crmTopBar\")"},
{ "Login_StaySignedIn", "id(\"idSIButton9\")"},
{ "Login_OneTimeCode", "//input[@name='otc']"},

//Notification
{ "Notification_AppMessageBar", "id(\"crmAppMessageBar\")"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dfe2c141-f1aa-4d4b-8df8-0fb93023cf45")]
[assembly: AssemblyVersion("8.2.19298.1349")]
[assembly: AssemblyFileVersion("8.2.19298.1349")]
[assembly: AssemblyVersion("9.1.19310.1248")]
[assembly: AssemblyFileVersion("9.1.19310.1248")]

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c9748803-f3cb-4531-b313-bc24d4d0bf0c")]
[assembly: AssemblyVersion("8.2.19298.1349")]
[assembly: AssemblyFileVersion("8.2.19298.1349")]
[assembly: AssemblyVersion("9.1.19310.1248")]
[assembly: AssemblyFileVersion("9.1.19310.1248")]

Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<Compile Include="UCI\GetValue.cs" />
<Compile Include="UCI\GlobalSearch\GlobalCategorizedSearch.cs" />
<Compile Include="UCI\GlobalSearch\GlobalRelevanceSearch.cs" />
<Compile Include="UCI\Login\Login.cs" />
<Compile Include="UCI\Navigation\FormSelector.cs" />
<Compile Include="UCI\Navigation\GlobalSearch.cs" />
<Compile Include="UCI\Navigation\OpenNavigation.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a075b87e-dca5-4a2a-909b-932e2f5f98b4")]
[assembly: AssemblyVersion("8.2.19298.1349")]
[assembly: AssemblyFileVersion("8.2.19298.1349")]
[assembly: AssemblyVersion("9.1.19310.1254")]
[assembly: AssemblyFileVersion("9.1.19310.1254")]

49 changes: 49 additions & 0 deletions Microsoft.Dynamics365.UIAutomation.Sample/UCI/Login/Login.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Security;
using Microsoft.Dynamics365.UIAutomation.Api.UCI.Extensions;
using Microsoft.Dynamics365.UIAutomation.Api.UCI;
using Microsoft.Dynamics365.UIAutomation.Browser;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.Extensions;
using Guid = System.Guid;

namespace Microsoft.Dynamics365.UIAutomation.Sample.UCI.Login
{
[TestClass]
public class Login
{
private readonly SecureString _username = System.Configuration.ConfigurationManager.AppSettings["OnlineUsername"].ToSecureString();
private readonly SecureString _password = System.Configuration.ConfigurationManager.AppSettings["OnlinePassword"].ToSecureString();
private readonly Uri _xrmUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["OnlineCrmUrl"]);
private readonly SecureString _mfaSecrectKey = System.Configuration.ConfigurationManager.AppSettings["MfaSecrectKey"].ToSecureString();

// Allow trigger to complete the set value action
private string _enter(string value) => value + Keys.Enter;
private string _timed(string value) => $"{value} {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}";

[TestMethod]
public void MultiFactorLogin()
{
var options = TestSettings.Options;
options.TimeFactor = 0.5f;
var client = new WebClient(options);
using (var xrmApp = new XrmApp(client))
{
xrmApp.OnlineLogin.Login(_xrmUri, _username, _password, _mfaSecrectKey);

xrmApp.Navigation.OpenApp(UCIAppName.Sales);

xrmApp.Navigation.OpenSubArea("Sales", "Accounts");

xrmApp.Grid.SwitchView("All Accounts");

xrmApp.CommandBar.ClickCommand("New");

xrmApp.Entity.SetValue("name", _timed("Test API Account"));
xrmApp.Entity.SetValue("telephone1", "555-555-5555");
//xrmApp.Entity.SetValue(new BooleanItem { Name = "creditonhold", Value = true });
}
}
}
}

0 comments on commit 4a6d996

Please sign in to comment.