Last active
September 16, 2016 12:37
-
-
Save janis-kra/55d69c7deed5d9d340da4e0f66a494f2 to your computer and use it in GitHub Desktop.
Extending Oracle JET with Google Sign-In — how not to do it
This file contains 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
<html lang="en-us"> | |
<head> | |
<title>Oracle JET & Google-Signin</title> | |
<meta name="google-signin-scope" content="profile email"> | |
<meta name="google-signin-client_id" content="YOUR_TOKEN_HERE.apps.googleusercontent.com"> | |
<script src="https://apis.google.com/js/platform.js" async defer></script> | |
</head> | |
<body> | |
<h3>how not to do it</h3> | |
<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('Full Name: ' + profile.getName()); | |
// The ID token you need to pass to your backend: | |
var id_token = googleUser.getAuthResponse().id_token; | |
console.log("ID Token: " + id_token); | |
}; | |
</script> | |
<script type="text/javascript" data-main="js/main" src="js/libs/require/require.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks fairly simple and actually works like a charm. But what if you actually need the users data for more than just logging it? Chances are you want to store it in one of your ViewModels and/or use it for making calls to your webservice. Then this approach gets you nowhere, as the
onSignIn
function lives outside the scope of Requirejs and your ViewModels (plus it clutters the global namespace which is almost never a good idea).