Skip to content

Commit 502f53a

Browse files
committed
Added sample code for .NET 9
1 parent 205e4a7 commit 502f53a

File tree

1 file changed

+21
-1
lines changed
  • src/content/docs/identityserver/tokens

1 file changed

+21
-1
lines changed

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+
```cs {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)