Skip to content

Commit

Permalink
Google-sigIn
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-i-silva committed Aug 11, 2020
1 parent 6080292 commit 8946d91
Show file tree
Hide file tree
Showing 7 changed files with 383 additions and 4 deletions.
226 changes: 226 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": "^5.0.0",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"google-auth-library": "^6.0.6",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.27",
"mongoose-unique-validator": "^2.0.3",
Expand Down
44 changes: 44 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Google SignIn Demo</title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="113170598534-5p4308sa0eotbv4ja2vbftgb9ka93uhp.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.

let 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>
7 changes: 6 additions & 1 deletion server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ if(process.env.NODE_ENV === 'dev'){
}


process.env.URLDB = urlDB
process.env.URLDB = urlDB

// ======================
// Client ID de google
// ======================
process.env.CLIENT_ID = process.env.CLIENT_ID || '113170598534-5p4308sa0eotbv4ja2vbftgb9ka93uhp.apps.googleusercontent.com'
1 change: 0 additions & 1 deletion server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ app.use( require('./usuario'))
app.use( require('./login'))



module.exports = app;
Loading

0 comments on commit 8946d91

Please sign in to comment.