Added and modified common auth function to work with command line