Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

MTLS Update #3962

Merged
merged 25 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d1a9a9f
a client cert auth handler
leastprivilege Jan 3, 2020
83a334d
Merge branch 'master' into features/mtls-update
leastprivilege Jan 3, 2020
c15e471
remove workspace.xml
leastprivilege Jan 3, 2020
456c156
exclude .idea folder when cleaning
leastprivilege Jan 3, 2020
0463896
ignore workspace xml
leastprivilege Jan 3, 2020
1326e85
add client cert to MTLS sample
leastprivilege Jan 3, 2020
21b03eb
add config for client cert authn
leastprivilege Jan 3, 2020
29d6dd7
add test cert
leastprivilege Jan 3, 2020
d74c98d
update client config for new cert
leastprivilege Jan 3, 2020
d97b51e
Move cnf generation to extension method
leastprivilege Jan 3, 2020
584ffb4
add mtls domain support to discovery
leastprivilege Jan 3, 2020
2dbdec0
update client to use SocketHandler
leastprivilege Jan 3, 2020
4ad4a15
rename MTLS middleware
leastprivilege Jan 3, 2020
10c5962
bug in disco
leastprivilege Jan 3, 2020
ab93547
add comments
leastprivilege Jan 4, 2020
2ab7026
cleanup mtls middleware
leastprivilege Jan 4, 2020
3f03a1f
cleanup
leastprivilege Jan 4, 2020
6ca57b6
cleanup client
leastprivilege Jan 4, 2020
c844cce
add feature to set client cert cnf claim regardless of authentication…
leastprivilege Jan 4, 2020
d8599f6
update ignore file
leastprivilege Jan 4, 2020
68debee
Merge branch 'master' into features/mtls-update
leastprivilege Jan 4, 2020
f7ff61c
remove rider files
leastprivilege Jan 4, 2020
a00149f
more rider files
leastprivilege Jan 4, 2020
bb0883a
use constants for path manipulation
leastprivilege Jan 4, 2020
b406133
set https fixed
leastprivilege Jan 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# Rider
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
.idea/**/contentModel.xml
.idea

# User-specific files
*.suo
Expand Down Expand Up @@ -223,3 +208,4 @@ identityserver4_log.txt
tempkey.rsa
samples/KeyManagement/FileSystem/dataprotectionkeys/
samples/KeyManagement/FileSystem/signingkeys/
workspace.xml
2 changes: 1 addition & 1 deletion clean.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
git clean -xdf -e samples -e src/IdentityServer4/.vs
git clean -xdf -e samples -e src/IdentityServer4/.vs -e .idea

./clean_cache.sh
323 changes: 0 additions & 323 deletions samples/Clients/.idea/.idea.Clients/.idea/workspace.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
<ProjectReference Include="..\Constants\Constants.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="client.p12">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
41 changes: 22 additions & 19 deletions samples/Clients/src/ConsoleMTLSClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;

namespace ConsoleMTLSClient
Expand All @@ -24,21 +25,19 @@ public static async Task Main()

static async Task<TokenResponse> RequestTokenAsync()
{
var handler = new HttpClientHandler();
var cert = X509.CurrentUser.My.Thumbprint.Find("bf6e2ca4f07994430b86bf9d48833a33f27a5c24").Single();
handler.ClientCertificates.Add(cert);
var client = new HttpClient(GetHandler());

var client = new HttpClient(handler);

var disco = await client.GetDiscoveryDocumentAsync(Constants.Authority);
var disco = await client.GetDiscoveryDocumentAsync("https://identityserver.local");
if (disco.IsError) throw new Exception(disco.Error);

var endpoint = disco
.TryGetValue(OidcConstants.Discovery.MtlsEndpointAliases)
.Value<string>(OidcConstants.Discovery.TokenEndpoint)
.ToString();

var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
{
Address = disco
.TryGetValue(OidcConstants.Discovery.MtlsEndpointAliases)
.Value<string>(OidcConstants.Discovery.TokenEndpoint)
.ToString(),
Address = endpoint,

ClientId = "mtls",
Scope = "api1"
Expand All @@ -50,15 +49,9 @@ static async Task<TokenResponse> RequestTokenAsync()

static async Task CallServiceAsync(string token)
{
var baseAddress = Constants.SampleApi;

var handler = new HttpClientHandler();
var cert = X509.CurrentUser.My.Thumbprint.Find("bf6e2ca4f07994430b86bf9d48833a33f27a5c24").Single();
handler.ClientCertificates.Add(cert);

var client = new HttpClient(handler)
var client = new HttpClient(GetHandler())
{
BaseAddress = new Uri(baseAddress)
BaseAddress = new Uri(Constants.SampleApi)
};

client.SetBearerToken(token);
Expand All @@ -67,5 +60,15 @@ static async Task CallServiceAsync(string token)
"\n\nService claims:".ConsoleGreen();
Console.WriteLine(JArray.Parse(response));
}

static SocketsHttpHandler GetHandler()
{
var handler = new SocketsHttpHandler();

var cert = new X509Certificate2("client.p12", "changeit");
handler.SslOptions.ClientCertificates = new X509CertificateCollection { cert };

return handler;
}
}
}
}
Binary file added samples/Clients/src/ConsoleMTLSClient/client.p12
Binary file not shown.
1 change: 1 addition & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<PackageReference Update="Microsoft.AspNetCore.Identity" Version="$(FrameworkVersion)" />
<PackageReference Update="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="$(FrameworkVersion)" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="$(FrameworkVersion)" />
<PackageReference Update="Microsoft.AspNetCore.Authentication.Certificate" Version="$(FrameworkVersion)"/>

<!--microsoft entity framework -->
<PackageReference Update="Microsoft.EntityFrameworkCore.Relational" Version="$(EntityFrameworkVersion)" />
Expand Down
Loading