Created
June 20, 2024 10:15
-
-
Save devvspaces/b6fa97fe72cd8e10634d6d95159ea193 to your computer and use it in GitHub Desktop.
Get Token from Google sign in
This file contains hidden or 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> | |
<title>Sign In with Firebase</title> | |
<script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-app-compat.js"></script> | |
<script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-auth-compat.js"></script> | |
<script> | |
// Your web app's Firebase configuration | |
const firebaseConfig = { | |
apiKey: "[INCLUDE]", | |
authDomain: "[INCLUDE]", | |
projectId: "[INCLUDE]", | |
storageBucket: "[INCLUDE]", | |
messagingSenderId: "[INCLUDE]", | |
appId: "[INCLUDE]" | |
}; | |
// Initialize Firebase | |
firebase.initializeApp(firebaseConfig); | |
const auth = firebase.auth(); | |
function signInWithGoogle() { | |
const provider = new firebase.auth.GoogleAuthProvider(); | |
auth.signInWithPopup(provider).then((result) => { | |
// This gives you a Google Access Token. You can use it to access the Google API. | |
const token = result.credential.accessToken; | |
// The signed-in user info. | |
const user = result.user; | |
// Get the Firebase ID token | |
user.getIdToken().then(idToken => { | |
console.log("Firebase ID Token:", idToken); | |
}); | |
}).catch((error) => { | |
console.log(error); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="signInWithGoogle()">Sign In with Google</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment