diff --git a/src/core/index.js b/src/core/index.js
index 621b095f..f7f3981f 100644
--- a/src/core/index.js
+++ b/src/core/index.js
@@ -31,7 +31,7 @@ export default function SwaggerUI(opts) {
maxDisplayedTags: null,
filter: null,
validatorUrl: "https://validator.swagger.io/validator",
- oauth2RedirectUrl: `${window.location.protocol}//${window.location.host}/oauth2-redirect.html`,
+ oauth2RedirectUrl: `${window.location.protocol}//${window.location.host}${window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"))}/oauth2-redirect.html`,
persistAuthorization: false,
configs: {},
custom: {},
diff --git a/test/e2e-cypress/static/pages/5085/index.html b/test/e2e-cypress/static/pages/5085/index.html
new file mode 100644
index 00000000..df3c2a25
--- /dev/null
+++ b/test/e2e-cypress/static/pages/5085/index.html
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+ Swagger UI
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/e2e-cypress/tests/features/dynamic-default-oauth.js b/test/e2e-cypress/tests/features/dynamic-default-oauth.js
index 73247781..dfb5d905 100644
--- a/test/e2e-cypress/tests/features/dynamic-default-oauth.js
+++ b/test/e2e-cypress/tests/features/dynamic-default-oauth.js
@@ -5,4 +5,22 @@ describe("dynamic default oauth2RedirectUrl", () => {
.then(win => win.ui.getConfigs())
.should("include", { oauth2RedirectUrl: "http://localhost:3230/oauth2-redirect.html" })
})
+ it("should compute an oauth2RedirectUrl based on the browser's location at runtime, including the path", () => {
+ cy.visit("/pages/5085/")
+ .window()
+ .then(win => win.ui.getConfigs())
+ .should("include", { oauth2RedirectUrl: "http://localhost:3230/pages/5085/oauth2-redirect.html" })
+ })
+ it("should compute an oauth2RedirectUrl based on the browser's location at runtime, including the path, without confusing the file name for a folder name", () => {
+ cy.visit("/pages/5085/index.html")
+ .window()
+ .then(win => win.ui.getConfigs())
+ .should("include", { oauth2RedirectUrl: "http://localhost:3230/pages/5085/oauth2-redirect.html" })
+ })
+ it("should compute an oauth2RedirectUrl based on the browser's location at runtime, including the path, even it does not end with a slash", () => {
+ cy.visit("/pages/5085")
+ .window()
+ .then(win => win.ui.getConfigs())
+ .should("include", { oauth2RedirectUrl: "http://localhost:3230/pages/5085/oauth2-redirect.html" })
+ })
})