Skip to content

Commit e14ded1

Browse files
authored
Merge pull request #712 from DuendeSoftware/wca/par-clarification
PAR guidance for .NET 9 and difference with .NET 8
2 parents 4e2e3b1 + 597ed9d commit e14ded1

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/content/docs/identityserver/samples/basics.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Key takeaways:
2121

2222
* how to request a token using client credentials
2323
* how to use a shared secret
24-
* how to use access token
24+
* how to use an access token
2525

2626
[link to source code](https://github.com/DuendeSoftware/Samples/tree/main/IdentityServer/v7/Basics/ClientCredentials)
2727

@@ -125,4 +125,13 @@ Key takeaways:
125125
would normally be sent in that redirect with the resulting request uri. See the `ParOidcEvents.cs` file for more
126126
details.
127127

128+
:::note
129+
This sample is only relevant if you're using .NET 8 or lower.
130+
131+
[.NET 9 has support for PAR built-in][ms-learn-par], and the ASP.NET Core OIDC authentication handler will automatically use
132+
PAR when the authority supports it, based on the discovery metadata.
133+
:::
134+
128135
[link to source code](https://github.com/DuendeSoftware/Samples/tree/main/IdentityServer/v7/Basics/MvcPar)
136+
137+
[ms-learn-par]: https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-9.0?view=aspnetcore-9.0#openidconnecthandler-adds-support-for-pushed-authorization-requests-par

src/content/docs/identityserver/tokens/par.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,27 @@ were just pushed. From there, the OAuth or OIDC flow continues as normal. For ex
5858
the user will be redirected to log in and other UI pages as necessary before being redirected back to the client with an
5959
authorization code which the client subsequently exchanges for tokens.
6060

61-
A sample of how to implement this flow in an ASP.NET application is
61+
If you're building an ASP.NET Core application using .NET 9 or higher, using PAR is very straightforward:
62+
63+
```csharp {13-15}
64+
// Program.cs
65+
builder.Services
66+
.AddAuthentication(options =>
67+
{
68+
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
69+
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
70+
})
71+
.AddCookie()
72+
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, oidcOptions =>
73+
{
74+
// Your authority, client ID, ... configuration goes here.
75+
76+
// By default, PushedAuthorizationBehavior is set to PushedAuthorizationBehavior.UseIfAvailable.
77+
// You can also require using PAR:
78+
oidcOptions.PushedAuthorizationBehavior = PushedAuthorizationBehavior.Require;
79+
});
80+
```
81+
.NET 8 does not have built-in support for PAR. If you're using .NET 8, we have a sample of how to implement this flow
6282
available [here](/identityserver/samples/basics#mvc-client-with-pushed-authorization-requests).
6383

6484
## Data Store

0 commit comments

Comments
 (0)