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
72: D102 Docstring missing
77: D102 Docstring missing
82: D102 Docstring missing
85: D102 Docstring missing
88: D102 Docstring missing
91: D102 Docstring missing
94: D102 Docstring missing
101: D103 Docstring missing