pediapress / mwlib

mediawiki parser library
103 stars 35 forks source link

mwlib fails when MediaWiki is behind authenticating reverse proxy #37

Closed bruinsg closed 11 years ago

bruinsg commented 11 years ago

We are running a MediaWiki behind a Apache Reverse Proxy that authenticates users and passes this information to MediaWiki. When trying to setup Collection extension I was unable to pdf to render as it was unable to connect. These are some steps I took:

  1. Supply user/password, still failed. No log entries found on apache, error 401
  2. Provide details of self signed cert, as there were no log entries in apache I thought it might be because of this. still error 401
  3. Buy a real ssl certs! As there were no log entries in apache it must be because something goes wrong before the connection is established. Still error 401
  4. Install my own rendering service.... still no luck! Still error 401
  5. Connect to MediaWiki direct, by passing the reverse proxy. MediaWiki throws an exception as no credentials are supplied.

In the end I checked the code and found that the ssl connection is build up without supplying the username and password. The username and password are used only to connect in the API login call.

This was easily fixed by adding the password manager to the build_opener, now the connection can opened and the API can be reached. See my HARD CODED (sorry) solution below, I think this can be generally adopted as the password manager only is used when required.

class mwapi(object):
    def __init__(self, apiurl):
        self.apiurl = apiurl
        self.baseurl = apiurl  
        passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
        passman.add_password(None, apiurl, 'username', 'password')
        self.auth_handler = urllib2.HTTPBasicAuthHandler(passman)
        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()), self.auth_handler)
schmir commented 11 years ago

Thanks for your report. We don't have a need for this feature, so you would have to provide at least a proper pull request. I think it would be enough if you read the authentication information from some environment variables.

Feel free to reopen if you can provide a pull request.