Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cors error if BasePath is set #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions e2e/tests/base-path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ describe('Base path', () => {
expect(result).toHaveProperty('token_endpoint', process.env.OIDC_TOKEN_URL_WITH_BASE_PATH);
});

test('CORS', async () => {
const origin = 'https://google.com';
const response = await fetch(process.env.OIDC_DISCOVERY_ENDPOINT_WITH_BASE_PATH, {
headers: {
origin,
},
});
expect(response.headers.get('access-control-allow-origin')).toEqual(origin);
});

test('Token Endpoint', async () => {
if (!client) throw new Error('Client not found');

Expand Down
32 changes: 0 additions & 32 deletions src/Middlewares/BasePathMiddleware.cs

This file was deleted.

15 changes: 2 additions & 13 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Duende.IdentityServer.Hosting;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileProviders;
using OpenIdConnectServer;
using OpenIdConnectServer.Helpers;
using OpenIdConnectServer.JsonConverters;
using OpenIdConnectServer.Middlewares;
using OpenIdConnectServer.Services;
using OpenIdConnectServer.Validation;
using Serilog;
Expand Down Expand Up @@ -53,6 +51,7 @@

var app = builder.Build();

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

var aspNetServicesOptions = Config.GetAspNetServicesOptions();
AspNetServicesHelper.ConfigureAspNetServices(builder.Services, aspNetServicesOptions);
Expand All @@ -65,16 +64,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 Down
Loading