diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..de338da
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+/.idea
+/bower_components
\ No newline at end of file
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..e801870
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,14 @@
+{
+ "name": "va-cordova-oauth",
+ "version": "0.0.1",
+ "description": "Useful web component for user authentication with Firebase.",
+ "license": "MIT",
+ "dependencies": {
+ "promise-polyfill": "polymerlabs/promise-polyfill#^1.0.0",
+ "polymer": "polymer/polymer#^1.6.0",
+ "va-cordova-oauth": "via-at/va-cordova-oauth"
+ },
+ "devDependencies": {
+ "web-component-tester": "^4.0.0"
+ }
+}
diff --git a/va-auth.html b/va-auth.html
index 78f8575..c41483b 100644
--- a/va-auth.html
+++ b/va-auth.html
@@ -5,6 +5,8 @@
+
+
@@ -36,35 +38,57 @@
_signInWithEmail: function (e) {
var promise = this.$.auth.signInWithEmailAndPassword(e.detail.email, e.detail.password);
-
- promise.then(function () {
- this.$.dialog.close();
- this.fire('done');
- }.bind(this), function () {
- this.$.dialog.failSignIn();
- this.fire('error');
- }.bind(this));
+ promise.then(this._done.bind(this), this._failSignIn.bind(this));
},
_signUpWithEmail: function (e) {
var promise = this.$.auth.createUserWithEmailAndPassword(e.detail.email, e.detail.password);
-
- promise.then(function () {
- this.$.dialog.close();
- this.fire('done');
- }.bind(this), function () {
- this.$.dialog.failSignUp();
- this.fire('error');
- }.bind(this));
+ promise.then(this._done.bind(this), this._failSignUp.bind(this));
},
_auth: function (e) {
- var promise = this.$.auth.signInWithPopup(e.detail.provider);
-
- promise.then(function () {
- this.$.dialog.close();
- this.fire('done');
- }.bind(this));
+ var provider = e.detail.provider;
+
+ if (cordova) {
+ var url = this.resolveUrl('../va-cordova-oauth/va-cordova-oauth.html', null, null, true);
+
+ this.importHref(url, function () {
+ this.$.cordovaAuth.signIn(provider).then(function () {
+ var credential;
+
+ switch (provider) {
+ case 'google':
+ credential = firebase.auth.GoogleAuthProvider.credential(arguments[0], null);
+ break;
+ case 'facebook':
+ credential = firebase.auth.FacebookAuthProvider.credential(arguments[0]);
+ break;
+ case 'twitter':
+ credential = firebase.auth.TwitterAuthProvider.credential(arguments[0], arguments[1]);
+ break;
+ }
+
+ this.$.auth.signInWithCredential(credential).then(this._done.bind(this));
+ }.bind(this));
+ }.bind(this));
+ } else {
+ this.$.auth.signInWithPopup(provider).then(this._done.bind(this));
+ }
+ },
+
+ _done: function () {
+ this.$.dialog.close();
+ this.fire('done');
+ },
+
+ _failSignIn: function () {
+ this.$.dialog.failSignIn();
+ this.fire('error');
+ },
+
+ _failSignUp: function () {
+ this.$.dialog.failSignUp();
+ this.fire('error');
}
});