Refactor oauth code

Authentication code refactored and tested. (Unitary and Integration tests)