Skip to content

Commit 8575bcc

Browse files
committed
EnableStatusCodePagesIntegration.
1 parent c8a8f99 commit 8575bcc

File tree

7 files changed

+65
-27
lines changed

7 files changed

+65
-27
lines changed

docs/en/Modules/OpenIddict.md

+32-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ This module implements the domain logic and database integrations, but not provi
1212

1313
This module is based on the [Identity Module](Identity.md) and have an [integration package](https://www.nuget.org/packages/Volo.Abp.Account.Web.IdentityServer) with the [Account Module](Account.md).
1414

15+
## OpenIddict documentation
16+
17+
For more details about OpenIddict, please refer to its official documentation and Github.
18+
19+
https://documentation.openiddict.com
20+
21+
https://github.com/openiddict/openiddict-core#resources
22+
1523
## The module
1624

1725
### Demo projects
@@ -65,6 +73,11 @@ IOpenIddictTokenRepository
6573
We enabled most of OpenIddict's features in the `AddOpenIddict` method, You can change OpenIddict's related builder options via `PreConfigure`.
6674

6775
```cs
76+
PreConfigure<OpenIddictBuilder>(builder =>
77+
{
78+
//builder
79+
});
80+
6881
PreConfigure<OpenIddictCoreBuilder>(builder =>
6982
{
7083
//builder
@@ -154,7 +167,14 @@ Implements the above four repository interfaces.
154167
Implements the above four repository interfaces.
155168

156169

157-
### Principle of OpenIddict
170+
## OpenIddict
171+
172+
173+
### PKCE
174+
175+
https://documentation.openiddict.com/configuration/proof-key-for-code-exchange.html
176+
177+
### Request/Response process
158178

159179
I will briefly introduce the principle of OpenIddict so that everyone can quickly understand it.
160180

@@ -166,14 +186,16 @@ It will be executed first in `AuthenticationMiddleware` and can short-circuit th
166186

167187
Example a token request:
168188

169-
```cs
170-
POST /connect/token
171-
grant_type:password
172-
client_id:AbpApp
173-
client_secret:1q2w3e*
174-
username:admin
175-
password:1q2w3E*
176-
scope:AbpAPI offline_access
189+
```
190+
POST /connect/token HTTP/1.1
191+
Content-Type: application/x-www-form-urlencoded
192+
193+
grant_type=password&
194+
client_id=AbpApp&
195+
client_secret=1q2w3e*&
196+
username=admin&
197+
password=1q2w3E*&
198+
scope=AbpAPI offline_access
177199
```
178200

179201
This request will be processed by various handlers. They will confirm the endpoint type of the request, check `http/https`, verify that the request parameters (`client. scope etc`) are valid and exist in the database, etc. Various protocol checks. And build a `OpenIddictRequest` object, If there are any errors, the response content may be set and directly short-circuit the current request.
@@ -190,8 +212,7 @@ If you need to customize OpenIddict, you need to replace/delete/add new handlers
190212

191213
Please refer to:
192214
https://documentation.openiddict.com/guides/index.html#events-model
193-
https://kevinchalet.com/2018/07/02/implementing-advanced-scenarios-using-the-new-openiddict-rc3-events-model/
194215

195216
## Sponsor
196217

197-
Please consider sponsoring this project if OpenIddict helped you: https://github.com/sponsors/kevinchalet
218+
Please consider sponsoring this project: https://github.com/sponsors/kevinchalet
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page
2+
@using Microsoft.AspNetCore.Authentication
23
@model IndexModel
34
@{
45
ViewData["Title"] = "Home page";
@@ -7,17 +8,22 @@
78
<div class="text-center">
89
<h1 class="display-4">Welcome</h1>
910
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
10-
11+
1112
<a class="btn btn-primary" href="/Login">Login</a>
1213
<a class="btn btn-warning" href="/Logout">Loout</a>
13-
14+
1415
@if (HttpContext.User.Identity != null && HttpContext.User.Identity.IsAuthenticated)
1516
{
1617
<ul class="list-group mt-3 text-start">
17-
@foreach (var claim in HttpContext.User.Claims)
18-
{
19-
<li class="list-group-item">@claim.Type : @claim.Value</li>
20-
}
18+
@foreach (var claim in HttpContext.User.Claims)
19+
{
20+
<li class="list-group-item">@claim.Type : @claim.Value</li>
21+
}
2122
</ul>
23+
24+
<p>HttpContext.GetTokenAsync("access_token")
25+
<br/>
26+
@await HttpContext.GetTokenAsync("access_token")
27+
</p>
2228
}
2329
</div>

modules/openiddict/app/OpenIddict.Demo.Client.Mvc/Program.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
options.GetClaimsFromUserInfoEndpoint = true;
2828
options.SaveTokens = true;
2929

30-
options.ResponseType = OidcConstants.ResponseTypes.CodeIdToken;
30+
options.UsePkce = true;
31+
32+
options.ResponseType = OidcConstants.ResponseTypes.Code;
3133

3234
options.SignOutScheme = "Cookies";
3335

modules/openiddict/app/OpenIddict.Demo.Server/EntityFrameworkCore/ServerDataSeedContributor.cs

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ await _applicationManager.CreateAsync(new OpenIddictApplicationDescriptor
9191
OpenIddictConstants.Permissions.Scopes.Email,
9292
OpenIddictConstants.Permissions.Scopes.Address,
9393
OpenIddictConstants.Permissions.Scopes.Phone,
94-
9594
OpenIddictConstants.Permissions.Prefixes.Scope + "AbpAPI"
9695
}
9796
});

modules/openiddict/app/OpenIddict.Demo.Server/Program.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using OpenIddict.Demo.Server;
2+
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
23
using Volo.Abp.Localization;
34
using Volo.Abp.OpenIddict.Jwt;
45

@@ -41,12 +42,17 @@
4142
var app = builder.Build();
4243
await app.InitializeApplicationAsync();
4344

45+
if (app.Environment.IsDevelopment())
46+
{
47+
app.UseDeveloperExceptionPage();
48+
}
49+
4450
app.UseAbpRequestLocalization();
4551

4652
// Configure the HTTP request pipeline.
4753
if (!app.Environment.IsDevelopment())
4854
{
49-
app.UseExceptionHandler("/Error");
55+
app.UseErrorPage();
5056
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
5157
app.UseHsts();
5258
}

modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
2525
.EnableTokenEndpointPassthrough()
2626
.EnableUserinfoEndpointPassthrough()
2727
.EnableLogoutEndpointPassthrough()
28-
.EnableVerificationEndpointPassthrough();
28+
.EnableVerificationEndpointPassthrough()
29+
.EnableStatusCodePagesIntegration();
2930
});
3031
}
3132

modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictDomainModule.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private static void AddOpenIddict(IServiceCollection services)
5454
})
5555
.AddServer(builder =>
5656
{
57-
// Can be enable by Configure OpenIddictServerOptions.DisableAccessTokenEncryption = false
57+
// Access token encryption can only be disabled when using JWT tokens.
5858
builder.DisableAccessTokenEncryption();
5959

6060
builder
@@ -84,20 +84,23 @@ private static void AddOpenIddict(IServiceCollection services)
8484

8585
builder.RegisterScopes(new[]
8686
{
87-
OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.Email,
88-
OpenIddictConstants.Scopes.Profile, OpenIddictConstants.Scopes.Phone,
89-
OpenIddictConstants.Scopes.Roles, OpenIddictConstants.Scopes.Address,
87+
OpenIddictConstants.Scopes.OpenId,
88+
OpenIddictConstants.Scopes.Email,
89+
OpenIddictConstants.Scopes.Profile,
90+
OpenIddictConstants.Scopes.Phone,
91+
OpenIddictConstants.Scopes.Roles,
92+
OpenIddictConstants.Scopes.Address,
9093
OpenIddictConstants.Scopes.OfflineAccess
9194
});
9295

9396
if (builderOptions.AddDevelopmentEncryptionAndSigningCertificate)
9497
{
95-
builder.AddDevelopmentEncryptionCertificate()
98+
builder
99+
.AddDevelopmentEncryptionCertificate()
96100
.AddDevelopmentSigningCertificate();
97101
}
98102

99103
services.ExecutePreConfiguredActions(builder);
100-
101104
});
102105

103106
services.Configure<OpenIddictCoreOptions>(options =>

0 commit comments

Comments
 (0)