First part of changes for oauth, still not tested due to non working of the server part.