'Given a response, change it to ask for credentials'

def unauthorized(self, response):

    if self.serve_challenge_on_401:
        realm = current_app.config.get('HTTP_BASIC_AUTH_REALM', 'flask-restful')
        challenge = u'{0}    realm="{1}"'.format('Basic', realm)
        response.headers['WWW-Authenticate'] = challenge
    return response
