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
42: D102 Docstring missing
49: D102 Docstring missing
52: D102 Docstring missing
56: D102 Docstring missing
59: D102 Docstring missing
63: D102 Docstring missing
67: D101 Docstring missing
68: D102 Docstring missing
161: D102 Docstring missing
165: D102 Docstring missing
172: D102 Docstring missing
178: D102 Docstring missing
216: D102 Docstring missing
238: D102 Docstring missing
242: D102 Docstring missing
247: D102 Docstring missing
297: D102 Docstring missing
303: D102 Docstring missing
306: D102 Docstring missing