Skip to content

Commit 661ad0c

Browse files
authored
Merge pull request #970 from DuendeSoftware/mb/pipeline
Clarify hosting guidance around UseAuthN/Z and update code snippets
2 parents e4c8014 + 9d2d0bf commit 661ad0c

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

  • src/content/docs/identityserver/fundamentals

src/content/docs/identityserver/fundamentals/hosting.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ You add the Duende IdentityServer engine to any ASP.NET Core application by addi
1313
dependency injection (DI) system and adding the middleware to the processing pipeline.
1414

1515
:::note
16-
While technically you could share the ASP.NET Core host between Duende IdentityServer, clients or APIs. We recommend
16+
While technically you could share the ASP.NET Core host between Duende IdentityServer, clients or APIs, we recommend
1717
putting your IdentityServer into a separate application.
1818
:::
1919

2020
## Dependency Injection System
2121

2222
You add the necessary services to the ASP.NET Core service provider by calling `AddIdentityServer` at application startup:
2323

24-
```cs
25-
//Program.cs
24+
```csharp
25+
// Program.cs
2626
var idsvrBuilder = builder.Services.AddIdentityServer(options =>
2727
{
2828
// ...
@@ -36,7 +36,7 @@ The builder object has a number of extension methods to add additional services
3636
You can see the full list in the [reference](/identityserver/reference/di.md) section, but very commonly you start by
3737
adding the configuration stores for clients and resources, e.g.:
3838

39-
```cs
39+
```csharp
4040
//Program.cs
4141
var idsvrBuilder = builder.Services.AddIdentityServer()
4242
.AddInMemoryClients(Config.Clients)
@@ -47,11 +47,18 @@ var idsvrBuilder = builder.Services.AddIdentityServer()
4747
The above is using the in-memory stores, but we also support EntityFramework-based implementations and custom stores.
4848
See [here](/identityserver/data) for more information.
4949

50-
## Request Pipeline
51-
5250
:::note
53-
`UseIdentityServer` includes a call to `UseAuthentication`, so it’s not necessary to have both.
54-
:::
51+
The `AddIdentityServer` extensions method also adds the required authentication services (it calls `AddAuthentication` internally).
52+
If you want to configure the authentication options, or be explicit about which services are registered, you can use the
53+
`AddAuthentication` (and `AddAuthorization`) extension method directly:
54+
55+
```csharp
56+
// Program.cs
57+
builder.Services.AddAuthentication();
58+
builder.Services.AddAuthorization();
59+
```
60+
61+
## Request Pipeline
5562

5663
You need to add the Duende IdentityServer middleware to the pipeline by calling `UseIdentityServer`.
5764

@@ -60,8 +67,9 @@ files, but before the UI framework like MVC.
6067

6168
This would be a very typical minimal pipeline:
6269

63-
```cs
70+
```csharp
6471
//Program.cs
72+
var app = builder.Build();
6573
app.UseStaticFiles();
6674

6775
app.UseRouting();
@@ -71,4 +79,11 @@ app.UseAuthorization();
7179
app.MapDefaultControllerRoute();
7280
```
7381

82+
:::note
83+
`UseIdentityServer` includes a call to `UseAuthentication`, so it’s not necessary to have both.
84+
85+
86+
However, IdentityServer does not include a call to `UseAuthorization`. You will need to add `UseAuthorization` (after `UseIdentityServer`/`UseAuthentication`) to include the authorization middleware into your pipeline. This will enable you to use various authorization features in your application.
7487

88+
If you use the Duende UI template and its various pages, the use of `UseAuthorization` is required.
89+
:::

0 commit comments

Comments
 (0)