Skip to content

Commit 6504218

Browse files
committed
Azure Key Vault sample added
1 parent a54dd59 commit 6504218

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+26088
-7
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ bld/
2222
[Bb]in/
2323
[Oo]bj/
2424

25+
# ignore appsettings configuration files
26+
**/appsettings.development.json
27+
**/appsettings.staging.json
28+
**/appsettings.production.json
29+
2530
# Visual Studio 2015 cache/options directory
2631
.vs/
2732
# Uncomment if you have tasks that create the project's static files in wwwroot

ITfoxtec.Identity.Saml2.sln

Lines changed: 10 additions & 3 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.27004.2002
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28922.388
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A05F26DE-17C2-497F-B244-EE6790789066}"
77
EndProject
@@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ITfoxtec.Identity.Saml2", "
2121
EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestWebAppCoreFramework", "test\TestWebAppCoreFramework\TestWebAppCoreFramework.csproj", "{AB921243-70BE-4B10-BDDD-7F62FDA8CF93}"
2323
EndProject
24-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ITfoxtec.Identity.Saml2.Mvc", "src\ITfoxtec.Identity.Saml2.Mvc\ITfoxtec.Identity.Saml2.Mvc.csproj", "{1966436F-5CEC-4290-A547-152357C0BD24}"
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ITfoxtec.Identity.Saml2.Mvc", "src\ITfoxtec.Identity.Saml2.Mvc\ITfoxtec.Identity.Saml2.Mvc.csproj", "{1966436F-5CEC-4290-A547-152357C0BD24}"
25+
EndProject
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestWebAppCoreAzureKeyVault", "test\TestWebAppCoreAzureKeyVault\TestWebAppCoreAzureKeyVault.csproj", "{03A37D91-A36B-48C0-90A1-1FCF43621E60}"
2527
EndProject
2628
Global
2729
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -57,6 +59,10 @@ Global
5759
{1966436F-5CEC-4290-A547-152357C0BD24}.Debug|Any CPU.Build.0 = Debug|Any CPU
5860
{1966436F-5CEC-4290-A547-152357C0BD24}.Release|Any CPU.ActiveCfg = Release|Any CPU
5961
{1966436F-5CEC-4290-A547-152357C0BD24}.Release|Any CPU.Build.0 = Release|Any CPU
62+
{03A37D91-A36B-48C0-90A1-1FCF43621E60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{03A37D91-A36B-48C0-90A1-1FCF43621E60}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{03A37D91-A36B-48C0-90A1-1FCF43621E60}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{03A37D91-A36B-48C0-90A1-1FCF43621E60}.Release|Any CPU.Build.0 = Release|Any CPU
6066
EndGlobalSection
6167
GlobalSection(SolutionProperties) = preSolution
6268
HideSolutionNode = FALSE
@@ -69,6 +75,7 @@ Global
6975
{3EE8359C-DD95-4AC9-8137-2E551CF7CDCD} = {A05F26DE-17C2-497F-B244-EE6790789066}
7076
{AB921243-70BE-4B10-BDDD-7F62FDA8CF93} = {DE5976C5-83CD-4518-A05E-0DEC2EA5D17C}
7177
{1966436F-5CEC-4290-A547-152357C0BD24} = {A05F26DE-17C2-497F-B244-EE6790789066}
78+
{03A37D91-A36B-48C0-90A1-1FCF43621E60} = {DE5976C5-83CD-4518-A05E-0DEC2EA5D17C}
7279
EndGlobalSection
7380
GlobalSection(ExtensibilityGlobals) = postSolution
7481
SolutionGuid = {64BB7D39-E92F-466D-B601-276E16FF6EB4}

test/TestIdPCore/Controllers/AuthController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ private RelyingParty ValidateRelyingParty(string issuer)
155155
SingleLogoutResponseDestination = new Uri("https://localhost:44307/Auth/LoggedOut"),
156156
SignatureValidationCertificate = CertificateUtil.Load(Startup.AppEnvironment.MapToPhysicalFilePath("itfoxtec.identity.saml2.testwebappcore_Certificate.crt"))
157157
});
158+
validRelyingPartys.Add(new RelyingParty
159+
{
160+
Issuer = "urn:itfoxtec:identity:saml2:testwebappcoreAzureKeyVault",
161+
SingleSignOnDestination = new Uri("https://localhost:44308/Auth/AssertionConsumerService"),
162+
SingleLogoutResponseDestination = new Uri("https://localhost:44308/Auth/LoggedOut"),
163+
SignatureValidationCertificate = CertificateUtil.Load(Startup.AppEnvironment.MapToPhysicalFilePath("itfoxtec.identity.saml2.testwebappcore_Certificate.crt"))
164+
});
158165

159166
return validRelyingPartys.Where(rp => rp.Issuer.Equals(issuer, StringComparison.InvariantCultureIgnoreCase)).Single();
160167
}

test/TestIdPCore/TestIdPCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Version>4.0.0</Version>
88
<Authors>Anders Revsgaard</Authors>
99
<Company>ITfoxtec</Company>
10-
<Copyright>Copyright © 2018</Copyright>
10+
<Copyright>Copyright © 2019</Copyright>
1111
</PropertyGroup>
1212
<ItemGroup>
1313
<Content Remove="package-lock.json" />

test/TestIdPCore/web.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<environmentVariables>
1212
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44305" />
1313
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
14+
<environmentVariable name="COMPLUS_ForceENC" value="1" />
1415
</environmentVariables>
1516
</aspNetCore>
1617
</system.webServer>

test/TestWebApp/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("ITfoxtec")]
1212
[assembly: AssemblyProduct("TestWebApp")]
13-
[assembly: AssemblyCopyright("Copyright © 2018")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

test/TestWebAppCore/TestWebAppCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Version>4.0.0</Version>
88
<Authors>Anders Revsgaard</Authors>
99
<Company>ITfoxtec</Company>
10-
<Copyright>Copyright © 2018</Copyright>
10+
<Copyright>Copyright © 2019</Copyright>
1111
</PropertyGroup>
1212
<ItemGroup>
1313
<Content Remove="package-lock.json" />

test/TestWebAppCore/web.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<environmentVariables>
1212
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44306" />
1313
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
14+
<environmentVariable name="COMPLUS_ForceENC" value="1" />
1415
</environmentVariables>
1516
</aspNetCore>
1617
</system.webServer>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using ITfoxtec.Identity.Messages;
2+
using Newtonsoft.Json;
3+
4+
namespace TestWebAppCoreAzureKeyVault.AzureKeyVault
5+
{
6+
public class ADTokenRequest : TokenRequest
7+
{
8+
/// <summary>
9+
/// Azure AD resource.
10+
/// </summary>
11+
[JsonProperty(PropertyName = "resource")]
12+
public string Resource { get; set; }
13+
}
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using ITfoxtec.Identity.Helpers;
3+
using Microsoft.Azure.KeyVault;
4+
5+
namespace TestWebAppCoreAzureKeyVault.AzureKeyVault
6+
{
7+
public static class AppKeyVaultClient
8+
{
9+
public static KeyVaultClient GetClient(string keyVaultClientId, string keyVaultClientSecret, TokenHelper tokenHelper)
10+
{
11+
var client = new KeyVaultClient(async (authority, resource, scope) =>
12+
{
13+
try
14+
{
15+
var tokenRequest = new ADTokenRequest
16+
{
17+
Resource = resource
18+
};
19+
return await tokenHelper.GetAccessTokenWithClientCredentialsAsync(keyVaultClientId, keyVaultClientSecret, $"{authority}/oauth2/token", tokenRequest);
20+
}
21+
catch (Exception ex)
22+
{
23+
throw new Exception("Error while retrieving a token from Azure AD to Azure Key Vault.", ex);
24+
}
25+
});
26+
27+
return client;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)