Check authentication and set HTTP response code correctly.