Oauth 2 support

This pull request replaces #691