Skip to content

Commit 1008308

Browse files
committed
chore: use pathBase middleware
Co-authored-by: gentoo90
1 parent 8d0a586 commit 1008308

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Base path Discovery Endpoint 1`] = `
4+
{
5+
"access-control-allow-origin": "https://google.com",
6+
"content-type": "application/json; charset=UTF-8",
7+
"date": Any<String>,
8+
"server": "Kestrel",
9+
"transfer-encoding": "chunked",
10+
}
11+
`;

e2e/tests/base-path.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ describe('Base path', () => {
1313
});
1414

1515
test('Discovery Endpoint', async () => {
16-
const response = await fetch(oidcDiscoveryEndpointWithBasePath);
16+
const response = await fetch(oidcDiscoveryEndpointWithBasePath, {
17+
headers: {
18+
origin: 'https://google.com',
19+
},
20+
});
1721
expect(response.ok).toBe(true);
1822
const result = (await response.json()) as unknown;
1923
expect(result).toHaveProperty('token_endpoint', oidcTokenUrlWithBasePath.href);
24+
expect(Object.fromEntries(response.headers.entries())).toMatchSnapshot({ date: expect.any(String) });
2025
});
2126

2227
test('Token Endpoint', async () => {

src/Helpers/AspNetServicesHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ namespace OpenIdConnectServer.Helpers
66
{
77
public class AspNetServicesOptions
88
{
9-
public AspNetCorsOptions Cors { get; set; }
9+
public AspNetCorsOptions? Cors { get; set; }
1010

11-
public IDictionary<string, AuthenticationOptions> Authentication { get; set; }
12-
public SessionOptions Session { get; set; }
11+
public IDictionary<string, AuthenticationOptions>? Authentication { get; set; }
12+
public SessionOptions? Session { get; set; }
1313

14-
public ForwardedHeadersOptions ForwardedHeadersOptions { get; set; }
14+
public ForwardedHeadersOptions? ForwardedHeadersOptions { get; set; }
1515

16-
public string BasePath { get; set; }
16+
public string? BasePath { get; set; }
1717
}
1818

1919
public class AuthenticationOptions
2020
{
21-
public CookieAuthenticationOptions CookieAuthenticationOptions { get; set; }
21+
public CookieAuthenticationOptions? CookieAuthenticationOptions { get; set; }
2222
}
2323

2424
public static class AspNetServicesHelper

src/OpenIdConnectServerMock.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<IsPackable>true</IsPackable>
1010
<Description>Configurable mock server with OpenId Connect functionality</Description>
11-
<VersionPrefix>0.10.1</VersionPrefix>
11+
<VersionPrefix>0.11.1</VersionPrefix>
1212
<PackageProjectUrl>https://github.com/Soluto/oidc-server-mock</PackageProjectUrl>
1313
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1414
<PackageTags>OIDC</PackageTags>

src/Program.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
var app = builder.Build();
5555

56+
app.UsePathBase(Config.GetAspNetServicesOptions().BasePath);
5657

5758
var aspNetServicesOptions = Config.GetAspNetServicesOptions();
5859
AspNetServicesHelper.ConfigureAspNetServices(builder.Services, aspNetServicesOptions);
@@ -65,16 +66,6 @@
6566

6667
app.UseIdentityServer();
6768

68-
var basePath = Config.GetAspNetServicesOptions().BasePath;
69-
if (!string.IsNullOrEmpty(basePath))
70-
{
71-
app.UseWhen(ctx => ctx.Request.Path.StartsWithSegments(basePath), appBuilder =>
72-
{
73-
appBuilder.UseMiddleware<BasePathMiddleware>();
74-
appBuilder.UseMiddleware<IdentityServerMiddleware>();
75-
});
76-
}
77-
7869
app.UseHttpsRedirection();
7970

8071
var manifestEmbeddedProvider = new ManifestEmbeddedFileProvider(typeof(Program).Assembly, "wwwroot");
@@ -84,13 +75,8 @@
8475
});
8576

8677
app.UseRouting();
87-
8878
app.UseAuthorization();
89-
app.UseEndpoints(endpoints =>
90-
{
91-
endpoints.MapDefaultControllerRoute();
92-
});
93-
79+
app.MapDefaultControllerRoute();
9480
app.MapRazorPages();
9581

9682
app.Run();

0 commit comments

Comments
 (0)