Skip to content

Commit

Permalink
Integrate Google Sign In
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Sztamfater committed Dec 15, 2020
1 parent c8b5efe commit 41c9821
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 14 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 @@ -21,6 +21,7 @@
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"google-auth-library": "^6.1.3",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.20",
"mongoose": "^5.11.6",
Expand Down
32 changes: 32 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html>
<head>
<title>Google Sign-In Demo</title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="865204013155-2eph0vh7lttm2lnq8kt2im8tb7hd3o2j.apps.googleusercontent.com">
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<script>
function onSignIn(googleUser) {
var id_token = googleUser.getAuthResponse().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>

<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>
</body>
</html>
10 changes: 8 additions & 2 deletions server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ process.env.TOKEN_EXPIRATION = 60 * 60 * 24 * 30;


// ===================
// SEED
// Seed
// ===================

process.env.SEED = process.env.SEED || 'this-is-the-dev-seed';
process.env.SEED = process.env.SEED || 'this-is-the-dev-seed';

// ===================
// Google Client ID
// ===================

process.env.GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID || '865204013155-2eph0vh7lttm2lnq8kt2im8tb7hd3o2j.apps.googleusercontent.com';
Loading

0 comments on commit 41c9821

Please sign in to comment.