In this article, I’m happy to introduce you the OAuth authorization via Phonegap’s inAppBrowser plugin with CordovaSim.
I was inspired to write this blog after reading a great article about Google API OAuth with PhoneGap’s InAppBrowser by Michael Dellanoce. I also want to spill the beans about new CordovaSim’s features like: JavaFx web engine, hybrid app debugging and eclipse console logging, that will be available in Beta3 (but you can try them now from the nightly build 4.2.x update site).
OAuth is an open standard for authorization. It specifies a process for resource owners to authorize third-party access to their server resources without sharing their credentials. Designed specifically to work with Hypertext Transfer Protocol (HTTP), OAuth essentially allows access tokens to be issued to third-party clients by an authorization server, with the approval of the resource owner, or end-user. PhoneGap Developers use inAppBrowser’s API to show the OAuth consent page.
CordovaSim supports inAppBrowser plugin and handles OAuth authorization. Here is a short video with OAuth demo and brand-new CordovaSim’s features (source code is also taken from the Michael Dellanoce’s article):
How to give it a go?
The sample should work with
JBoss Tools 4.2.0 Beta3 release and later versions.
Clone the demo project
File → Import → Import Cordova Project
Right-click on the project → Properties → Hybrid Mobile Engine → Download → 3.4.0 (select as default engine)
Create a Google Developers Console project
Copy and paste Client ID and Client secret to index.js (lines 80-81) of the hybrid project
Right-click on the project → Run As.. → Run with CordovaSim
A few things to notice here : first, the Hybrid Mobile Tools imports the project into Eclipse and configures the proper plugins without there being any Eclipse specfic setup in the project. This works because the project is following the conventions from Cordova CLI generated projects and the import wizard understands this.
Secondly, when using Java 8, you can connect the Chrome debugger to the CordovaSimulator (Right click → Debug on browser) allowing you to step through the code, introspect variables and so forth.
We are trying our best to make CordovaSim as good as possible. User feedback is what we are seeking for now. We are looking forward to hearing your comments / remarks!