diff --git a/src/core/index.js b/src/core/index.js
index e5f68527ad4..6cb29a30142 100644
--- a/src/core/index.js
+++ b/src/core/index.js
@@ -36,7 +36,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 00000000000..df3c2a2536b
--- /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 73247781aed..dfb5d905cc2 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" })
+ })
})