Created
June 27, 2018 03:02
-
-
Save IllDepence/7c201287af52bd1f78bed65ec7737e84 to your computer and use it in GitHub Desktop.
web ui for getting firebase id tokens for testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<script src="https://cdn.firebase.com/libs/firebaseui/2.5.1/firebaseui.js"></script> | |
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/2.5.1/firebaseui.css" /> | |
</head> | |
<body> | |
<div id="firebaseui-auth-container"></div> | |
<div id="loader">Loading...</div> | |
<br> | |
<br> | |
<br> | |
<a href="#show" onClick="showIDToken()">show ID token</a> | |
<p id="idToken">...</p> | |
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script> | |
<script> | |
// Initialize Firebase | |
var config = { | |
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", | |
authDomain: "yyyyyyyyyy.firebaseapp.com", | |
databaseURL: "https://yyyyyyyyyy.firebaseio.com", | |
projectId: "yyyyyyyyyy", | |
storageBucket: "yyyyyyyyyy.appspot.com", | |
messagingSenderId: "000000000000" | |
}; | |
firebase.initializeApp(config); | |
// Initialize UI | |
var ui = new firebaseui.auth.AuthUI(firebase.auth()); | |
var uiConfig = { | |
callbacks: { | |
signInSuccessWithAuthResult: function(authResult, redirectUrl) { | |
// User successfully signed in. | |
// Return type determines whether we continue the redirect automatically | |
// or whether we leave that to developer to handle. | |
return true; | |
}, | |
uiShown: function() { | |
// The widget is rendered. | |
// Hide the loader. | |
document.getElementById('loader').style.display = 'none'; | |
} | |
}, | |
// Will use popup for IDP Providers sign-in flow instead of the default, redirect. | |
signInFlow: 'popup', | |
signInSuccessUrl: '#done', | |
signInOptions: [ | |
// Leave the lines as is for the providers you want to offer your users. | |
firebase.auth.GoogleAuthProvider.PROVIDER_ID, | |
firebase.auth.TwitterAuthProvider.PROVIDER_ID, | |
firebase.auth.GithubAuthProvider.PROVIDER_ID, | |
firebase.auth.EmailAuthProvider.PROVIDER_ID, | |
], | |
// Terms of service url. | |
tosUrl: '#tos' | |
}; | |
// Start | |
ui.start('#firebaseui-auth-container', uiConfig); | |
function showIDToken() { | |
firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) { | |
elem = document.querySelector('#idToken'); | |
elem.innerHTML = idToken; | |
}).catch(function(error) { | |
// Handle error | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment