Skip to content

Commit e31a3cd

Browse files
authored
Merge pull request #717 from DuendeSoftware/wca/mtls-sample-update
Fixed an mTLS sample
2 parents 8fbae41 + 7e4a40e commit e31a3cd

File tree

1 file changed

+8
-5
lines changed
  • src/content/docs/identityserver/tokens

1 file changed

+8
-5
lines changed

src/content/docs/identityserver/tokens/pop.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ In this scenario, the client would create an X.509 certificate on the fly, and u
7070
#### .NET Client
7171
In .NET it is straight-forward to create an X.509 certificate on the fly and use it to open a TLS connection.
7272

73-
```cs
73+
```csharp
7474
static X509Certificate2 CreateClientCertificate(string name)
7575
{
7676
X500DistinguishedName distinguishedName = new X500DistinguishedName($"CN={name}");
@@ -101,18 +101,21 @@ static X509Certificate2 CreateClientCertificate(string name)
101101

102102
Then use this client certificate on the TLS channel to request the token:
103103

104-
```cs
104+
```csharp
105105
static async Task<TokenResponse> RequestTokenAsync()
106106
{
107107
var client = new HttpClient(GetHandler(ClientCertificate));
108108

109109
var disco = await client.GetDiscoveryDocumentAsync("https://demo.duendesoftware.com");
110110
if (disco.IsError) throw new Exception(disco.Error);
111111

112-
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
112+
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
113113
{
114114
Address = disco.MtlsEndpointAliases.TokenEndpoint,
115-
115+
116+
// The default ClientCredentialStyle value is ClientCredentialStyle.AuthorizationHeader, which does not work in a Mutual TLS scenario
117+
ClientCredentialStyle = ClientCredentialStyle.PostBody,
118+
116119
ClientId = "client",
117120
Scope = "api1"
118121
});
@@ -133,7 +136,7 @@ static SocketsHttpHandler GetHandler(X509Certificate2 certificate)
133136
#### Enabling Support In IdentityServer
134137
The last step is to enable that feature in the options:
135138

136-
```cs
139+
```csharp
137140
// Program.cs
138141
var idsvrBuilder = builder.Services.AddIdentityServer(options =>
139142
{

0 commit comments

Comments
 (0)