5

I am trying to get the Google authorization code using a simple C# console application. The whole process is pretty simple: sending a request using a url containing a unique Client Id to Google Oauth2 endpoint, logging into the Google account and then get the authorization code:

string url = "https://accounts.google.com/o/oauth2/v2/auth?whatever";
Process.Start("chrome.exe", url); // open up browser so user can log in
// get the auth code from chrome

How I can get that generated code from Google chrome and pass it back to my app?

Yar
  • 7,020
  • 11
  • 49
  • 69

1 Answers1

1

Start another process that opens a web server. This web server will simply return the request URL code param it's getting.

In the OAuth flow set the callback URL to http://localhost:8080 (you will need to set it in the console as well).

So after the user consent, Google will redirect to localhost. your web server will catch the request (localhost?code=auth_code) and return the auth_code to the console like described here

Boaz
  • 1,212
  • 11
  • 25