From 75092238e536fa52fb8cbf184e9e3bf2b244b6fd Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Thu, 20 Jul 2017 14:10:37 +0300 Subject: [PATCH 1/3] Add phone number sign-in Fix #228. --- firebase-auth.html | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/firebase-auth.html b/firebase-auth.html index 3eb8d25..c6560dd 100644 --- a/firebase-auth.html +++ b/firebase-auth.html @@ -231,7 +231,31 @@ sendPasswordResetEmail: function(email) { return this._handleSignIn(this.auth.sendPasswordResetEmail(email)); }, - + + /** + * Authenticates a Firebase client using a phone number. + * + * @param {!String} phoneNumber Phone number of the user. + * @return {Promise} Promise that handles success and failure. + */ + signInWithPhoneNumber: function(phoneNumber) { + var appVerifier = new firebase.auth.RecaptchaVerifier(this.$$('#recaptcha-container')); + return this._handleSignIn(firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier) + .then(function(confirmationResult) { + window.confirmationResult = confirmationResult; + })); + }, + + /** + * Confirms authentication code for phone number sign-in. + * + * @param {!String} code One-time code contained in the SMS message. + * @return {Promise} Promise that handles success and failure. + */ + confirmCode: function(code) { + return this._handleSignIn(window.confirmationResult.confirm(code)); + }, + /** * Unauthenticates a Firebase client. * From e2d58b0e7baf7f701ecaf00bd1d292faa9a3b2a1 Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Wed, 26 Jul 2017 10:52:53 +0300 Subject: [PATCH 2/3] Change element selector to getElementById --- firebase-auth.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-auth.html b/firebase-auth.html index c6560dd..fd4aff3 100644 --- a/firebase-auth.html +++ b/firebase-auth.html @@ -239,7 +239,7 @@ * @return {Promise} Promise that handles success and failure. */ signInWithPhoneNumber: function(phoneNumber) { - var appVerifier = new firebase.auth.RecaptchaVerifier(this.$$('#recaptcha-container')); + var appVerifier = new firebase.auth.RecaptchaVerifier(document.getElementById('recaptcha-container')); return this._handleSignIn(firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier) .then(function(confirmationResult) { window.confirmationResult = confirmationResult; From 2ed4c4a05b434a7fba6869f56302c4cbcd9cd1be Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 8 Sep 2017 15:04:15 +0300 Subject: [PATCH 3/3] Review feedback --- firebase-auth.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/firebase-auth.html b/firebase-auth.html index fd4aff3..a27910c 100644 --- a/firebase-auth.html +++ b/firebase-auth.html @@ -235,12 +235,22 @@ /** * Authenticates a Firebase client using a phone number. * - * @param {!String} phoneNumber Phone number of the user. + * @param {!String} phoneNumber The user's phone number string in E.164 format (e.g. +16505550101). + * @param {!String|HTMLElement} container The HTML element (the ID of the container (string) + * or the DOM element itself) to render the reCAPTCHA widget. For a visible reCAPTCHA corresponding + * element must be empty. reCAPTCHA doesn't work inside Shadow DOM, so it must not be in the Shadow DOM. + * It must also be in the DOM at the time of initialization. + * @param {Object} [parameters] The optional object containing reCAPTCHA parameters as "key":"value" pairs. + * Check the reCAPTCHA docs for a comprehensive list. All parameters are accepted except for the "sitekey". + * Firebase Auth backend provisions a reCAPTCHA for each project and will configure this upon rendering. + * For an invisible reCAPTCHA, a "size" key must have the value "invisible". + * @param {Object} [app] The corresponding Firebase app. If none is provided, the default Firebase App instance + * is used. A Firebase App instance must be initialized with an API key, otherwise an error will be thrown. * @return {Promise} Promise that handles success and failure. */ - signInWithPhoneNumber: function(phoneNumber) { - var appVerifier = new firebase.auth.RecaptchaVerifier(document.getElementById('recaptcha-container')); - return this._handleSignIn(firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier) + signInWithPhoneNumber: function(phoneNumber, container, parameters, app) { + var applicationVerifier = new firebase.auth.RecaptchaVerifier(container, parameters, app); + return this._handleSignIn(this.auth.signInWithPhoneNumber(phoneNumber, applicationVerifier) .then(function(confirmationResult) { window.confirmationResult = confirmationResult; }));