Updated for OAuth support and fixed refresh issue