Skip to content

Commit

Permalink
Integrado Google Sign-In
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Serrey committed Dec 16, 2019
1 parent eeb7ec2 commit d9ef1f1
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 0 deletions.
176 changes: 176 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"bcrypt": "^3.0.7",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"google-auth-library": "^5.7.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.7.14",
"mongoose-unique-validator": "^2.0.3",
Expand Down
50 changes: 50 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Google SignIn Demo</title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="290449245938-ejv1n291ijgubosedub0mikh4oiro0h3.apps.googleusercontent.com">
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>

<a href="#" onclick="signOut();">Sign out</a>
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
</script>



<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
// console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
// console.log('Name: ' + profile.getName());
// console.log('Image URL: ' + profile.getImageUrl());
// console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.

var id_token = googleUser.getAuthResponse().id_token;
console.log(id_token);

var xhr = new XMLHttpRequest();
xhr.open('POST', '/google');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
console.log('Signed in as: ' + xhr.responseText);
};
xhr.send('idtoken=' + id_token);


}
</script>

</body>
</html>
6 changes: 6 additions & 0 deletions server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ else
urlDB = 'mongodb+srv://lucas:[email protected]/cursonode';
}
process.env.URLDB = urlDB;


// =========================
// GOOGLE CLIENT ID
// =========================
process.env.CLIENT_ID = process.env.CLIENT_ID || '290449245938-ejv1n291ijgubosedub0mikh4oiro0h3.apps.googleusercontent.com';
Loading

0 comments on commit d9ef1f1

Please sign in to comment.