Skip to content

Commit b990823

Browse files
committed
Found another spot where the RequestTokenAsync mTLS sample was missing a line
1 parent 0cf5905 commit b990823

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/content/docs/identityserver/tokens/client-authentication.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ All information in this section also applies to [API secrets](/identityserver/re
3737

3838
A client secret is abstracted by the `Secret` class. It provides properties for setting the value and type and a description and expiration date.
3939

40-
```cs
40+
```csharp
4141
var secret = new Secret
4242
{
4343
Value = "foo",
@@ -50,7 +50,7 @@ var secret = new Secret
5050

5151
You can assign multiple secrets to a client to enable roll-over scenarios, e.g.:
5252

53-
```cs
53+
```csharp
5454
var primary = new Secret("foo");
5555
var secondary = new Secret("bar");
5656

@@ -128,7 +128,7 @@ From a security point of view they have some shortcomings
128128

129129
The following creates a shared secret:
130130

131-
```cs
131+
```csharp
132132
// loadSecret is responsible for loading a SHA256 or SHA512 hash of a good,
133133
// high-entropy secret from a secure storage location
134134
var hash = loadSecretHash();
@@ -146,7 +146,7 @@ when prototyping or during demos to get started quickly. However, the clear text
146146
of secrets used in production should never be written down in your source code.
147147
Anyone with access to the repository can see the secret.
148148

149-
```cs
149+
```csharp
150150
var compromisedSecret = new Secret("just for demos, not prod!".Sha256());
151151
```
152152

@@ -185,7 +185,7 @@ Authorization: Basic xxxxx
185185
You can use the [Duende IdentityModel](/identitymodel/index.mdx) client library to programmatically interact with
186186
the protocol endpoint from .NET code.
187187

188-
```cs
188+
```csharp
189189
using Duende.IdentityModel.Client;
190190

191191
var client = new HttpClient();
@@ -217,7 +217,7 @@ based on the OAuth JWT assertion specification [(RFC 7523)](https://tools.ietf.o
217217
The default private key JWT secret validator expects either a base64 encoded X.509 certificate or
218218
a [JSON Web Key](https://tools.ietf.org/html/rfc7517) formatted RSA, EC or symmetric key on the secret definition:
219219

220-
```cs
220+
```csharp
221221
var client = new Client
222222
{
223223
ClientId = "client.jwt",
@@ -271,7 +271,7 @@ Content-type: application/x-www-form-urlencoded
271271
You can use the [Microsoft JWT library](https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/) to create JSON
272272
Web Tokens.
273273

274-
```cs
274+
```csharp
275275
private static string CreateClientToken(SigningCredentials credential, string clientId, string tokenEndpoint)
276276
{
277277
var now = DateTime.UtcNow;
@@ -298,7 +298,7 @@ private static string CreateClientToken(SigningCredentials credential, string cl
298298
...and the [Duende IdentityModel](../../../identitymodel) client library to programmatically interact with the
299299
protocol endpoint from .NET code.
300300

301-
```cs
301+
```csharp
302302
using Duende.IdentityModel.Client;
303303

304304
static async Task<TokenResponse> RequestTokenAsync(SigningCredentials credential)
@@ -338,7 +338,7 @@ created client assertion.
338338
This is accomplished by handling the various events on the handler. We recommend to encapsulate the event handler in a
339339
separate type. This makes it easier to consume services from DI:
340340

341-
```cs
341+
```csharp
342342
// Program.cs
343343
// some details omitted
344344
builder.Services.AddTransient<OidcEvents>();
@@ -358,7 +358,7 @@ builder.Services.AddAuthentication(options =>
358358

359359
In your event handler you can inject code before the handler redeems the code:
360360

361-
```cs
361+
```csharp
362362
public class OidcEvents : OpenIdConnectEvents
363363
{
364364
private readonly AssertionService _assertionService;
@@ -415,7 +415,7 @@ Clients can use an X.509 client certificate as an authentication mechanism to en
415415
For this you need to associate a client certificate with a client in your IdentityServer and enable MTLS support on the
416416
options.
417417

418-
```cs
418+
```csharp
419419
// Program.cs
420420
var idsvrBuilder = builder.Services.AddIdentityServer(options =>
421421
{
@@ -426,7 +426,7 @@ var idsvrBuilder = builder.Services.AddIdentityServer(options =>
426426
Use the [ASP.NET Core service provider extensions methods](/identityserver/reference/di) to add the services to the
427427
ASP.NET Core service provider. A default implementation is available to do that either thumbprint or common-name based:
428428

429-
```cs
429+
```csharp
430430
idsvrBuilder.AddMutualTlsSecretValidators();
431431
```
432432

@@ -435,7 +435,7 @@ or `SecretTypes.X509CertificateThumbprint` (for self-issued certificates) to the
435435

436436
For example:
437437

438-
```cs
438+
```csharp
439439
new Client
440440
{
441441
ClientId = "mtls.client",
@@ -469,7 +469,7 @@ Use such a handler with `HttpClient` to perform the client certificate authentic
469469
The following snippet is using [Duende IdentityModel](../../../identitymodel) to read the discovery document and
470470
request a token:
471471

472-
```cs
472+
```csharp
473473
static async Task<TokenResponse> RequestTokenAsync()
474474
{
475475
var handler = new SocketsHttpHandler();
@@ -484,6 +484,10 @@ static async Task<TokenResponse> RequestTokenAsync()
484484
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
485485
{
486486
Address = disco.MtlEndpointAliases.TokenEndpoint,
487+
488+
// The default ClientCredentialStyle value is ClientCredentialStyle.AuthorizationHeader, which does not work in a Mutual TLS scenario
489+
ClientCredentialStyle = ClientCredentialStyle.PostBody,
490+
487491
ClientId = "mtls.client",
488492
Scope = "api1"
489493
});

0 commit comments

Comments
 (0)