Skip to content

Commit 0dae9b8

Browse files
committed
fixes 1046 - fix relative URL calculation for refreshUrl, tokenUrl and authorizationUrl
1 parent dde25c2 commit 0dae9b8

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/templates/security-scheme-template.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,34 @@ function oAuthFlowTemplate(flowName, clientId, clientSecret, securitySchemeId, a
260260
let { authorizationUrl, tokenUrl, refreshUrl } = authFlow;
261261
const pkceOnly = authFlow['x-pkce-only'] || false;
262262
const isUrlAbsolute = (url) => (url.indexOf('://') > 0 || url.indexOf('//') === 0);
263-
// Calculcate base URL
263+
/*
264+
Calculcate Relative URL based on the following logic
265+
IF this.selectedServer?.computedUrl ends with slash and the refreshUrl / tokenUrl / authorizationUrl do not start with slash
266+
THEN Relative URL is concatenate else use this.selectedServer?.computedUrl + refreshUrl / tokenUrl / authorizationUrl
267+
ELSE Relative URL is concatenate else use (origin of this.selectedServer?.computedUrl) + refreshUrl / tokenUrl / authorizationUrl
268+
*/
264269
const url = new URL(this.selectedServer?.computedUrl);
265-
const baseUrl = url.origin;
266-
270+
const originUrl = url.origin;
267271
if (refreshUrl && !isUrlAbsolute(refreshUrl)) {
268-
refreshUrl = `${baseUrl}/${refreshUrl.replace(/^\//, '')}`;
272+
if (this.selectedServer?.computedUrl.trim().endsWith('/') && !refreshUrl.trim().startsWith('/')) {
273+
refreshUrl = `${this.selectedServer?.computedUrl.trim()}${tokenUrl.trim()}`;
274+
} else {
275+
refreshUrl = `${originUrl}/${refreshUrl.replace(/^\//, '')}`;
276+
}
269277
}
270278
if (tokenUrl && !isUrlAbsolute(tokenUrl)) {
271-
tokenUrl = `${baseUrl}/${tokenUrl.replace(/^\//, '')}`;
279+
if (this.selectedServer?.computedUrl.trim().endsWith('/') && !tokenUrl.trim().startsWith('/')) {
280+
tokenUrl = `${this.selectedServer?.computedUrl.trim()}${tokenUrl.trim()}`;
281+
} else {
282+
tokenUrl = `${originUrl}/${tokenUrl.replace(/^\//, '')}`;
283+
}
272284
}
273285
if (authorizationUrl && !isUrlAbsolute(authorizationUrl)) {
274-
authorizationUrl = `${baseUrl}/${authorizationUrl.replace(/^\//, '')}`;
286+
if (this.selectedServer?.computedUrl.trim().endsWith('/') && !authorizationUrl.trim().startsWith('/')) {
287+
authorizationUrl = `${this.selectedServer?.computedUrl.trim()}${authorizationUrl.trim()}`;
288+
} else {
289+
authorizationUrl = `${originUrl}/${authorizationUrl.replace(/^\//, '')}`;
290+
}
275291
}
276292
let flowNameDisplay;
277293
if (flowName === 'authorizationCode') {

0 commit comments

Comments
 (0)