Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
<!DOCTYPE html>
Copyright (c) 2016 Google Inc.
Licensed 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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
<meta charset=utf-8 />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitHub Sign In Example</title>
<!-- Material Design Theming -->
<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
<script defer src=""></script>
<link rel="stylesheet" href="main.css">
<!-- Import and configure the Firebase SDK -->
<!-- These scripts are made available when the app is served or deployed on Firebase Hosting -->
<!-- If you do not serve/host your project using Firebase Hosting see -->
<script src="/__/firebase/9.0.2/firebase-app-compat.js"></script>
<script src="/__/firebase/9.0.2/firebase-auth-compat.js"></script>
<script src="/__/firebase/init.js"></script>
<script type="text/javascript">
* Function called when clicking the Login/Logout button.
function toggleSignIn() {
if (!firebase.auth().currentUser) {
var provider = new firebase.auth.GithubAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a GitHub Access Token. You can use it to access the GitHub API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
document.getElementById('quickstart-oauthtoken').textContent = token;
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email =;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
if (errorCode === 'auth/account-exists-with-different-credential') {
alert('You have already signed up with a different auth provider for that email.');
// If you are using multiple auth providers on your app you should handle linking
// the user's accounts here.
} else {
} else {
document.getElementById('quickstart-sign-in').disabled = true;
* initApp handles setting up UI event listeners and registering Firebase auth listeners:
* - firebase.auth().onAuthStateChanged: This listener is called when the user is signed in or
* out, and that is where we update the UI.
function initApp() {
// Listening for auth state changes.
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var displayName = user.displayName;
var email =;
var emailVerified = user.emailVerified;
var photoURL = user.photoURL;
var isAnonymous = user.isAnonymous;
var uid = user.uid;
var providerData = user.providerData;
document.getElementById('quickstart-sign-in-status').textContent = 'Signed in';
document.getElementById('quickstart-sign-in').textContent = 'Sign out';
document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');
} else {
// User is signed out.
document.getElementById('quickstart-sign-in-status').textContent = 'Signed out';
document.getElementById('quickstart-sign-in').textContent = 'Sign in with GitHub';
document.getElementById('quickstart-account-details').textContent = 'null';
document.getElementById('quickstart-oauthtoken').textContent = 'null';
document.getElementById('quickstart-sign-in').disabled = false;
document.getElementById('quickstart-sign-in').addEventListener('click', toggleSignIn, false);
window.onload = function() {
<div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-header">
<!-- Header section containing title -->
<header class="mdl-layout__header mdl-color-text--white mdl-color--light-blue-700">
<div class="mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-grid">
<div class="mdl-layout__header-row mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-cell--8-col-desktop">
<a href="/"><h3>Firebase Authentication</h3></a>
<main class="mdl-layout__content mdl-color--grey-100">
<div class="mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-grid">
<!-- Container for the demo -->
<div class="mdl-card mdl-shadow--2dp mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-cell--12-col-desktop">
<div class="mdl-card__title mdl-color--light-blue-600 mdl-color-text--white">
<h2 class="mdl-card__title-text">GitHub Authentication with Popup</h2>
<div class="mdl-card__supporting-text mdl-color-text--grey-600">
<p>Sign in with your GitHub account below.</p>
<!-- Button that handles sign-in/sign-out -->
<button disabled class="mdl-button mdl-js-button mdl-button--raised" id="quickstart-sign-in">Sign in with GitHub</button>
<!-- Container where we'll display the user details -->
<div class="quickstart-user-details-container">
Firebase sign-in status: <span id="quickstart-sign-in-status">Unknown</span>
<div>Firebase auth <code>currentUser</code> object value:</div>
<pre><code id="quickstart-account-details">null</code></pre>
<div>GitHub OAuth Access Token:</div>
<pre><code id="quickstart-oauthtoken">null</code></pre>