Added middleware to catch JSON errors 
and return a JSON response.
Updated token authentication to use basic HTTP authentication