How eddyverbruggen/cordova-plugin-googleplus works
1. This repository is a Cordova/PhoneGap plugin, not an app. Its job is to expose Google Sign-In to hybrid apps through a single JavaScript API while delegating platform-specific auth work to native code on iOS and Android.
2. The top-level integration point is plugin.xml. It defines the plugin metadata, which source files are installed per platform, and the variables the app must provide at install time, especially REVERSED_CLIENT_ID and WEB_APPLICATION_CLIENT_ID. That file is the central boundary between Cordova and the native implementations.
3. The JavaScript surface area lives in www/GooglePlus.js. This is the public plugin API consumed by Cordova apps via window.plugins.googleplus. It is the only code the host application calls directly; everything else is behind the Cordova bridge.
4. Native sign-in logic is split by platform under src/ios/GooglePlus.m/.h and src/android/GooglePlus.java. These are the real authentication adapters that talk to the Google SDKs, handle login/silent login/logout/disconnect, and translate SDK results into plain JS objects returned to the callback layer.
5. The data flow is consistent across platforms: app code calls the JS wrapper, Cordova forwards the request to the native side, the native SDK performs authentication, and the result is marshaled back as a JSON-like object containing profile fields plus optional idToken, serverAuthCode, and accessToken.
6. Browser support is implemented separately in src/browser/GooglePlusProxy.js. This is a Cordova proxy layer for the browser platform, meant to keep the plugin callable in non-native environments. It is part of the same API surface but does not use the iOS/Android SDKs.
7. There is also a simulation layer in src/simulation/, with sim-host.js and sim-host-handlers.js. This appears to provide a host-driven fake environment for testing or demoing plugin behavior without a real device auth flow, forming a separate non-production execution path.
8. Build-time behavior is customized with hooks. hooks/browser/after_prepare.js adjusts browser platform output after Cordova prepare, and hooks/ios/prerequisites.js plus hooks/ios/package.json support iOS dependency/setup handling. These hooks are important because they bridge the plugin into platform build systems rather than runtime auth.
9. The iOS side depends on CocoaPods, as called out in the README. That means the plugin is not fully self-contained on iOS: the Cordova plugin installs native code, but the final app build also needs Pods resolution for Google Sign-In libraries.
10. Android integration depends on Google Play Services and OAuth configuration rather than bundled credentials. The plugin code expects the app developer to provide the correct SHA-1 / client IDs, while the plugin itself focuses only on the sign-in flow and token retrieval.
11. The demo/ directory contains reference host apps for different Cordova stacks: plain Cordova, Cordova with Firebase, and Ionic 2. These demos are not part of the plugin runtime, but they illustrate the expected call pattern and serve as integration examples.
12. Overall architecture: a thin cross-platform JS API at the top, Cordova bridge and platform proxies in the middle, native Google Sign-In implementations at the bottom, and a small amount of build-time glue around the edges to wire in platform dependencies and configuration.
Main entry points: plugin.xml plugin.xml · GooglePlus.m GooglePlus.m · GooglePlus.js GooglePlus.js · GooglePlus.java GooglePlus.java
Components 17
Plugin core
Cordova plugin boundary and public API surface.
- plugin.xml · Plugin metadata, platform file mapping, and install variables.
plugin.xml - GooglePlus.js · Public Cordova-facing API used by host apps.
www/GooglePlus.js - Cordova bridge · Dispatches JS calls into platform-specific implementations.
- README.md · Plugin usage, setup requirements, and platform notes.
README.md
Native auth
Platform-specific Google Sign-In implementations.
- GooglePlus.h · Native plugin interface and method declarations.
src/ios/GooglePlus.h - GooglePlus.m · iOS Google Sign-In adapter and result marshaling.
src/ios/GooglePlus.m - GooglePlus.java · Android Google Sign-In adapter and callback handling.
src/android/GooglePlus.java
Support paths
Browser, simulation, and build-time integration paths.
- GooglePlusProxy.js · Browser-platform Cordova proxy for the same API surface.
src/browser/GooglePlusProxy.js - sim-host.js · Host-driven simulated plugin environment.
src/simulation/sim-host.js - sim-host-handlers.js · Fake auth responses and simulation behavior.
src/simulation/sim-host-handlers.js - after_prepare.js · Browser platform post-prepare customization.
hooks/browser/after_prepare.js - prerequisites.js · iOS setup and dependency preparation logic.
hooks/ios/prerequisites.js - package.json · iOS hook package metadata and dependency wiring.
hooks/ios/package.json
Demos
Reference host apps showing plugin usage.
- Cordova demo · Plain Cordova integration example.
demo/cordova/index.html - Firebase demo · Cordova example combined with Firebase.
demo/cordova-firebase/index.html - Ionic 2 demo · Ionic-based integration example.
demo/ionic2/app/app.module.ts - demo README · Overview of the available demo host apps.
demo/README.md
Connections 28
- plugin.xml → GooglePlus.js: installs · Declares the JavaScript entry point.
- plugin.xml → GooglePlus.m: installs · Registers the iOS native implementation.
- plugin.xml → GooglePlus.java: installs · Registers the Android native implementation.
- plugin.xml → GooglePlusProxy.js: maps · Provides the browser platform proxy.
- plugin.xml → after_prepare.js: hooks · Runs browser post-prepare customization.
- plugin.xml → prerequisites.js: hooks · Runs iOS setup/dependency preparation.
- GooglePlus.js → Cordova bridge: calls · Host apps invoke the JS API, which forwards through Cordova.
- Cordova bridge → GooglePlus.h: dispatches · Routes calls into the iOS plugin interface.
- Cordova bridge → GooglePlus.m: dispatches · Routes calls into the iOS authentication adapter.
- Cordova bridge → GooglePlus.java: dispatches · Routes calls into the Android authentication adapter.
- Cordova bridge → GooglePlusProxy.js: dispatches · Routes calls to the browser implementation when applicable.
- Cordova bridge → sim-host.js: supports · Can be exercised through the simulation path.
- GooglePlus.m → GooglePlus.h: implements · Objective-C implementation matches the native interface.
- GooglePlus.m → Cordova bridge: returns · Marshals auth results back through Cordova callbacks.
- GooglePlus.java → Cordova bridge: returns · Marshals auth results back through Cordova callbacks.
- GooglePlusProxy.js → Cordova bridge: adapts · Implements the same API surface for browsers.
- sim-host.js → sim-host-handlers.js: drives · Simulation host delegates fake auth behavior to handlers.
- sim-host.js → Cordova bridge: mimics · Exercises the same logical API flow without real devices.
- prerequisites.js → package.json: uses · Hook setup is packaged with iOS hook metadata.
- README.md → plugin.xml: documents · Explains install variables and plugin boundary.
- README.md → GooglePlus.m: documents · Describes iOS setup and CocoaPods dependency.
- README.md → GooglePlus.java: documents · Describes Android Google Play Services configuration.
- demo README → Cordova demo: references · Lists the Cordova demo app.
- demo README → Firebase demo: references · Lists the Firebase-integrated demo app.
- demo README → Ionic 2 demo: references · Lists the Ionic 2 demo app.
- Cordova demo → GooglePlus.js: consumes · Shows the plugin API from a host app.
- Firebase demo → GooglePlus.js: consumes · Shows the plugin API from a host app.
- Ionic 2 demo → GooglePlus.js: consumes · Shows the plugin API from a host app.