Refactored newAuthenticationSource function