added more robust oauth handling flow