I know, the code is (very) ugly but the alternative is major changes to all the other OAuth2 apis which other people have tried (there's 2 pull requests for this api already) and got rejected. Do you have any suggestions on how you want this implemented?