Skip to content

Commit 33663be

Browse files
authored
Merge pull request #709 from DuendeSoftware/mb/dataprotectionis4
Update IdentityServer upgrade guide with data protection setup
2 parents d701c57 + 6fb0766 commit 33663be

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

src/content/docs/identityserver/upgrades/identityserver4-to-duende-identityserver-v7.mdx

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ You'll need to make a similar change for all IdentityServer4 packages, including
351351
+ <PackageReference Include="Duende.IdentityServer.EntityFramework" Version="7.2.0" />
352352
```
353353

354-
The IdentityModel package was renamed to Duende IdentityModel, and needs updating if you reference it directly:
354+
The IdentityModel package was renamed to Duende IdentityModel and needs updating if you reference it directly:
355355

356356
```diff lang="xml" title=".csproj"
357357
- <PackageReference Include="IdentityModel" Version="x.y.z" />
@@ -454,14 +454,66 @@ When upgrading, consider how those applications will handle an upgraded token se
454454
- If you can restart all client apps and APIs that depend on your current signing key, you can remove the old signing key and start to use automatic key management. A restart reloads the discovery document and the new signing key.
455455
- If you can not restart client apps and APIs, check the [manual and automatic key rotation topics](../../fundamentals/key-management#manual-key-rotation) to learn how to announce new signing key material while still supporting the old signing key for a period of time.
456456

457-
### Step 7: Validate Your Deployment
457+
### Step 7: Verify Data Protection Configuration :badge[Optional]
458+
459+
Duende IdentityServer depends on [ASP.NET Data Protection](/identityserver/deployment.md#aspnet-core-data-protection) to encrypt and sign data using keys managed by ASP.NET.
460+
461+
As part of your migration, verify the application name is set in your Data Protection configuration:
462+
463+
```csharp title="Program.cs" {4}
464+
builder.Services.AddDataProtection()
465+
.PersistKeysTo...()
466+
.ProtectKeysWith...()
467+
.SetApplicationName("IdentityServerXYZ");
468+
```
469+
470+
If an application name is set, you can skip this section.
471+
472+
Data Protection keys are isolated by application name, to prevent multiple applications from sharing encryption keys.
473+
474+
If no application name is configured, ASP.NET Data Protection uses the content root path of the IdentityServer host as the application name.
475+
As a consequence, if your content root path changes, the default settings for data protection will prevent you from using your old data protection keys.
476+
477+
Between different .NET versions, this default setting has changed:
478+
479+
| Version | Default |
480+
| -------- | -------------------------------------------------------------- |
481+
| .NET 3.1 | Content root path without directory separator suffix |
482+
| .NET 5 | Content root path without directory separator suffix |
483+
| .NET 6 | Content root path (normalized with directory separator suffix) |
484+
| .NET 7+ | Content root path without directory separator suffix |
485+
486+
Your application name might change (and existing data protection keys may become invalid) if you are currently targeting .NET 6 and do not have the application name set explicitly.
487+
488+
To prevent this from happening, you can explicitly set the application name to the content root path without the directory separator character, as [documented on Microsoft Learn](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-6.0#setapplicationname).
489+
490+
:::tip[Getting the current application name]
491+
In your current (pre-upgraded) IdentityServer version, you can query the application name used and set it explicitly in your upgraded deployment:
492+
493+
```csharp
494+
// ...
495+
496+
var app = builder.Build();
497+
498+
// ...
499+
var applicationName = app.Services
500+
.GetRequiredService<IOptions<DataProtectionOptions>>()
501+
.Value.ApplicationDiscriminator;
502+
503+
// applicationName is now the (auto-generated?) application name
504+
// - you can use it in your upgraded IdentityServer version
505+
```
506+
507+
:::
508+
509+
### Step 8: Validate Your Deployment
458510

459511
Congratulations! Your upgrade is complete.
460512

461513
Make sure to validate and test your Duende IdentityServer is working as expected, and check integrations with your client applications and APIs.
462514

463515
:::note
464-
IdentityServer is free for development, testing and personal projects, but production use
516+
IdentityServer is free for development, testing, and personal projects, but production use
465517
requires a [license](https://duendesoftware.com/products/identityserver).
466518
:::
467519

@@ -476,7 +528,7 @@ As part of your upgrade from IdentityServer4 to Duende IdentityServer, we recomm
476528
- [Addition of cancellation token to store APIs](https://github.com/DuendeSoftware/IdentityServer/pull/405)
477529
- [Store DbContext constructors to support DbContext pooling](https://github.com/DuendeSoftware/IdentityServer/pull/260)
478530
- [CustomRedirectResult returnUrl changes](https://github.com/DuendeSoftware/IdentityServer/pull/358)
479-
- [Add missing columns for created, updated, etc to EF entities](https://github.com/DuendeSoftware/IdentityServer/pull/356)
531+
- [Add missing columns for created, updated, etc. to EF entities](https://github.com/DuendeSoftware/IdentityServer/pull/356)
480532
- [Add unique constraints to EF tables where duplicate records not allowed](https://github.com/DuendeSoftware/IdentityServer/pull/355)
481533
- [Added grant handle versioning suffix](https://github.com/DuendeSoftware/IdentityServer/pull/404)
482534
- [Many HttpContext extensions marked obsolete](https://github.com/DuendeSoftware/IdentityServer/pull/414)

0 commit comments

Comments
 (0)