oauth2server: authorization flow fixes

Fixes issues with the oauth2server authorization flow as well as adds test for restful APIS.

Supersedes PR #2003 
74: D102 Docstring missing
81: D102 Docstring missing
89: D102 Docstring missing
108: D101 Docstring missing
123: D101 Docstring missing
135: D101 Docstring missing