Skip to content

Instantly share code, notes, and snippets.

@gentritabazi
Last active January 25, 2021 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gentritabazi/2ecc1fbb6b2dfabe634e532afbf82f48 to your computer and use it in GitHub Desktop.
Save gentritabazi/2ecc1fbb6b2dfabe634e532afbf82f48 to your computer and use it in GitHub Desktop.
GOOGLE LOGIN HTML
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="{client_id}">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The token you need to pass to your backend:
let accessToken = googleUser.getAuthResponse().access_token;
// Send request to backend:
axios.post('{backend_url}', {accessToken: accessToken}).then(function (response) {
console.log(response)
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment