From d2d4325145e34838d43c3dc38d5c563484fd28dc Mon Sep 17 00:00:00 2001 From: Adriano Lettieri Date: Tue, 2 Nov 2021 19:00:32 +0100 Subject: [PATCH] Managed query string parameters in the authorize endpoint. --- src/AuthService.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/AuthService.ts b/src/AuthService.ts index d4d1d8c..09653c5 100644 --- a/src/AuthService.ts +++ b/src/AuthService.ts @@ -156,7 +156,10 @@ export class AuthService { client_id: clientId, post_logout_redirect_uri: redirectUri } - const url = `${logoutEndpoint || `${provider}/logout`}?${toUrlEncoded(query)}` + const logoutUrl = `${logoutEndpoint || `${provider}/logout`}`; + // Check if the url already contains at least one parameter + const separator = new RegExp('^.*\?.+=.+$').test(logoutUrl) ? '&' : '?'; + const url = logoutUrl + separator + toUrlEncoded(query); window.location.replace(url) return true; } else { @@ -189,7 +192,10 @@ export class AuthService { codeChallengeMethod: 'S256' } // Responds with a 302 redirect - const url = `${authorizeEndpoint || `${provider}/authorize`}?${toUrlEncoded(query)}` + const authorizeUrl = `${authorizeEndpoint || `${provider}/authorize`}`; + // Check if the url already contains at least one parameter + const separator = new RegExp('^.*\?.+=.+$').test(authorizeUrl) ? '&' : '?'; + const url = authorizeUrl + separator + toUrlEncoded(query); window.location.replace(url) return true }