fork download
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>OAuth2.0</title>
  6. <meta charset='utf-8' />
  7. </head>
  8. <body>
  9. <p>OAuth2.</p>
  10.  
  11. <!--Add buttons to initiate auth sequence and sign out-->
  12. <button id="authorize-button" style="display: none;">Authorize</button>
  13. <button id="signout-button" style="display: none;">Sign Out</button>
  14.  
  15. <div id="content"></div>
  16.  
  17. <script type="text/javascript">
  18.  
  19.  
  20. let clientId = 'client id';
  21.  
  22. let scopes = 'https://mail.google.com/';
  23.  
  24. let authorizeButton = document.getElementById('authorize-button');
  25. let signoutButton = document.getElementById('signout-button');
  26.  
  27. function handleClientLoad() {
  28. // Load the API client and auth2 library
  29. gapi.load('client:auth2', initClient);
  30. }
  31.  
  32. function initClient() {
  33. gapi.client.init({
  34. clientId: clientId,
  35. scope: scopes
  36. }).then(function () {
  37. // Listen for sign-in state changes.
  38. gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
  39.  
  40. // Handle the initial sign-in state.
  41. updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
  42.  
  43. authorizeButton.onclick = handleAuthClick;
  44. signoutButton.onclick = handleSignoutClick;
  45. });
  46. }
  47.  
  48. function updateSigninStatus(isSignedIn) {
  49. // Access permission
  50. if (isSignedIn) {
  51. authorizeButton.style.display = 'none';
  52. signoutButton.style.display = 'block';
  53. makeApiCall();
  54. } else {
  55. authorizeButton.style.display = 'block';
  56. signoutButton.style.display = 'none';
  57. }
  58. }
  59.  
  60. function handleAuthClick(event) {
  61. gapi.auth2.getAuthInstance().signIn();
  62. }
  63.  
  64. function handleSignoutClick(event) {
  65. gapi.auth2.getAuthInstance().signOut();
  66. }
  67.  
  68. function makeApiCall() {
  69. // Acess token is ready !!!
  70. console.log(gapi.client.getToken());
  71. console.log('Yessssssssssssss');
  72. }
  73. </script>
  74. <script async defer src="https://apis.google.com/js/api.js"
  75. onload="this.onload=function(){};handleClientLoad()"
  76. onreadystatechange="if (this.readyState === 'complete') this.onload()">
  77. </script>
  78. </body>
  79. </html>
Runtime error #stdin #stdout #stderr 0.01s 5404KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog.sh: line 2: syntax error near unexpected token `newline'
./prog.sh: line 2: `<!DOCTYPE html>'