Skip to content

Commit 05e3b60

Browse files
client credentials
1 parent a20b104 commit 05e3b60

File tree

6 files changed

+479
-225
lines changed

6 files changed

+479
-225
lines changed

src/content/docs/accesstokenmanagement/advanced/client-assertions.md

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
title: Client Assertions
3+
description: Learn how to use client assertions instead of shared secrets for token client authentication in Duende.AccessTokenManagement.
4+
sidebar:
5+
label: Client Assertions
6+
order: 30
7+
redirect_from:
8+
- /foss/accesstokenmanagement/advanced/client_assertions/
9+
---
10+
import { Tabs, TabItem } from "@astrojs/starlight/components";
11+
12+
If your token client is using a client assertion instead of a shared secret, you can provide the assertion in two ways
13+
14+
* use the request parameter mechanism to pass a client assertion to the management
15+
* implement the `IClientAssertionService` interface to centralize client assertion creation
16+
17+
Here's a sample client assertion service using the Microsoft JWT library:
18+
19+
20+
{/* prettier-ignore */}
21+
<Tabs syncKey="atm">
22+
{/* prettier-ignore */}
23+
<TabItem label="V4">
24+
```csharp
25+
// ClientAssertionService.cs
26+
using Duende.AccessTokenManagement;
27+
using Duende.IdentityModel;
28+
using Duende.IdentityModel.Client;
29+
using Microsoft.Extensions.Options;
30+
using Microsoft.IdentityModel.JsonWebTokens;
31+
using Microsoft.IdentityModel.Tokens;
32+
33+
public class ClientAssertionService(IOptionsSnapshot<ClientCredentialsClient> options)
34+
: IClientAssertionService
35+
{
36+
public Task<ClientAssertion?> GetClientAssertionAsync(
37+
ClientCredentialsClientName? clientName = null, TokenRequestParameters? parameters = null)
38+
{
39+
if (clientName == "invoice")
40+
{
41+
var options1 = options.Get(clientName);
42+
43+
var descriptor = new SecurityTokenDescriptor
44+
{
45+
Issuer = options1.ClientId,
46+
Audience = options1.TokenEndpoint,
47+
Expires = DateTime.UtcNow.AddMinutes(1),
48+
SigningCredentials = GetSigningCredential(),
49+
50+
Claims = new Dictionary<string, object>
51+
{
52+
{ JwtClaimTypes.JwtId, Guid.NewGuid().ToString() },
53+
{ JwtClaimTypes.Subject, options1.ClientId! },
54+
{ JwtClaimTypes.IssuedAt, DateTime.UtcNow.ToEpochTime() }
55+
},
56+
57+
AdditionalHeaderClaims = new Dictionary<string, object>
58+
{
59+
{ JwtClaimTypes.TokenType, "client-authentication+jwt" }
60+
}
61+
};
62+
63+
var handler = new JsonWebTokenHandler();
64+
var jwt = handler.CreateToken(descriptor);
65+
66+
return Task.FromResult<ClientAssertion?>(new ClientAssertion
67+
{
68+
Type = OidcConstants.ClientAssertionTypes.JwtBearer,
69+
Value = jwt
70+
});
71+
}
72+
73+
return Task.FromResult<ClientAssertion?>(null);
74+
}
75+
76+
private SigningCredentials GetSigningCredential()
77+
{
78+
throw new NotImplementedException();
79+
}
80+
}
81+
```
82+
</TabItem>
83+
<TabItem label="V3">
84+
85+
```csharp
86+
// ClientAssertionService.cs
87+
using Duende.AccessTokenManagement;
88+
using Duende.IdentityModel;
89+
using Duende.IdentityModel.Client;
90+
using Microsoft.Extensions.Options;
91+
using Microsoft.IdentityModel.JsonWebTokens;
92+
using Microsoft.IdentityModel.Tokens;
93+
94+
public class ClientAssertionService(IOptionsSnapshot<ClientCredentialsClient> options)
95+
: IClientAssertionService
96+
{
97+
public Task<ClientAssertion?> GetClientAssertionAsync(
98+
string? clientName = null, TokenRequestParameters? parameters = null)
99+
{
100+
if (clientName == "invoice")
101+
{
102+
var options1 = options.Get(clientName);
103+
104+
var descriptor = new SecurityTokenDescriptor
105+
{
106+
Issuer = options1.ClientId,
107+
Audience = options1.TokenEndpoint,
108+
Expires = DateTime.UtcNow.AddMinutes(1),
109+
SigningCredentials = GetSigningCredential(),
110+
111+
Claims = new Dictionary<string, object>
112+
{
113+
{ JwtClaimTypes.JwtId, Guid.NewGuid().ToString() },
114+
{ JwtClaimTypes.Subject, options1.ClientId! },
115+
{ JwtClaimTypes.IssuedAt, DateTime.UtcNow.ToEpochTime() }
116+
},
117+
118+
AdditionalHeaderClaims = new Dictionary<string, object>
119+
{
120+
{ JwtClaimTypes.TokenType, "client-authentication+jwt" }
121+
}
122+
};
123+
124+
var handler = new JsonWebTokenHandler();
125+
var jwt = handler.CreateToken(descriptor);
126+
127+
return Task.FromResult<ClientAssertion?>(new ClientAssertion
128+
{
129+
Type = OidcConstants.ClientAssertionTypes.JwtBearer,
130+
Value = jwt
131+
});
132+
}
133+
134+
return Task.FromResult<ClientAssertion?>(null);
135+
}
136+
137+
private SigningCredentials GetSigningCredential()
138+
{
139+
throw new NotImplementedException();
140+
}
141+
}
142+
```
143+
</TabItem>
144+
</Tabs>

src/content/docs/accesstokenmanagement/advanced/client-credentials.md

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)