Add basic authentication middleware

@clytwynec @cgoldberg