adding test sandbox
This commit is contained in:
Родитель
9b4bef6473
Коммит
210e8ee0c5
|
@ -70,6 +70,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sarif.Viewer.VisualStudio.R
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sarif.Viewer.VisualStudio.ResultSources.GitHubAdvancedSecurity.Resources", "Sarif.Viewer.VisualStudio.ResultSources.GitHubAdvancedSecurity.Resources\Sarif.Viewer.VisualStudio.ResultSources.GitHubAdvancedSecurity.Resources.csproj", "{6C18770E-F2D2-4A9E-B5EC-0A3E77EF5005}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject1", "TestProject1\TestProject1.csproj", "{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|AnyCPU = Debug|AnyCPU
|
||||
|
@ -284,6 +286,18 @@ Global
|
|||
{6C18770E-F2D2-4A9E-B5EC-0A3E77EF5005}.Release|x64.Build.0 = Release|x64
|
||||
{6C18770E-F2D2-4A9E-B5EC-0A3E77EF5005}.Release|x86.ActiveCfg = Release|x86
|
||||
{6C18770E-F2D2-4A9E-B5EC-0A3E77EF5005}.Release|x86.Build.0 = Release|x86
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Debug|AnyCPU.Build.0 = Debug|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Release|AnyCPU.ActiveCfg = Release|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Release|AnyCPU.Build.0 = Release|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C0C9BFE1-A7AA-4AFF-936F-07B957A74BB5}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Runtime;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Microsoft.Identity.Client;
|
||||
|
||||
namespace TestProject1
|
||||
{
|
||||
|
||||
public class AuthManager
|
||||
{
|
||||
private readonly IPublicClientApplication publicClientApplication;
|
||||
/// <summary>
|
||||
/// This one is from the as-ado branch
|
||||
/// </summary>
|
||||
//private const string ClientId = "b86035bd-b0d6-48e8-aa8e-ac09b247525b";
|
||||
|
||||
///publicInsightsServerPMEProdAADApp
|
||||
private const string ClientId = "7ba8d231-9a00-4118-8a4d-9423b0f0a0f5";
|
||||
private readonly string[] scopes = new string[] { "499b84ac-1321-427f-aa17-267ca6975798/user_impersonation" }; // Constant value to target Azure DevOps. Do not change!
|
||||
private const string AadInstanceUrlFormat = "https://login.microsoftonline.com/{0}/v2.0";
|
||||
private const string msAadTenant = "72f988bf-86f1-41af-91ab-2d7cd011db47"; // GUID for the microsoft AAD tenant;
|
||||
private const string tenantId = "975f013f-7f24-47e8-a7d3-abc4752bf346"; // from the az portal page for devcanvas insight api
|
||||
|
||||
public AuthManager()
|
||||
{
|
||||
string authorityUrl = string.Format(CultureInfo.InvariantCulture, AadInstanceUrlFormat, msAadTenant);
|
||||
this.publicClientApplication = PublicClientApplicationBuilder
|
||||
.Create(ClientId)
|
||||
.WithAuthority(authorityUrl)
|
||||
//.WithRedirectUri("https://insightsapi.devcanvas.trafficmanager.net/.auth/login/aad/callback")
|
||||
.WithRedirectUri("https://insightwebv2.azurewebsites.net/.auth/login/aad/callback")
|
||||
//.WithRedirectUri(@"https://insightwebv2.azurewebsites.net")
|
||||
.Build();
|
||||
}
|
||||
|
||||
public async Task<AuthenticationResult> AuthenticateAsync()
|
||||
{
|
||||
AuthenticationResult result = null;
|
||||
|
||||
try
|
||||
{
|
||||
IEnumerable<IAccount> accounts = await this.publicClientApplication.GetAccountsAsync();
|
||||
result = await this.publicClientApplication
|
||||
.AcquireTokenSilent(new List<string>(), accounts.FirstOrDefault())
|
||||
//.AcquireTokenSilent(this.scopes, accounts.FirstOrDefault())
|
||||
.ExecuteAsync();
|
||||
}
|
||||
catch (MsalUiRequiredException ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
Dictionary<string, string> extraParams = new Dictionary<string, string>();
|
||||
// If the token has expired or the cache was empty, display a login prompt
|
||||
result = await this.publicClientApplication
|
||||
.AcquireTokenInteractive(new List<string>())
|
||||
.WithClaims(ex.Claims)
|
||||
.ExecuteAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("04f0c124-f2bc-4f59-8241-bf6df9866bbd")]
|
|
@ -0,0 +1,27 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Identity.Client" Version="4.54.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
|
||||
<PackageVersion Include="MSTest.TestAdapter" Version="2.2.8" />
|
||||
<PackageVersion Include="MSTest.TestFramework" Version="2.2.8" />
|
||||
<PackageVersion Include="Microsoft.Identity.Client" Version="4.51.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Web" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,24 @@
|
|||
using System.Net.Http.Headers;
|
||||
using System.Net.Http;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace TestProject1
|
||||
{
|
||||
[TestClass]
|
||||
public class UnitTest1
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task TestMethod1()
|
||||
{
|
||||
AuthManager authManager = new AuthManager();
|
||||
Microsoft.Identity.Client.AuthenticationResult x = await authManager.AuthenticateAsync();
|
||||
Console.WriteLine(x);
|
||||
|
||||
HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", x.AccessToken);
|
||||
HttpResponseMessage devCanvasOutput = await client.GetAsync("https://insightwebv2.azurewebsites.net/api/v1/SarifInsight/SarifInsightProviders");
|
||||
Console.WriteLine(devCanvasOutput);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
Загрузка…
Ссылка в новой задаче