Demo entry 5685808

mypythoncode

   

Submitted by anonymous on Jul 08, 2016 at 19:49
Language: JavaScript. Code size: 3.0 kB.

      function loginfusion() {
        console.log("loginfusion");
        gapi.client.setApiKey(apiKey);
        window.setTimeout(function() {
          auth(true);
        }, 1);
      }

      // Run OAuth 2.0 authorization.
      function auth(immediate) {
        console.log("auth %s", immediate);
        gapi.auth.authorize({
          client_id: clientId,
          scope: scopes,
          immediate: immediate
        }, handleAuthResult);
      }

      // Handle the results of the OAuth 2.0 flow.
      function handleAuthResult(authResult) {
        console.log("handleAuthResult %s", authResult.error);
        var loginfusionButton = document.getElementById('loginfusion-button');
        var authorizeButton = document.getElementById('authorize-button');
        var createTableButton = document.getElementById('create-table');
        var insertDataButton = document.getElementById('insert-data');
        var selectDataButton = document.getElementById('select-data');
        if (authResult && !authResult.error) {
          console.log("authorized");
          loginfusionButton.disabled = true;
          authorizeButton.disabled = true;
          createTableButton.disabled = false;
          insertDataButton.disabled = false;
          selectDataButton.disabled = false;
          } else {
          console.log("authFAILED");
          authorizeButton.disabled = false;
          authorizeButton.onclick = function() {
            auth(false);
            return false;
          };
        }

        var OAuthResult = document.getElementById('loginfusion-output');
        if (authResult['status']['signed_in']) {
          label = 'User granted access:';
          gapi.auth.setToken(authResult);
        } else {
          label = 'Access denied: ' + authResult['error'];
        }
        OAuthResult.innerHTML =
          label + '<pre class="prettyprint"><code>' +
          // JSON.stringify doesn't work in IE8.
          '{<br />' +
          '  "id_token" : "' + authResult['id_token'] + '",<br />' +
          '  "access_token" : "' + authResult['access_token'] + '",<br />' +
          '  "state" : "' + authResult['state'] + '",<br />' +
          '  "expires_in" : "' + authResult['expires_in'] + '",<br />' +
          '  "error" : "' + authResult['error'] + '",<br />' +
          '  "error_description" : "' + authResult['error_description'] + '",<br />' +
          '  "authUser" : "' + authResult['authuser'] + '",<br />' +
          '  "code" : "' + authResult['code'] + '",<br />' +
          '  "status" : {"' + '<br />' +
          '    "google_logged_in" : "' + authResult['status']['google_logged_in'] + '",<br />' +
          '    "method" : "' + authResult['status']['method'] + '",<br />' +
          '    "signed_in" : "' + authResult['status']['signed_in'] + '"<br />' +
          '  }<br />' +
          '}</code></pre>';

      } // haldeAuthResult

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).