Skip to content

Instantly share code, notes, and snippets.

@elliotlarson
Created November 17, 2016 23:51
Show Gist options
  • Select an option

  • Save elliotlarson/e73bdcd025f688e4e7a84332b9460300 to your computer and use it in GitHub Desktop.

Select an option

Save elliotlarson/e73bdcd025f688e4e7a84332b9460300 to your computer and use it in GitHub Desktop.
Utility web page for creating a Firebase application user via Google provider authentication
<!--
You need to run this in a webserver environment over HTTP for it to work.
Start a basic server with:
```bash
$ http-server
```
Then navigate to: http://localhost:8080/create-app-user.html
-->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Add App User</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="https://firebase.google.com/_static/b177369db9/images/firebase/favicon.png">
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<script src="https://www.gstatic.com/firebasejs/3.5.2/firebase.js"></script>
</head>
<body>
<div class="container">
<br>
<br>
<div class="jumbotron">
<div class="row">
<div class='col-md-12'>
<h2>Adding an application user</h2>
<br>
<p>
This is about setting up a new application user by authenticating with the Google provider.
</p>
<p>
This has to be carried out in a web page (over HTTP) for the process to work.
</p>
<br>
<br>
<h3>Do this...</h3>
<br>
<p>
<b>1.</b> Open the developer console
</p>
<p>
<b>2.</b> Type in: authenticate()
</p>
</div>
</div>
</div>
</div>
<script>
var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
storageBucket: "<BUCKET>.appspot.com",
messagingSenderId: "<SENDER_ID>"
}
firebase.initializeApp(config);
function authenticate() {
// Using a popup.
let provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token.
let token = result.credential.accessToken;
// The signed-in user info.
let user = result.user;
// console.log(user);
console.log("Okay, you've been authenticated. There should be a new user account in your FB console.");
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment