This is taken from parts of org.oauth3-frontend and oauth3.js
Needs a proper README. TODO cc / @coolaj86