Skip to content

Commit

Permalink
Switched to version eap.3 of Firebase JS.
Browse files Browse the repository at this point in the history
Some additional polish.

Change-Id: I7c07263ce0675b8cc6d9e9e84639ec263e8cc2bf
  • Loading branch information
Nicolas Garnier committed Apr 6, 2016
1 parent a2c00b7 commit 4cf0bba
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 168 deletions.
31 changes: 9 additions & 22 deletions auth/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
Firebase Auth Quickstart
=============================

The Firbase auth quickstart demonstrate several methods for signing in.
The Firebase auth quickstart demonstrates several methods for signing in.

The Firebase email/password quickstart demonstrates using a Firebase stored email & password - you can both create and sign in a user.

The Firebase Google Sign in quickstart demonstrates using a Google account to authenticate to Firebase.
The Firebase Google Sign in quickstart demonstrates using a Google account to authenticate to Firebase.

The Firebase Facebook Login quickstart demonstrates using a Facebook account to authenticate to Firebase.

The Firebase custom auth web quickstart demonstrates how to authenticate with the Firebase user management
system with a user who has been authenticated from your own pre-existing authentication system.This is done by generating a token in a specific format, which is signed using the private key from a service account downloaded from the Google Developer Console. This token can then be passed to your client application which uses it to authenticate to Firebase.
The Firebase Anonymous auth quickstart demonstrates authenticate to Firebase anonymously.

The Firebase custom auth web quickstart demonstrates how to authenticate to Firebase with a user who has been authenticated from your own pre-existing authentication system. This is done by generating a token in a specific format, which is signed using the private key from a service account downloaded from the Google Developer Console. This token can then be passed to your client application which uses it to authenticate to Firebase.

Introduction
------------
Expand All @@ -21,35 +22,21 @@ Getting Started
---------------

- Set up your project on the [Firebase Console](http://g.co/firebase).
- Enable the authentication method you want to use in the User Management tab - you don't need to enable custom auth.
- Enable the authentication method you want to use in the Auth tab - you don't need to enable custom auth.
- In the [Google Developer Console](https://console.developers.google.com), access the project you created in the Firebase Console.
- In the search box search for an select "Credentials" and create a Browser API key restricted to the domain you are using.
- For Custom Auth, also create a new Service Account, and download the JSON representation.
- For Google Sign In you will need to create a client ID with a Javascript Origin field set to your domain.
- Edit the .html for the authentication method you want to try and fill in the API key and Database URL values in index.html. You can see the database URL from the Database section on the Firebase Console.
- Open the sample .html in a web browser. Note that for Google Sign In you must use a webserver of some kind, file:// hosted pages wont work.
- Open the sample `.html` in a web browser. Note that for Google Sign In you must use a webserver of some kind, file:// hosted pages wont work.

Support
-------

https://developers.google.com/firebase/support/


License
-------

Copyright 2016 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
© Google, 2016. Licensed under an [Apache-2](../LICENSE) license.
17 changes: 7 additions & 10 deletions auth/quickstart/anon.html → auth/anon.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<title>Anonymous Authentication Example</title>

<!-- Material Design Theming -->
<link rel="stylesheet" href="https://code.getmdl.io/1.1.2/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script defer src="https://code.getmdl.io/1.1.2/material.min.js"></script>
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script>

<!-- Firebase Auth -->
<script type="text/javascript">
Expand All @@ -34,7 +34,7 @@
var databaseUrl = 'YOUR_DATABASE_URL_HERE';
</script>

<script src="https://www.gstatic.com/firebasejs/3.0.0-eap.2/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/staging/3.0.0-eap.3/firebase.js"></script>
<script type="text/javascript">
var app = null;
var auth = null;
Expand Down Expand Up @@ -103,9 +103,9 @@
// Api key in config.
var config = {
apiKey: apiKey,
databaseUrl: databaseUrl
databaseURL: databaseUrl
};
app = firebase.App.initialize(config);
app = firebase.initializeApp(config);
auth = app.auth();
// [END appconfig]

Expand All @@ -114,8 +114,7 @@
// [START authstatelistener]
app.addAuthStateListener(function(event) {
// Current user.
var user = event.user;
var getToken = event.getToken;
var user = event.currentUser;
console.log('User Object:', user);

if (!user) {
Expand All @@ -131,8 +130,6 @@
console.log('Database snapshot:', snapshot.val());
});
// [END_EXCLUDE]
}, function(error) {
console.error('Auth Listener Error', error);
});
// [END authstatelistener]

Expand Down Expand Up @@ -160,7 +157,7 @@ <h1>Firebase Anonymous Authentication</h1>
<div class="mdl-grid">
<div class="mdl-layout-spacer"></div>
<div class="mdl-cell mdl-cell-8-col-tablet mdl-cell--8-col-desktop">
<button id="signin" name="signin">Sign In</button>
<button class="mdl-button mdl-js-button mdl-button--raised" id="signin" name="signin">Sign In</button>
</div>
<div class="mdl-layout-spacer"></div>
</div>
Expand Down
17 changes: 7 additions & 10 deletions auth/quickstart/customauth.html → auth/customauth.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<title>Custom Token Consumer Example</title>

<!-- Material Design Theming -->
<link rel="stylesheet" href="https://code.getmdl.io/1.1.2/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script defer src="https://code.getmdl.io/1.1.2/material.min.js"></script>
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script>

<!-- Firebase Auth -->
<script type="text/javascript">
Expand All @@ -34,7 +34,7 @@
var databaseUrl = 'YOUR_DATABASE_URL_HERE';
</script>

<script src="https://www.gstatic.com/firebasejs/3.0.0-eap.2/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/staging/3.0.0-eap.3/firebase.js"></script>
<script type="text/javascript">
var app = null;
var auth = null;
Expand Down Expand Up @@ -106,9 +106,9 @@
// Api key in config.
var config = {
apiKey: apiKey,
databaseUrl: databaseUrl
databaseURL: databaseUrl
};
app = firebase.App.initialize(config);
app = firebase.initializeApp(config);
auth = app.auth();
// [END appconfig]

Expand All @@ -117,8 +117,7 @@
// [START authstatelistener]
app.addAuthStateListener(function(event) {
// Current user.
var user = event.user;
var getToken = event.getToken;
var user = event.currentUser;
console.log('User Object:', user);

if (!user) {
Expand All @@ -134,8 +133,6 @@
console.log('Database snapshot:', snapshot.val());
});
// [END_EXCLUDE]
}, function(error) {
console.error('Auth Listener Error', error);
});
// [END authstatelistener]

Expand Down Expand Up @@ -165,7 +162,7 @@ <h1>Firebase Custom Authentication</h1>
<div class="mdl-cell mdl-cell-8-col-tablet mdl-cell--8-col-desktop">
<textarea id="tokentext" style="width: 100%; height: 200px;" name="tokentext" placeholder="Enter Your Custom Token"></textarea>
<br />
<button id="signin" name="signin">Sign In</button>
<button class="mdl-button mdl-js-button mdl-button--raised" id="signin" name="signin">Sign In / Sign Out</button>
</div>
<div class="mdl-layout-spacer"></div>
</div>
Expand Down
26 changes: 13 additions & 13 deletions auth/quickstart/email.html → auth/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<title>Email/Password Authentication Example</title>

<!-- Material Design Theming -->
<link rel="stylesheet" href="https://code.getmdl.io/1.1.2/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script defer src="https://code.getmdl.io/1.1.2/material.min.js"></script>
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script>

<!-- Firebase Auth -->
<script type="text/javascript">
Expand All @@ -34,7 +34,7 @@
var databaseUrl = 'YOUR_DATABASE_URL_HERE';
</script>

<script src="https://www.gstatic.com/firebasejs/3.0.0-eap.2/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/staging/3.0.0-eap.3/firebase.js"></script>
<script type="text/javascript">
var app = null;
var auth = null;
Expand Down Expand Up @@ -134,9 +134,9 @@
// Api key in config.
var config = {
apiKey: apiKey,
databaseUrl: databaseUrl
databaseURL: databaseUrl
};
app = firebase.App.initialize(config);
app = firebase.initializeApp(config);
auth = app.auth();
// [END appconfig]

Expand All @@ -145,8 +145,7 @@
// [START authstatelistener]
app.addAuthStateListener(function(event) {
// Current user.
var user = event.user;
var getToken = event.getToken;
var user = event.currentUser;
console.log('User Object:', user);

if (!user) {
Expand All @@ -164,8 +163,6 @@
console.log('Database snapshot:', snapshot.val());
});
// [END_EXCLUDE]
}, function(error) {
console.error('Auth Listener Error', error);
});
// [END authstatelistener]

Expand Down Expand Up @@ -194,10 +191,13 @@ <h1>Firebase Email &amp; Password Authentication</h1>
<div class="mdl-grid">
<div class="mdl-layout-spacer"></div>
<div class="mdl-cell mdl-cell-8-col-tablet mdl-cell--8-col-desktop">
<input type="text" id="email" name="email" placeholder="Email" />
<input type="password" id="password" name="password" placeholder="Password" />
<br />
<button id="signin" name="signin">Sign In</button> <button id="signup" name="signup">Sign Up</button>
<input class="mdl-textfield__input" style="display:inline;width:auto;" type="text" id="email" name="email" placeholder="Email" />
&nbsp;&nbsp;&nbsp;
<input class="mdl-textfield__input" style="display:inline;width:auto;" type="password" id="password" name="password" placeholder="Password" />
<br /><br />
<button class="mdl-button mdl-js-button mdl-button--raised" id="signin" name="signin">Sign In</button>
&nbsp;&nbsp;&nbsp;
<button class="mdl-button mdl-js-button mdl-button--raised" id="signup" name="signup">Sign Up</button>
</div>
<div class="mdl-layout-spacer"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<title>Custom Token Generator Example</title>

<!-- Material Design Theming -->
<link rel="stylesheet" href="https://code.getmdl.io/1.1.2/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script defer src="https://code.getmdl.io/1.1.2/material.min.js"></script>
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script>

<script language="JavaScript" type="text/javascript"
src="http://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js">
Expand Down
24 changes: 9 additions & 15 deletions auth/quickstart/facebook.html → auth/facebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<title>Facebook Sign In Example</title>

<!-- Material Design Theming -->
<link rel="stylesheet" href="https://code.getmdl.io/1.1.2/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.orange-indigo.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script defer src="https://code.getmdl.io/1.1.2/material.min.js"></script>
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script>

<!-- Firebase Auth -->
<script type="text/javascript">
Expand All @@ -35,16 +35,16 @@
var facebookAppId = 'YOUR_FACEBOOK_APP_ID';
</script>

<script src="https://www.gstatic.com/firebasejs/3.0.0-eap.2/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/staging/3.0.0-eap.3/firebase.js"></script>
<script type="text/javascript">
console.log('Initializing App');
// [START appconfig]
// Api key in config.
var config = {
apiKey: apiKey,
databaseUrl: databaseUrl
databaseURL: databaseUrl
};
var app = firebase.App.initialize(config);
var app = firebase.initializeApp(config);
var auth = app.auth();
// [END appconfig]

Expand All @@ -54,7 +54,7 @@
console.log('Facebook Auth Response', response);
// [START facebookcredential]
// Sign in with credential from the Facebook user.
var credential = firebase.FacebookAuthProvider.credential({
var credential = firebase.auth.FacebookAuthProvider.credential({
'accessToken' : response.authResponse.accessToken
});
// [END facebookcredential]
Expand Down Expand Up @@ -117,8 +117,7 @@
// [START authstatelistener]
app.addAuthStateListener(function(event) {
// Current user.
var user = event.user;
var getToken = event.getToken;
var user = event.currentUser;
console.log('User Object:', user);

if (!user) {
Expand All @@ -134,8 +133,6 @@
console.log('Database snapshot:', snapshot.val());
});
// [END_EXCLUDE]
}, function(error) {
console.log('Auth Listener Error', error);
});
// [END authstatelistener]

Expand All @@ -156,9 +153,6 @@
// [START facebookconfig]
window.fbAsyncInit = function() {
FB.init({
/**************************************************
* TODO(DEVELOPER): Change these config variable. *
**************************************************/
appId : facebookAppId,
xfbml : true,
version : 'v2.5'
Expand All @@ -169,7 +163,7 @@
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = ''//connect.facebook.net/en_US/sdk.js';
js.src = '//connect.facebook.net/en_US/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// [END facebookconfig]
Expand All @@ -190,7 +184,7 @@ <h1>Firebase Facebook Authentication</h1>
<div class="mdl-layout-spacer"></div>
<div class="mdl-cell mdl-cell-8-col-tablet mdl-cell--8-col-desktop" style=>
<fb:login-button data-auto-logout-link="true" scope="public_profile,email" onlogin="checkLoginState();"></fb:login-button>
<button id="signout" name="signout">Sign Out</button>
<button class="mdl-button mdl-js-button mdl-button--raised" id="signout" name="signout">Sign Out</button>
</div>
<div class="mdl-layout-spacer"></div>
</div>
Expand Down
15 changes: 8 additions & 7 deletions auth/firebase.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"firebase": "YOUR_PROJECT_ID_HERE",
"public": "quickstart",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
"hosting": {
"public": "./",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
Loading

0 comments on commit 4cf0bba

Please sign in to comment.