login.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html lang="">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0">
  7. <meta name="google-signin-client_id" content="398214166622-jkme0i3k4tbsgqh19aejaqatrark5l94.apps.googleusercontent.com">
  8. <title>Login google</title>
  9. </head>
  10. <body>
  11. <h1>Get Google Token</h1>
  12. <div id="my-signin2"></div>
  13. <script>
  14. function onSuccess(googleUser) {
  15. console.log('Logged in as: ' + googleUser.getBasicProfile().getName());
  16. const idToken = googleUser.getAuthResponse().id_token;
  17. window.location.href = '/?id_token='+idToken
  18. }
  19. function onFailure(error) {
  20. alert(error);
  21. console.log(error);
  22. }
  23. function renderButton() {
  24. gapi.signin2.render('my-signin2', {
  25. 'scope': 'profile email',
  26. 'width': 240,
  27. 'height': 50,
  28. 'longtitle': true,
  29. 'theme': 'dark',
  30. 'onsuccess': onSuccess,
  31. 'onfailure': onFailure
  32. });
  33. }
  34. </script>
  35. <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
  36. <script>
  37. console.log({code})
  38. </script>
  39. </body>
  40. </html>