@@ -37,7 +37,7 @@ All information in this section also applies to [API secrets](/identityserver/re
37
37
38
38
A client secret is abstracted by the ` Secret ` class. It provides properties for setting the value and type and a description and expiration date.
39
39
40
- ``` cs
40
+ ``` csharp
41
41
var secret = new Secret
42
42
{
43
43
Value = " foo" ,
@@ -50,7 +50,7 @@ var secret = new Secret
50
50
51
51
You can assign multiple secrets to a client to enable roll - over scenarios , e .g .:
52
52
53
- ```cs
53
+ ```csharp
54
54
var primary = new Secret (" foo" );
55
55
var secondary = new Secret (" bar" );
56
56
@@ -128,7 +128,7 @@ From a security point of view they have some shortcomings
128
128
129
129
The following creates a shared secret:
130
130
131
- ``` cs
131
+ ``` csharp
132
132
// loadSecret is responsible for loading a SHA256 or SHA512 hash of a good,
133
133
// high-entropy secret from a secure storage location
134
134
var hash = loadSecretHash ();
@@ -146,7 +146,7 @@ when prototyping or during demos to get started quickly. However, the clear text
146
146
of secrets used in production should never be written down in your source code.
147
147
Anyone with access to the repository can see the secret.
148
148
149
- ``` cs
149
+ ``` csharp
150
150
var compromisedSecret = new Secret (" just for demos, not prod!" .Sha256 ());
151
151
```
152
152
@@ -185,7 +185,7 @@ Authorization: Basic xxxxx
185
185
You can use the [ Duende IdentityModel] ( /identitymodel/index.mdx ) client library to programmatically interact with
186
186
the protocol endpoint from .NET code.
187
187
188
- ``` cs
188
+ ``` csharp
189
189
using Duende .IdentityModel .Client ;
190
190
191
191
var client = new HttpClient ();
@@ -217,7 +217,7 @@ based on the OAuth JWT assertion specification [(RFC 7523)](https://tools.ietf.o
217
217
The default private key JWT secret validator expects either a base64 encoded X.509 certificate or
218
218
a [ JSON Web Key] ( https://tools.ietf.org/html/rfc7517 ) formatted RSA, EC or symmetric key on the secret definition:
219
219
220
- ``` cs
220
+ ``` csharp
221
221
var client = new Client
222
222
{
223
223
ClientId = " client.jwt" ,
@@ -271,7 +271,7 @@ Content-type: application/x-www-form-urlencoded
271
271
You can use the [ Microsoft JWT library] ( https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/ ) to create JSON
272
272
Web Tokens.
273
273
274
- ``` cs
274
+ ``` csharp
275
275
private static string CreateClientToken (SigningCredentials credential , string clientId , string tokenEndpoint )
276
276
{
277
277
var now = DateTime .UtcNow ;
@@ -298,7 +298,7 @@ private static string CreateClientToken(SigningCredentials credential, string cl
298
298
...and the [ Duende IdentityModel] ( ../../../identitymodel ) client library to programmatically interact with the
299
299
protocol endpoint from .NET code.
300
300
301
- ``` cs
301
+ ``` csharp
302
302
using Duende .IdentityModel .Client ;
303
303
304
304
static async Task < TokenResponse > RequestTokenAsync (SigningCredentials credential )
@@ -338,7 +338,7 @@ created client assertion.
338
338
This is accomplished by handling the various events on the handler. We recommend to encapsulate the event handler in a
339
339
separate type. This makes it easier to consume services from DI:
340
340
341
- ``` cs
341
+ ``` csharp
342
342
// Program.cs
343
343
// some details omitted
344
344
builder .Services .AddTransient <OidcEvents >();
@@ -358,7 +358,7 @@ builder.Services.AddAuthentication(options =>
358
358
359
359
In your event handler you can inject code before the handler redeems the code:
360
360
361
- ``` cs
361
+ ``` csharp
362
362
public class OidcEvents : OpenIdConnectEvents
363
363
{
364
364
private readonly AssertionService _assertionService ;
@@ -415,7 +415,7 @@ Clients can use an X.509 client certificate as an authentication mechanism to en
415
415
For this you need to associate a client certificate with a client in your IdentityServer and enable MTLS support on the
416
416
options.
417
417
418
- ``` cs
418
+ ``` csharp
419
419
// Program.cs
420
420
var idsvrBuilder = builder .Services .AddIdentityServer (options =>
421
421
{
@@ -426,7 +426,7 @@ var idsvrBuilder = builder.Services.AddIdentityServer(options =>
426
426
Use the [ASP .NET Core service provider extensions methods ](/ identityserver / reference / di ) to add the services to the
427
427
ASP .NET Core service provider . A default implementation is available to do that either thumbprint or common -name based :
428
428
429
- ```cs
429
+ ```csharp
430
430
idsvrBuilder .AddMutualTlsSecretValidators ();
431
431
```
432
432
@@ -435,7 +435,7 @@ or `SecretTypes.X509CertificateThumbprint` (for self-issued certificates) to the
435
435
436
436
For example:
437
437
438
- ``` cs
438
+ ``` csharp
439
439
new Client
440
440
{
441
441
ClientId = " mtls.client" ,
@@ -469,7 +469,7 @@ Use such a handler with `HttpClient` to perform the client certificate authentic
469
469
The following snippet is using [ Duende IdentityModel] ( ../../../identitymodel ) to read the discovery document and
470
470
request a token:
471
471
472
- ``` cs
472
+ ``` csharp
473
473
static async Task < TokenResponse > RequestTokenAsync ()
474
474
{
475
475
var handler = new SocketsHttpHandler ();
@@ -484,6 +484,10 @@ static async Task<TokenResponse> RequestTokenAsync()
484
484
var response = await client .RequestClientCredentialsTokenAsync (new ClientCredentialsTokenRequest
485
485
{
486
486
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
+
487
491
ClientId = " mtls.client" ,
488
492
Scope = " api1"
489
493
});
0 commit comments