Borrowed stuff from OAuth module