@@ -16,7 +16,36 @@ redirect_from:
1616 - /identityserver/v7/configuration/dcr/installation/
1717---
1818
19- import { Steps } from " @astrojs/starlight/components" ;
19+ import { Code , Steps } from " @astrojs/starlight/components" ;
20+
21+ export const addMainPackageSnippet = `
22+ cd Configuration
23+ dotnet add package Duende.IdentityServer.Configuration
24+ ` ;
25+
26+ export const addStoragePackageSnippet = ` dotnet add package Duende.IdentityServer.Configuration.EntityFramework ` ;
27+
28+ export const licenseSnippet = `
29+ builder.Services.AddIdentityServerConfiguration(opt =>
30+ opt.LicenseKey = "<license>";
31+ );
32+ ` ;
33+
34+ export const dbConfigurationSnippet = `
35+ builder.Services.AddIdentityServerConfiguration(opt =>
36+ opt.LicenseKey = "<license>"
37+ ).AddClientConfigurationStore(); ` + ' \r\n ' + `
38+ var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
39+ builder.Services.AddConfigurationDbContext<ConfigurationDbContext>(options =>
40+ {
41+ options.ConfigureDbContext = builder => builder.UseSqlite(connectionString);
42+ });
43+ ` ;
44+
45+ export const mapDcrEndpointSnippet = `
46+ app.MapDynamicClientRegistration()
47+ .RequireAuthorization("DCR");
48+ ` ;
2049
2150Dynamic Client Registration (DCR) is the process of registering OAuth clients
2251dynamically. It allows OAuth client applications to programmatically register
@@ -53,31 +82,24 @@ To host the Configuration API separately from IdentityServer, you will need to
5382create a new ASP.NET Core Web application which will host the Configuration API.
5483
5584<Steps >
85+
56861 . ** Create a new project of type "Empty Web Application"**
5787
5888 ``` bash title=Terminal
5989 dotnet new web -n Configuration
6090 ```
6191
62922 . ** Add the ` Duende.IdentityServer.Configuration ` package**
63-
64- ``` bash title=Terminal
65- cd Configuration
66- dotnet add package Duende.IdentityServer.Configuration
67- ```
68-
93+
94+ <Code code = { addMainPackageSnippet } lang = " bash" title = " Terminal" />
95+
69963 . ** Configure services to include the Configuration API**
70-
71- ``` csharp
72- // Program.cs
73- builder .Services .AddIdentityServerConfiguration (opt =>
74- opt .LicenseKey = " <license>" ;
75- );
76- ```
97+
98+ <Code code = { licenseSnippet } lang = " csharp" title = " Program.cs" />
7799
78100 :::note
79101 This feature is part of the [ Duende IdentityServer Business and Enterprise Edition] ( https://duendesoftware.com/products/identityserver ) .
80- Configure the same license key for IdentityServer and the Configuration API.
102+ You don't need to acquire an additional license, use the same license key for Duende IdentityServer and the DCR Configuration API.
81103 :::
82104
831054 . ** Add and configure the client configuration store**
@@ -90,43 +112,27 @@ create a new ASP.NET Core Web application which will host the Configuration API.
90112 the interface yourself. See [ the IClientConfigurationStore reference] ( /identityserver/reference/stores/index.md )
91113 for more details. If you wish to use the built-in implementation, install its NuGet
92114 package and add it to the ASP.NET Core service provider.
93-
94- ``` bash title=Terminal
95- dotnet add package Duende.IdentityServer.Configuration.EntityFramework
96- ```
115+
116+ <Code code = { addStoragePackageSnippet } lang = " bash" title = " Terminal" />
97117
98118 The ` AddClientConfigurationStore() ` extension method registers the built-in
99119 implementation of the ` IClientConfigurationStore ` interface with the service
100120 provider. Make sure to also configure the connection string to the
101121 [ configuration store] ( /identityserver/data/ef.md#configuration-store-support ) :
102122
103- ``` csharp {4}
104- // Program.cs
105- builder .Services .AddIdentityServerConfiguration (opt =>
106- opt .LicenseKey = " <license>"
107- ).AddClientConfigurationStore ();
108-
109- var connectionString = builder .Configuration .GetConnectionString (" DefaultConnection" );
110- builder .Services .AddConfigurationDbContext <ConfigurationDbContext >(options =>
111- {
112- options .ConfigureDbContext = builder => builder .UseSqlite (connectionString );
113- });
114- ```
115-
123+ <Code code = { dbConfigurationSnippet } lang = " csharp" title = " Program.cs" mark = { [3 ]} />
124+
1161255 . ** Map the Configuration API endpoints**
117-
118- ``` csharp
119- // Program.cs
120- app .MapDynamicClientRegistration ()
121- .RequireAuthorization (" DCR" );
122- ```
123-
126+
127+ <Code code = { mapDcrEndpointSnippet } lang = " csharp" title = " Program.cs" />
128+
124129 The ` MapDynamicClientRegistration ` extension method registers the DCR endpoints
125130 and returns an ` IEndpointConventionBuilder ` which you can use to define authorization
126131 requirements for your DCR endpoint.
127132
128133 See [ Authorization] ( #authorization ) for more details about implementing authorization for
129134 the DCR endpoint.
135+
130136</Steps >
131137
132138### Shared Host For Configuration API and IdentityServer
@@ -136,26 +142,18 @@ You'll need to add the Configuration API's services to the service collection,
136142and configure the store implementation.
137143
138144<Steps >
145+
1391461 . ** Add the ` Duende.IdentityServer.Configuration ` package**
140147
141- ``` bash title=Terminal
142- cd Configuration
143- dotnet add package Duende.IdentityServer.Configuration
144- ```
148+ <Code code = { addMainPackageSnippet } lang = " bash" title = " Terminal" />
145149
1461502 . ** Configure services to include the Configuration API**
147151
148- ``` csharp
149- // Program.cs
150- builder .Services .AddIdentityServerConfiguration (opt =>
151- opt .LicenseKey = " <license>" ;
152- );
153- ```
152+ <Code code = { licenseSnippet } lang = " csharp" title = " Program.cs" />
154153
155154 :::note
156- The Configuration API feature is included in the Duende IdentityServer Business
157- edition license and higher. Use the same license key for IdentityServer and the
158- Configuration API.
155+ This feature is part of the [ Duende IdentityServer Business and Enterprise Edition] ( https://duendesoftware.com/products/identityserver ) .
156+ You don't need to acquire an additional license, use the same license key for Duende IdentityServer and the DCR Configuration API.
159157 :::
160158
1611593 . ** Add and configure the client configuration store**
@@ -169,45 +167,69 @@ and configure the store implementation.
169167 for more details. If you wish to use the built-in implementation, install its NuGet
170168 package and add it to the ASP.NET Core service provider.
171169
172- ``` bash title=Terminal
173- dotnet add package Duende.IdentityServer.Configuration.EntityFramework
174- ```
170+ <Code code = { addStoragePackageSnippet } lang = " bash" title = " Terminal" />
175171
176172 The ` AddClientConfigurationStore() ` extension method registers the built-in
177173 implementation of the ` IClientConfigurationStore ` interface with the service
178174 provider. Make sure to also configure the connection string to the
179175 [ configuration store] ( /identityserver/data/ef.md#configuration-store-support ) if
180176 you haven't already as part of your IdentityServer host:
181177
182- ``` csharp {4}
183- // Program.cs
184- builder .Services .AddIdentityServerConfiguration (opt =>
185- opt .LicenseKey = " <license>"
186- ).AddClientConfigurationStore ();
187-
188- var connectionString = builder .Configuration .GetConnectionString (" DefaultConnection" );
189- builder .Services .AddConfigurationDbContext <ConfigurationDbContext >(options =>
190- {
191- options .ConfigureDbContext = builder => builder .UseSqlite (connectionString );
192- });
193- ```
178+ <Code code = { dbConfigurationSnippet } lang = " csharp" title = " Program.cs" mark = { [3 ]} />
194179
1951804 . ** Map the Configuration API endpoints**
196181
197- ``` csharp
198- // Program.cs
199- app .MapDynamicClientRegistration ()
200- .RequireAuthorization (" DCR" );
201- ```
182+ <Code code = { mapDcrEndpointSnippet } lang = " csharp" title = " Program.cs" />
202183
203184 The ` MapDynamicClientRegistration ` extension method registers the DCR endpoints
204185 and returns an ` IEndpointConventionBuilder ` which you can use to define authorization
205186 requirements for your DCR endpoint.
206187
207188 See [ Authorization] ( #authorization ) for more details about implementing authorization for
208189 the DCR endpoint.
190+
209191</Steps >
210192
193+ ### Adding the Registration Endpoint to the Discovery Document
194+
195+ By default, the Dynamic Client Registration (DCR) endpoint is not included in the [ discovery document] ( /identityserver/reference/endpoints/discovery.md ) of Duende IdentityServer.
196+
197+ To include it, change the Discovery Document options when registering IdentityServer in the service collection:
198+
199+ ``` csharp
200+ // Program.cs
201+ builder .Services .AddIdentityServer (options =>
202+ {
203+ // Either use a static URL for the registration endpoint, when hosted outside of IdentityServer:
204+ options .Discovery .DynamicClientRegistration .RegistrationEndpointMode =
205+ RegistrationEndpointMode .Static ;
206+
207+ options .Discovery .DynamicClientRegistration .StaticRegistrationEndpoint =
208+ new Uri (" https://my-configuration-api/connect/dcr" );
209+
210+ // Or use inferred when the registration endpoint is hosted within IdentityServer:
211+ options .Discovery .DynamicClientRegistration .RegistrationEndpointMode =
212+ RegistrationEndpointMode .Inferred ;
213+ });
214+ ```
215+
216+ :::note
217+ DCR support was added to Duende IdentityServer v7.4. If you cannot upgrade your IdentityServer solution yet,
218+ you'll have to add custom entries to the Discovery Document instead:
219+
220+ ``` csharp
221+ // Program.cs
222+ using Duende .IdentityModel ;
223+
224+ builder .Services .AddIdentityServer (options =>
225+ {
226+ options .Discovery .CustomEntries .Add
227+ OidcConstants .Discovery .RegistrationEndpoint ,
228+ " https://my-configuration-api/connect/dcr" );
229+ });
230+ ```
231+ :::
232+
211233## Authorization
212234
213235When implementing Dynamic Client Registration (DCR), it is important to consider
@@ -339,4 +361,4 @@ For more details, see the [reference section on DCR request processing](/identit
339361To customize the HTTP responses of the Configuration API, you can implement the ` IDynamicClientRegistrationResponseGenerator `
340362interface, or extend the default ` DynamicClientRegistrationResponseGenerator ` .
341363
342- For more details, see the [ reference section on rDCR esponse generation] ( /identityserver/reference/dcr/response.md ) .
364+ For more details, see the [ reference section on DCR response generation] ( /identityserver/reference/dcr/response.md ) .
0 commit comments