migrated onmiauth and authentication code from helpified