Skip to content

Commit bbd4387

Browse files
Browser changes (#12)
Implemented authentication flow with Web interaction to support form based login and SAML 2.0 login.
1 parent 1ef6a8a commit bbd4387

16 files changed

Lines changed: 2585 additions & 58 deletions

Common/Code/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class Constants
55
#region AuthTypeUserpassword
66

77
public const string AuthenticationaType_DefaultValue = "access_control";
8+
public const string AuthenticationaType_IE = "access_control_ie";
89
public const string AuthenticationaType_UserNamePassword = "username_password";
910

1011
public const string USERNAME_KEY = "username";
@@ -49,6 +50,8 @@ public class Constants
4950
public const string RESPONSE_TYPE_VALUE = "code";
5051
public const string SCOPE_VALUE = "offline_access openid sast_api sast-permissions access_control_api";
5152
public const string AUTHORIZATION_ENDPOINT = SAST_PREFIX + "/identity/connect/authorize";
53+
public const string SAST_Login = "/CxRestAPI/auth/#/login?ReturnUrl=%2FCxRestAPI%2Fauth%2Fidentity%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3Dide_client%26scope%3Doffline_access%2520openid%2520sast_api%2520sast-permissions%2520access_control_api%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252F";
54+
public const string SAST_Suffix = "%252F";
5255
public const string AUTHORIZATION_HEADER = "Authorization";
5356
public const string BEARER = "Bearer ";
5457
public const string USER_INFO_ENDPOINT = SAST_PREFIX + "/identity/connect/userinfo";

CxViewer.sln

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26403.0
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.32126.315
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CxViewerVSIX", "CxViewerVSIX\CxViewerVSIX.csproj", "{0D4CC225-7BF6-4EB8-9936-C6FD86FABCAB}"
77
EndProject
@@ -71,12 +71,12 @@ Global
7171
{4B9BE5FD-303E-4270-9C4D-FA3BDE6C34EB}.Release|Any CPU.Build.0 = Release|Any CPU
7272
{4B9BE5FD-303E-4270-9C4D-FA3BDE6C34EB}.Release|x86.ActiveCfg = Release|Any CPU
7373
{4B9BE5FD-303E-4270-9C4D-FA3BDE6C34EB}.Release|x86.Build.0 = Release|Any CPU
74-
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Build|Any CPU.ActiveCfg = Build|Any CPU
75-
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Build|Any CPU.Build.0 = Build|Any CPU
74+
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Build|Any CPU.ActiveCfg = Build|x86
75+
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Build|Any CPU.Build.0 = Build|x86
7676
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Build|x86.ActiveCfg = Build|x86
7777
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Build|x86.Build.0 = Build|x86
78-
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
79-
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Debug|Any CPU.ActiveCfg = Debug|x86
79+
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Debug|Any CPU.Build.0 = Debug|x86
8080
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Debug|x86.ActiveCfg = Debug|x86
8181
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Debug|x86.Build.0 = Debug|x86
8282
{A3841A67-DAE8-42BD-B0D4-9D0D1657F902}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -87,25 +87,7 @@ Global
8787
GlobalSection(SolutionProperties) = preSolution
8888
HideSolutionNode = FALSE
8989
EndGlobalSection
90-
GlobalSection(TeamFoundationVersionControl) = preSolution
91-
SccNumberOfProjects = 6
92-
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
93-
SccTeamFoundationServer = http://tfs2013:8080/tfs/defaultcollection
94-
SccLocalPath0 = .
95-
SccProjectUniqueName1 = CxViewerVSIX\\CxViewerVSIX.csproj
96-
SccProjectName1 = CxViewerVSIX
97-
SccLocalPath1 = CxViewerVSIX
98-
SccProjectUniqueName2 = Common\\Common.csproj
99-
SccProjectName2 = Common
100-
SccLocalPath2 = Common
101-
SccProjectUniqueName3 = CxViewerColorButton\\ColorButton.csproj
102-
SccProjectName3 = CxViewerColorButton
103-
SccLocalPath3 = CxViewerColorButton
104-
SccProjectUniqueName4 = CxViewerDgvFilterPopup\\DgvFilterPopup.csproj
105-
SccProjectName4 = CxViewerDgvFilterPopup
106-
SccLocalPath4 = CxViewerDgvFilterPopup
107-
SccProjectUniqueName5 = CxViewerAction\\CxViewerAction.csproj
108-
SccProjectName5 = CxViewerAction
109-
SccLocalPath5 = CxViewerAction
90+
GlobalSection(ExtensibilityGlobals) = postSolution
91+
SolutionGuid = {3A7D1BD1-CBAD-4801-9BC2-7120E0EA84CF}
11092
EndGlobalSection
11193
EndGlobal

CxViewerAction/CxViewerAction.csproj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
3+
<Import Project="..\packages\CefSharp.Common.99.2.120\build\CefSharp.Common.props" Condition="Exists('..\packages\CefSharp.Common.99.2.120\build\CefSharp.Common.props')" />
4+
<Import Project="..\packages\cef.redist.x86.99.2.12\build\cef.redist.x86.props" Condition="Exists('..\packages\cef.redist.x86.99.2.12\build\cef.redist.x86.props')" />
5+
<Import Project="..\packages\cef.redist.x64.99.2.12\build\cef.redist.x64.props" Condition="Exists('..\packages\cef.redist.x64.99.2.12\build\cef.redist.x64.props')" />
36
<PropertyGroup>
47
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
58
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -35,6 +38,8 @@
3538
<UseApplicationTrust>false</UseApplicationTrust>
3639
<BootstrapperEnabled>true</BootstrapperEnabled>
3740
<ApplicationIcon>Resources\cx.ico</ApplicationIcon>
41+
<NuGetPackageImportStamp>
42+
</NuGetPackageImportStamp>
3843
</PropertyGroup>
3944
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
4045
<DebugSymbols>true</DebugSymbols>
@@ -99,6 +104,15 @@
99104
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
100105
</PropertyGroup>
101106
<ItemGroup>
107+
<Reference Include="CefSharp, Version=99.2.120.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138, processorArchitecture=MSIL">
108+
<HintPath>..\packages\CefSharp.Common.99.2.120\lib\net452\CefSharp.dll</HintPath>
109+
</Reference>
110+
<Reference Include="CefSharp.Core, Version=99.2.120.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138, processorArchitecture=MSIL">
111+
<HintPath>..\packages\CefSharp.Common.99.2.120\lib\net452\CefSharp.Core.dll</HintPath>
112+
</Reference>
113+
<Reference Include="CefSharp.WinForms, Version=99.2.120.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138, processorArchitecture=MSIL">
114+
<HintPath>..\packages\CefSharp.WinForms.99.2.120\lib\net462\CefSharp.WinForms.dll</HintPath>
115+
</Reference>
102116
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
103117
<EmbedInteropTypes>True</EmbedInteropTypes>
104118
</Reference>
@@ -292,6 +306,12 @@
292306
<Compile Include="Views\BindingPrjList.Designer.cs">
293307
<DependentUpon>BindingPrjList.cs</DependentUpon>
294308
</Compile>
309+
<Compile Include="Views\BrowserForm.cs">
310+
<SubType>Form</SubType>
311+
</Compile>
312+
<Compile Include="Views\BrowserForm.Designer.cs">
313+
<DependentUpon>BrowserForm.cs</DependentUpon>
314+
</Compile>
295315
<Compile Include="Views\DockedView\ConnectionCtrl.cs">
296316
<SubType>UserControl</SubType>
297317
</Compile>
@@ -423,6 +443,7 @@
423443
</Compile>
424444
</ItemGroup>
425445
<ItemGroup>
446+
<Content Include="bin\x86\Build\LICENSE.txt" />
426447
<None Include="key.snk" />
427448
<None Include="packages.config" />
428449
<None Include="Web References\CxVSWebService\CxVSWebService.disco" />
@@ -555,6 +576,9 @@
555576
<SubType>Designer</SubType>
556577
<DependentUpon>BindingPrjList.cs</DependentUpon>
557578
</EmbeddedResource>
579+
<EmbeddedResource Include="Views\BrowserForm.resx">
580+
<DependentUpon>BrowserForm.cs</DependentUpon>
581+
</EmbeddedResource>
558582
<EmbeddedResource Include="Views\DockedView\ConnectionCtrl.resx">
559583
<DependentUpon>ConnectionCtrl.cs</DependentUpon>
560584
</EmbeddedResource>
@@ -701,6 +725,16 @@
701725
<ProjectExtensions>
702726
<VisualStudio />
703727
</ProjectExtensions>
728+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
729+
<PropertyGroup>
730+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
731+
</PropertyGroup>
732+
<Error Condition="!Exists('..\packages\cef.redist.x64.99.2.12\build\cef.redist.x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x64.99.2.12\build\cef.redist.x64.props'))" />
733+
<Error Condition="!Exists('..\packages\cef.redist.x86.99.2.12\build\cef.redist.x86.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x86.99.2.12\build\cef.redist.x86.props'))" />
734+
<Error Condition="!Exists('..\packages\CefSharp.Common.99.2.120\build\CefSharp.Common.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.99.2.120\build\CefSharp.Common.props'))" />
735+
<Error Condition="!Exists('..\packages\CefSharp.Common.99.2.120\build\CefSharp.Common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.99.2.120\build\CefSharp.Common.targets'))" />
736+
</Target>
737+
<Import Project="..\packages\CefSharp.Common.99.2.120\build\CefSharp.Common.targets" Condition="Exists('..\packages\CefSharp.Common.99.2.120\build\CefSharp.Common.targets')" />
704738
<!--<Target Name="AfterBuild">
705739
<PropertyGroup>
706740
<DllName>$(AssemblyName).dll</DllName>

CxViewerAction/CxViewerAction.csproj.user

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
</PropertyGroup>
1212
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
1313
<StartAction>Program</StartAction>
14-
<StartProgram>C:\Program Files %28x86%29\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe</StartProgram>
15-
<StartWorkingDirectory>C:\Program Files %28x86%29\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe</StartWorkingDirectory>
14+
<StartProgram>C:\Program Files %28x86%29\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe</StartProgram>
15+
<StartWorkingDirectory>C:\Program Files %28x86%29\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\</StartWorkingDirectory>
1616
<StartArguments>/rootsuffix Exp</StartArguments>
1717
</PropertyGroup>
1818
</Project>

CxViewerAction/Helpers/LoginHelper.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,13 @@ public static bool DolLogin(LoginData login, CxWebServiceClient client)
384384
if (!string.IsNullOrWhiteSpace(login.AuthenticationType) && login.AuthenticationType == Constants.AuthenticationaType_DefaultValue)
385385
{
386386
_oidcLoginHelper.resetLatestResult();
387-
oidcLoginResult = _oidcLoginHelper.ConnectToIdentidyProvider(login.ServerBaseUri);
387+
oidcLoginResult = _oidcLoginHelper.ConnectToIdentidyProvider(login.ServerBaseUri, login.AuthenticationType);
388+
}
389+
390+
else if (!string.IsNullOrWhiteSpace(login.AuthenticationType) && login.AuthenticationType == Constants.AuthenticationaType_IE)
391+
{
392+
_oidcLoginHelper.resetLatestResult();
393+
oidcLoginResult = _oidcLoginHelper.ConnectToIdentidyProvider(login.ServerBaseUri, login.AuthenticationType);
388394
}
389395
else if (!string.IsNullOrWhiteSpace(login.AuthenticationType) && login.AuthenticationType == Constants.AuthenticationaType_UserNamePassword)
390396
{
@@ -417,7 +423,7 @@ public static bool DolLogin(LoginData login, CxWebServiceClient client)
417423
}
418424
if (oidcLoginResult != null && oidcLoginResult.IsSuccessful)
419425
{
420-
if (!string.IsNullOrWhiteSpace(login.AuthenticationType) && login.AuthenticationType == Constants.AuthenticationaType_DefaultValue)
426+
if (!string.IsNullOrWhiteSpace(login.AuthenticationType) && (login.AuthenticationType == Constants.AuthenticationaType_DefaultValue || login.AuthenticationType == Constants.AuthenticationaType_IE))
421427
{
422428
//Add logs for print Server url and AccessToken
423429
Logger.Create().Debug("Server URL: " + login.ServerBaseUri);
@@ -431,7 +437,7 @@ public static bool DolLogin(LoginData login, CxWebServiceClient client)
431437
}
432438
else
433439
{
434-
if (!string.IsNullOrWhiteSpace(login.AuthenticationType) && login.AuthenticationType == Constants.AuthenticationaType_DefaultValue)
440+
if (!string.IsNullOrWhiteSpace(login.AuthenticationType) && (login.AuthenticationType == Constants.AuthenticationaType_DefaultValue || login.AuthenticationType == Constants.AuthenticationaType_IE))
435441
{
436442
Logger.Create().Debug("Server URL: " + login.ServerBaseUri);
437443
_oidcLoginHelper.CloseLoginWindow();
@@ -447,6 +453,7 @@ public static bool DolLogin(LoginData login, CxWebServiceClient client)
447453
/// </summary>
448454
internal static void DoLogout()
449455
{
456+
Application.DoEvents();
450457
Logger.Create().Debug("Logging out, clear authentication data");
451458
OidcLoginData oidcLoginData = OidcLoginData.GetOidcLoginDataInstance();
452459
oidcLoginData.AccessToken = null;
Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Threading;
33
using System.Windows.Forms;
4+
using Common;
5+
using CxViewerAction.Entities;
46
using CxViewerAction.ValueObjects;
57
using CxViewerAction.Views;
68

@@ -16,16 +18,13 @@ public class OIDCLoginHelper
1618

1719
public OIDCLoginHelper()
1820
{
19-
_oidcLoginFrm.OidcLoginCtrl2.NavigationCompleted += OidcLoginCtrlOnNavigationCompleted;
20-
_oidcLoginFrm.OidcLoginCtrl2.NavigationError += OidcLoginCtrlOnNavigationError;
21-
_oidcLoginFrm.UserClosedForm += OnUserClosedForm;
22-
_latestResult = new OidcLoginResult(false, string.Empty, null);
23-
}
2421

25-
public void resetLatestResult()
26-
{
27-
_latestResult = new OidcLoginResult(false, string.Empty, null);
28-
}
22+
}
23+
24+
public void resetLatestResult()
25+
{
26+
_latestResult = new OidcLoginResult(false, string.Empty, null);
27+
}
2928

3029
private void OnUserClosedForm(object sender, EventArgs e)
3130
{
@@ -36,7 +35,7 @@ private void OnUserClosedForm(object sender, EventArgs e)
3635
private void OidcLoginCtrlOnNavigationError(object sender, string errorMessage)
3736
{
3837
errorWasShown = true;
39-
MessageBox.Show(errorMessage,"Error", MessageBoxButtons.OK);
38+
MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK);
4039
_latestResult = new OidcLoginResult(false, errorMessage, null);
4140
_oidcLoginEvent.Set();
4241
}
@@ -47,28 +46,58 @@ private void OidcLoginCtrlOnNavigationCompleted(object sender, string code)
4746
_oidcLoginEvent.Set();
4847
}
4948

50-
private void ConectAndWait(string baseServerUri)
49+
private void ConectAndWait(string baseServerUri, string AuthenticationType)
5150
{
52-
_oidcLoginFrm.OidcLoginCtrl2.Invoke(new MethodInvoker(() =>
51+
if (AuthenticationType == Constants.AuthenticationaType_DefaultValue)
52+
{
53+
Thread.Sleep(3000);
54+
Application.DoEvents();
55+
var browserForm = new BrowserForm();
56+
browserForm.NavigationCompleted += OidcLoginCtrlOnNavigationCompleted;
57+
browserForm.NavigationError += OidcLoginCtrlOnNavigationError;
58+
BrowserForm.IsbrowserIntialized();
59+
browserForm.Show();
60+
browserForm.Invoke(new MethodInvoker(() =>
61+
{
62+
// browserForm.Show();
63+
browserForm.ConnectToIdentidyProvider(baseServerUri);
64+
Application.Run(browserForm);
65+
66+
}));
67+
}
68+
else
5369
{
54-
_oidcLoginFrm.Show();
55-
_oidcLoginFrm.ConnectToIdentidyProvider(baseServerUri);
56-
}));
57-
_oidcLoginEvent.WaitOne();
70+
_oidcLoginFrm.OidcLoginCtrl2.NavigationCompleted += OidcLoginCtrlOnNavigationCompleted;
71+
_oidcLoginFrm.OidcLoginCtrl2.NavigationError += OidcLoginCtrlOnNavigationError;
72+
_oidcLoginFrm.UserClosedForm += OnUserClosedForm;
73+
_latestResult = new OidcLoginResult(false, string.Empty, null);
74+
_oidcLoginFrm.OidcLoginCtrl2.Invoke(new MethodInvoker(() =>
75+
{
76+
_oidcLoginFrm.Show();
77+
_oidcLoginFrm.ConnectToIdentidyProvider(baseServerUri);
78+
}));
79+
_oidcLoginEvent.WaitOne();
80+
}
5881
}
5982

60-
public OidcLoginResult ConnectToIdentidyProvider(string baseServerUri)
83+
public OidcLoginResult ConnectToIdentidyProvider(string baseServerUri, string AuthenticationType)
6184
{
6285

63-
ConectAndWait(baseServerUri);
86+
ConectAndWait(baseServerUri, AuthenticationType);
87+
if (AuthenticationType == Constants.AuthenticationaType_IE)
88+
{
89+
_oidcLoginFrm.CloseForm();
90+
}
6491

65-
_oidcLoginFrm.CloseForm();
6692
return _latestResult;
6793
}
6894

69-
public void CloseLoginWindow()
70-
{
71-
_oidcLoginFrm.CloseForm();
72-
}
95+
public void CloseLoginWindow()
96+
{
97+
if (_oidcLoginFrm.Visible == true)
98+
{
99+
_oidcLoginFrm.CloseForm();
100+
}
101+
}
73102
}
74103
}

0 commit comments

Comments
 (0)