I am implementing a CLI client for an OAuth process in python. At the beginning, the user types the command which opens the browser to the login page. After the user sign in, the browser redirects to localhost:1234 (redirect uri passed during the oauth process), passing the authorization code as parameter.
Then my CLI client needs to listen to the redirection at port 1234 to continue the oauth process (ie make the POST call to the resource server to exchange the authorization code against an access token).
What is the simplest way to implement this listening to redirection?