That's quite cool. I'm wondering now if it's possible to implement this in Google Apps Script.
Something along these lines : http://stackoverflow.com/a/19658754/4306542 or if at all possible use https://github.com/googlesamples/apps-script-oauth2 to handle the authenticating.