Skip to content

Commit

Permalink
chore: use pathBase middleware
Browse files Browse the repository at this point in the history
Co-authored-by: gentoo90
  • Loading branch information
AleF83 committed Jan 20, 2025
1 parent 8d0a586 commit 1008308
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
11 changes: 11 additions & 0 deletions e2e/tests/__snapshots__/base-path.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Base path Discovery Endpoint 1`] = `
{
"access-control-allow-origin": "https://google.com",
"content-type": "application/json; charset=UTF-8",
"date": Any<String>,
"server": "Kestrel",
"transfer-encoding": "chunked",
}
`;
7 changes: 6 additions & 1 deletion e2e/tests/base-path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ describe('Base path', () => {
});

test('Discovery Endpoint', async () => {
const response = await fetch(oidcDiscoveryEndpointWithBasePath);
const response = await fetch(oidcDiscoveryEndpointWithBasePath, {
headers: {
origin: 'https://google.com',
},
});
expect(response.ok).toBe(true);
const result = (await response.json()) as unknown;
expect(result).toHaveProperty('token_endpoint', oidcTokenUrlWithBasePath.href);
expect(Object.fromEntries(response.headers.entries())).toMatchSnapshot({ date: expect.any(String) });
});

test('Token Endpoint', async () => {
Expand Down
12 changes: 6 additions & 6 deletions src/Helpers/AspNetServicesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ namespace OpenIdConnectServer.Helpers
{
public class AspNetServicesOptions
{
public AspNetCorsOptions Cors { get; set; }
public AspNetCorsOptions? Cors { get; set; }

public IDictionary<string, AuthenticationOptions> Authentication { get; set; }
public SessionOptions Session { get; set; }
public IDictionary<string, AuthenticationOptions>? Authentication { get; set; }
public SessionOptions? Session { get; set; }

public ForwardedHeadersOptions ForwardedHeadersOptions { get; set; }
public ForwardedHeadersOptions? ForwardedHeadersOptions { get; set; }

public string BasePath { get; set; }
public string? BasePath { get; set; }
}

public class AuthenticationOptions
{
public CookieAuthenticationOptions CookieAuthenticationOptions { get; set; }
public CookieAuthenticationOptions? CookieAuthenticationOptions { get; set; }
}

public static class AspNetServicesHelper
Expand Down
2 changes: 1 addition & 1 deletion src/OpenIdConnectServerMock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<IsPackable>true</IsPackable>
<Description>Configurable mock server with OpenId Connect functionality</Description>
<VersionPrefix>0.10.1</VersionPrefix>
<VersionPrefix>0.11.1</VersionPrefix>
<PackageProjectUrl>https://github.com/Soluto/oidc-server-mock</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageTags>OIDC</PackageTags>
Expand Down
18 changes: 2 additions & 16 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

var app = builder.Build();

app.UsePathBase(Config.GetAspNetServicesOptions().BasePath);

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

app.UseIdentityServer();

var basePath = Config.GetAspNetServicesOptions().BasePath;
if (!string.IsNullOrEmpty(basePath))
{
app.UseWhen(ctx => ctx.Request.Path.StartsWithSegments(basePath), appBuilder =>
{
appBuilder.UseMiddleware<BasePathMiddleware>();
appBuilder.UseMiddleware<IdentityServerMiddleware>();
});
}

app.UseHttpsRedirection();

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

app.UseRouting();

app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});

app.MapDefaultControllerRoute();
app.MapRazorPages();

app.Run();

0 comments on commit 1008308

Please sign in to comment.