title: Serving JSON from Google Apps Script as "user accessing the web-app"
body: <p>Trying to serve a JSON request made by a Google Apps Script as the user who is making the request. After thinking for a while, I realized that this cannot work, because the serving script needs to be authorized to run as the user who calls him, so the calling script would have to add some authorization info, which it doesn't, and I have no idea how to add that information (that is actually my question: which information to add to the http-request, and from where to get it). <p>
  But, nevertheless, when I call that server from within the browser, it works because the browser (in which I am logged into my Google account) sends the right info in the http-request to prove that it is authorized. <p>
  This question is somehow related to the question <a href="https://stackoverflow.com/questions/11475972/how-to-use-google-apps-script-contentservice-as-a-rest-server">How to use Google Apps Script ContentService as a REST server</a>, but the answer given there is exactly what I don't want: The invoked JSON-Server should not run under my account, but under the account of the invoking user and use that users resources (scriptdb, drive, ...). 
  So the question is: How to provide that information from one script run from a Google-account to another script, so that this other script can run within that account? I know that using gas-libraries solves that issue, but I would like to have it as JSON-client/server (Mainly to decouple dependencies). To add some code (to keep the Stack Overflow-spirit running), my client:</p>
  
  <pre><code>var scriptUrl="https://script.google.com/macros/s/paperlapapp1231231/exec";
  function callIt (nm, args) {
    var a=[nm];
    for (x in args) {
      a.push(args[x]);
    }
    return Utilities.jsonParse(UrlFetchApp.fetch(scriptUrl+"?args="
         +encodeURIComponent(Utilities.jsonStringify(a))).getContentText());
  }
  function testFunction (p1, p2, p3) { // this is the proxy
    return callIt ("testFunction", arguments);
  }
  // Testroutine
  function callTest() {
    var r=testFunction (9, "XXXlala", {"dudu":1, "dada":"xxx"});
    Logger.log ("r="+Utilities.jsonStringify(r));
  }
  </code></pre>
  
  <p>My server:</p>
  
  <pre><code>function doGet(request) {
    var ret=null;
    try {
      Logger.log ("I got called with "+JSON.stringify(request));
      var args=JSON.parse(decodeURIComponent (request.parameters.args));
      ret=ContentService.createTextOutput(
              JSON.stringify(this[args.shift()].apply (this, args)))
           .setMimeType(ContentService.MimeType.JSON);
    }
    catch (e) {
      ret=ContentService.createTextOutput(JSON.stringify(e))
            .setMimeType(ContentService.MimeType.JSON);
    }
    return ret;
  }
  function testFunction (p1, p2, p3) { // this is the implementation
    var s="testing called p1="+p1+", p2="+p2+", p3="+p3;
    Logger.log (s);
    return {testingResult:s};
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Worked out a solution, but requires a Chrome extension and an intermediate proxy server. See code at <a href="https://bitbucket.org/pbhd/gas-rest-server-as-calling-user" rel="nofollow noreferrer">https://bitbucket.org/pbhd/gas-rest-server-as-calling-user</a></p>