Google Installed Application OAuth2 Flow Without User Interaction

Tags

, ,

In this journey, I augmented my knowledge on OAuth specially its 2nd version while trying to implement an OAuth authentication and authorization flow that did not pop up a browser as is the case when using the Google apis for OAuth.  By the way, Although the title of this post mentions Installed Application, the app was actually an ASP.NET MVC app.  The app runs a Job on schedule and as part of its tasks,  interaction with Google services is a requirement for the usual CRUD operation if I may put it that way; When using the Google apis to authenticate to its services, the usual workflow is as follow: the client library constructs an url with all the required identifiers including a redirect_url that points to the local host on an available port, and launches a browser with the GET method to constructed URL in parallel with an HttpListener awaiting for the authentication code arrival on the IP endpoint specified for the redirect_url.  My route to discharge got me playing around with HttpClient, followed by HTMLAgilityPack, followed by SimpleBrowser.  Google with all the JavaScript inside its pages made my attempts not so of a straight shot.  SimpleBrowser is a really nice and performing piece of code, but its lack of JavaScript engine limited it in the final bouts.  As my last resort, NHTMLUnit as slow as it can be did it for me.  Inside my implementation of ICodeReceiver.ReceiveCodeAsync, I relied on NHTMLUnit as the headless browser it is to authenticate and authorize my account with a refresh token I may add.  Some journeys never ends, some do, and for us new ones are always exiting.

Follow

Get every new post delivered to your Inbox.