Add client side authentication.
Move the auth code entierly into its own module in preperation for seperation.