This section provides an overview of what firebase-authentication is, and why a developer might want to use it.
It should also mention any large subjects within firebase-authentication, and link out to the related topics. Since the Documentation for firebase-authentication is new, you may need to create initial versions of those related topics.
You can use Firebase Authentication to let your users authenticate with Firebase using their email addresses and passwords, and to manage your app's password-based accounts.
In this example, we use these steps to set it up for our Android project which is based on JavaScript.
But before doing so, this is what needs to get done before:
There are 2 auth methods required to create a password based user with displayName, namely .createUserWithEmailAndPassword and .updateProfile. I have nested the latter and created a single function which fires both of these methods for ease of use.
function registerPasswordUser(email,displayName,password,photoURL){
var user = null;
//NULLIFY EMPTY ARGUMENTS
for (var i = 0; i < arguments.length; i++) {
arguments[i] = arguments[i] ? arguments[i] : null;
}
auth.createUserWithEmailAndPassword(email, password)
.then(function () {
user = auth.currentUser;
user.sendEmailVerification();
})
.then(function () {
user.updateProfile({
displayName: displayName,
photoURL: photoURL
});
})
.catch(function(error) {
console.log(error.message,7000);
});
console.log('Validation link was sent to ' + email + '.');
}
A fully functional demo of Firebase v3 Web authentication viewable here. Sign in with Facebook, Github, Google, Twitter, password based, and anonymous accounts. The code, available on Github, is easy to read and follow and is well documented. The focus is on the fully functional authentication system.
Password based users are sent a validation link. They can also change their email address and password - both of these events send a verification email as an additional security measure.
Lastly, the difference between authentication, client side authorization, and server side authorization secured via Firebase Realtime Database Security Rules is demonstrated.
Prerequisites
Configure Your IDE
npm install -g firebase-tools
firebase login --no-localhost
firebase init
git clone https://github.com/rhroyston/firebase-auth.git
firebase deploy
href
, src
, and background: url
in all JS, CSS, and all HTML files depending on your Web hosting folder structure .
href
and src
and update as necessary.privateLink.href = "../firebase-auth/private"
the ..
seems to be required.Configure Firebase
https://my-app-1234/ack
.Login to Web app
demo.update('mynode','myKey','myValue')
method to add secure markup to your Realtime Database.
href
path to match your folder structure.demo.update("markup","secureData","<div class=\"mdl-card__title\"> <h1 class=\"mdl-card__title-text mdl-color-text--white\">Secured Data</h1> </div><div class=\"mdl-card__supporting-text mdl-typography--headline\"> <p>This is a secure card. The HTML markup that renders this card is secured in the Realtime Database. Access is determined server side so no matter what you do with JavaScript on your browser you will not be able to view this card unless you are authorized to.</p><p>Secured data can be markup, JSON, strings, numbers, etc. Your imagination is the limit!</p></div><div class=\"mdl-card__actions mdl-card--border intro-card-actions\"> <a class=\"mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect\" href=\"../firebase-auth/\">Home</a></div>");
Login using each oAuth provider
Register as a Password based user
Logout