I am trying to use the Node URL and URLSearchParams APIs to make URL building a bit simpler. I'm using it to build a URL like this:
https://<ye olde oauth host>/oauth/authorize?response_type=code&client_id=<my client id>&redirect_uri=https://localhost:4200&scopes=scope1%20scope2
However, my code below is creating the URL like this:
https://<ye olde oauth host>/oauth/authorize?response_type=code&client_id=<my client id>&redirect_uri=https%3A%2F%2Flocalhost%3A4200&scopes=scope1%20scope2
It's my understanding that the URLSearchParams API will percent-encode strings, but what if I don't want them to be encoded, like URLs? Here is my code:
const loginURL = new URL('https://<ye olde oauth host>');
url.pathname = 'oauth/authorize';
url.search = new URLSearchParams({
response_type: 'code',
client_id: '<my client id>'
}).toString();
loginURL.searchParams.append('redirect_uri', redirectURI);
loginURL.searchParams.append('scopes', scopes);
The reason I don't want the redirect_uri to be percent encoded is because the OAuth API on the receiving end doesn't know how to parse it. Is there any way using the URLSearchParams to stop it from encoding?