oauth2server: authorization flow fixes

Fixes issues with the oauth2server authorization flow as well as adds test for restful APIS.

Supersedes PR #2003 
1: D100 Docstring missing
26: D200 One-line docstring should not occupy 3 lines
38: D102 Docstring missing