'Get params from constructed URL after being redirected

I working on solving this problem with my very limited knowledge when it comes to OAuth2.

This question revolves around a way that I'm trying to work around it.

I want to retrieve data from a URL, but for the data to be provided, I have to click the link I've constructed to be redirected.

So how can I fetch the desired string?

To sumarize. authorizeURL redirects me to a link where I want to get the code param from.

let url = authorizeURL;
let params = (new URL(url)).searchParams;
var code = params.get('code');
console.log(code);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source